Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Using Argo Workflow to Deploy Instance #744

Merged
merged 32 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
575b5b0
basic interface for using argo workflow
zhxu73 Jun 20, 2020
a98de04
use argo workflow to deploy instance
zhxu73 Jun 20, 2020
29542db
rename provider_uuid to provider_name
zhxu73 Jun 23, 2020
850866e
put path to argo config file in ini config
zhxu73 Jun 23, 2020
09ab39d
fix open files
zhxu73 Jun 23, 2020
45f481a
ArgoWorkflow.status() check for Error
zhxu73 Jun 24, 2020
c761e54
read zoneinfo from argo config file
zhxu73 Jun 23, 2020
1e2eeae
remove private key as an workflow argument to instance_deploy.yml
zhxu73 Jun 30, 2020
60e7828
ArgoWorkflow.status() check for Error
zhxu73 Jun 24, 2020
b812e3f
remove private key as an workflow argument to instance_deploy.yml
zhxu73 Jun 30, 2020
182ca91
add support for workflow template
zhxu73 Jun 30, 2020
ed1ae01
separate class for workflow status
zhxu73 Jul 7, 2020
bef6ce9
add support for dumping workflow logs
zhxu73 Jul 9, 2020
d90aeae
separate log file for each workflow
zhxu73 Jul 9, 2020
a385e45
Merge branch 'argo_wf_temp' into argo_deploy
zhxu73 Jul 9, 2020
b4d8c42
uses provider uuid as identifier
zhxu73 Jul 9, 2020
c28eac8
remove duplicate
zhxu73 Jul 9, 2020
5f1bbd0
provider specific config
zhxu73 Jul 9, 2020
3ab9ee4
separate log file for each pod in wf, better path naming for wf log dump
zhxu73 Jul 14, 2020
b551900
refactor ArgoWorkflow
zhxu73 Jul 15, 2020
8d733e7
add fields selection when fetching workflow
zhxu73 Jul 15, 2020
1fdcfdb
deploy log dump uses playbook name as filename
zhxu73 Jul 20, 2020
ed10235
shorten timestamp in log dump path
zhxu73 Jul 20, 2020
9e9aa6e
read ssl_verify from argo config
zhxu73 Aug 12, 2020
66a0c54
validate argo config schema
zhxu73 Aug 12, 2020
3be6ef1
set locale to en_US.UTF-8
zhxu73 Aug 12, 2020
ad96979
remove unused import, clean up comments
zhxu73 Aug 12, 2020
6b255d3
fix linting
zhxu73 Aug 12, 2020
c02e877
formatted with yapf
zhxu73 Aug 13, 2020
37b291f
add script to create access token for users
zhxu73 Aug 13, 2020
c44ad53
update changelog
zhxu73 Aug 13, 2020
7a1cba9
yapf scripts/batch_create_access_token.py
zhxu73 Aug 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
-->

## [Unreleased](https://github.com/cyverse/atmosphere/compare/v36-9...HEAD) - YYYY-MM-DD
### Added
- script to create access token for users

### Changed
- Using argo workflow to run ansible playbooks to deploy instance


## [v36-9](https://github.com/cyverse/atmosphere/compare/v36-8...v36-9) - 2020-06-16
### Fixed
Expand Down
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ RUN apt-get update && \
libssl-dev \
libxml2-dev \
libxslt1-dev \
locales \
make \
netcat \
openssl \
Expand All @@ -39,7 +40,12 @@ RUN apt-get update && \
uwsgi \
uwsgi-plugin-python \
zlib1g-dev && \
rm -rf /var/lib/apt/lists/*
rm -rf /var/lib/apt/lists/* && \
locale-gen en_US.UTF-8

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# Create PID and log directories for uWSGI
RUN mkdir -p /run/uwsgi/app/atmosphere /var/log/uwsgi && \
Expand Down
3 changes: 3 additions & 0 deletions atmosphere/settings/local.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,6 @@ CACHES = {
'LOCATION': '/var/tmp/django_cache',
}
}

# Argo workflow
ARGO_CONFIG_FILE_PATH = "{{ ARGO_CONFIG_FILE_PATH }}"
34 changes: 34 additions & 0 deletions docker/argo_config.schema
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"type": "object",
"properties": {
"default": {
"type": "string",
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
}
},
"patternProperties": {
"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$": {
"$ref": "#/definitions/provider"
}
},
"definitions" : {
"provider": {
"properties": {
"api_host": {"type": "string"},
"api_port": {
"type": "integer",
"minimum": 0,
"maximum": 65535
},
"token": {"type": "string"},
"namespace": {"type": "string"},
"workflow_base_dir": {"type": "string"},
"zoneinfo": {"type": "string"},
"ssl_verify": {"type": "boolean"}
},
"required": ["api_host", "api_port", "token", "namespace", "workflow_base_dir", "zoneinfo", "ssl_verify"]
}
},
"required": ["default"],
"additionalProperties": false
}
5 changes: 5 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ else
chown -R www-data:www-data /opt/dev/atmosphere
fi

# Validate argo config
cat $SECRETS_DIR/argo.config.yml | python -c "import yaml, json, sys; print(json.dumps(yaml.safe_load(sys.stdin.read())));" | tee /tmp/argo_config.json
jsonschema -i /tmp/argo_config.json argo_config.schema
rm /tmp/argo_config.json

# Start services
sed -i "s/^bind 127.0.0.1 ::1$/bind 127.0.0.1/" /etc/redis/redis.conf
service redis-server start
Expand Down
103 changes: 103 additions & 0 deletions scripts/batch_create_access_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env python
"""
Create access token for users

Usage:
python scripts/batch_create_access_token.py --token-name workshop_token --users name1,name2,name3
"""
import django

django.setup()

import argparse
from core.models import AccessToken
from core.models.user import AtmosphereUser
from core.models.access_token import create_access_token


def parse_arg():
"""
Parse command line arguments.

Returns:
argparse.Namespace: result
"""
parser = argparse.ArgumentParser(
description="create or fetch tokens for users"
)
parser.add_argument(
"--users",
dest="users",
type=str,
required=True,
help="usernames, comma separated if more than 1(no space)"
)
parser.add_argument(
"--token-name",
dest="token_name",
type=str,
required=True,
help="name of the token"
)

args = parser.parse_args()
args.users = args.users.split(',')
return args


def fetch_user_by_username(username):
"""
Fetch user by username

Args:
username (str): username of the user

Returns:
Optional[AtmosphereUser]: user
"""
try:
return AtmosphereUser.objects.get(username=username)
except Exception as exc:
print("unable to fetch user {}".format(username))
print(exc)
return None


def create_or_fetch_token_for_user(user, token_name):
"""
Fetch token with given name for user, create a token if none exists with the same name

Args:
user (AtmosphereUser): user
token_name (str): name of the token

Returns:
str: token
"""
# check if there is any existing token by the same name
existing_tokens = AccessToken.objects.filter(token__user=user)
for token in existing_tokens:
if token.name == token_name:
# return token if same name
return token.token_id
# create new token if none with the same name exists
new_token = create_access_token(
user, token_name, issuer="Personal-Access-Token"
)
print("new token created for user {}".format(user.username))
return new_token.token_id


def main():
"""
Entrypoint
"""
args = parse_arg()
for username in args.users:
user = fetch_user_by_username(username)
token = create_or_fetch_token_for_user(user, args.token_name)
print("{}, {}".format(username, token))


if __name__ == '__main__':
main()
Empty file added service/argo/__init__.py
Empty file.
Loading