diff --git a/app/deployment/auto_deploy.py b/app/deployment/auto_deploy.py new file mode 100755 index 0000000000..3b7ebce332 --- /dev/null +++ b/app/deployment/auto_deploy.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 +import yaml +import docker +import boto3 +import base64 +import os +import subprocess + + +def get_conf(config="./deploy_conf.yaml"): + conf_file = open(config,"r").read() + return yaml.safe_load(conf_file) + + +def get_database_container(docker_client, container_id): + return docker_client.containers.get(container_id) + + +def main(config): + docker_client = docker.from_env() + # add database stuff when app is migrated to postgresql + #database_container = get_database_container(docker_client, config["containers"]["database_container"]["name"]) + #if not os.path.exists("/ + #database_container.exec_run("pg_dumpall > /var/lib/postgresql/data/ + ecr_client = boto3.client("ecr", region_name=config["region"]) + auth = ecr_client.get_authorization_token() + docker_client.login(username="AWS", password=base64.b64decode(auth["authorizationData"][0]["authorizationToken"]).decode().split(":")[1], registry="694904428454.dkr.ecr.us-east-1.amazonaws.com") + for image in config["images"]: + pull_image(docker_client,config["images"][image]["uri"]) + + #run docker compose + subprocess.Popen(["docker-compose", "up", "--force-recreate", "--build", "-d"],cwd=config["working_directory"]) + subprocess.Popen(["docker", "image", "prune", "-f"]) + + +def pull_image(docker_client, image_repository): + docker_client.images.pull(image_repository) + + +if __name__=="__main__": + main(get_conf()) diff --git a/app/deployment/deploy_conf.yaml b/app/deployment/deploy_conf.yaml new file mode 100644 index 0000000000..3c5d43888d --- /dev/null +++ b/app/deployment/deploy_conf.yaml @@ -0,0 +1,16 @@ +images: + couchers_backend: + uri: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/backend + couchers_media: + uri: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/media + couchers_proxy: + uri: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/proxy + + +containers: + database_container: + name: "" + +working_directory: /home/ubuntu/couchers/app/ + +region: 'us-east-1' diff --git a/app/docker-compose.prod.yml b/app/docker-compose.prod.yml index 4f23cc2906..9ef35d29a9 100644 --- a/app/docker-compose.prod.yml +++ b/app/docker-compose.prod.yml @@ -1,20 +1,20 @@ version: "3" services: proxy: - build: proxy + image: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/proxy restart: on-failure ports: - 8888:8888 - 9901:9901 backend: - build: backend + image: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/backend restart: on-failure ports: - 1751:1751 - 1752:1752 - 1753:1753 media: - build: media + image: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/media env_file: media/prod.env restart: on-failure ports: diff --git a/app/docker-compose.yml b/app/docker-compose.yml index a26766c6ab..53180e5a78 100644 --- a/app/docker-compose.yml +++ b/app/docker-compose.yml @@ -8,7 +8,7 @@ services: - 9901:9901 backend_tests: build: backend - volumes: + volumes: - "./backend:/app" command: bash -c "find src -name '**.py' | ENTR_INOTIFY_WORKAROUND=1 entr -d pytest src" restart: on-failure