From 18f68ad2ad97db3ca116c10144c9f37c115f943f Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 18 Aug 2020 23:43:29 +1000 Subject: [PATCH 1/7] In order for the script to update the application, docker compose had to be modified to use the newly pulled images, rather than building them from a dockerfile --- app/docker-compose.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/docker-compose.yml b/app/docker-compose.yml index a26766c6ab..4d44b40725 100644 --- a/app/docker-compose.yml +++ b/app/docker-compose.yml @@ -1,19 +1,19 @@ version: "3" services: proxy: - build: proxy + build: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/proxy restart: on-failure ports: - 8888:8888 - 9901:9901 backend_tests: - build: backend + build: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/backend volumes: - "./backend:/app" command: bash -c "find src -name '**.py' | ENTR_INOTIFY_WORKAROUND=1 entr -d pytest src" restart: on-failure backend: - build: backend + build: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/backend environment: MEDIA_SERVER_SECRET_KEY: 1c40f0f493eea6e0c2dec15c8c1d32c25f2f4b4dacf3a7a255d8d2ab56fa9677 MEDIA_SERVER_BEARER_TOKEN: aabbcbaa02883911 @@ -29,13 +29,13 @@ services: - 1752:1752 - 1753:1753 media_tests: - build: media + build: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/media command: pytest src restart: on-failure environment: MEDIA_SERVER_FROM_ENV: 0 media: - build: media + build: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/media environment: MAIN_SERVER_ADDRESS: "backend:1753" MEDIA_SERVER_SECRET_KEY: 1c40f0f493eea6e0c2dec15c8c1d32c25f2f4b4dacf3a7a255d8d2ab56fa9677 From fdd4bf5f35358f36fc9d7f6cd1961a59dfd14b60 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 18 Aug 2020 23:44:03 +1000 Subject: [PATCH 2/7] script and script config to pull new images and rebuild the docker stack --- app/deployment/auto_deploy.py | 41 +++++++++++++++++++++++++++++++++ app/deployment/deploy_conf.yaml | 16 +++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 app/deployment/auto_deploy.py create mode 100644 app/deployment/deploy_conf.yaml diff --git a/app/deployment/auto_deploy.py b/app/deployment/auto_deploy.py new file mode 100644 index 0000000000..f1e88e0103 --- /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' From 0e4b39ec2bfe59e127fa7156da1be3382c9a9429 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 19 Aug 2020 00:00:41 +1000 Subject: [PATCH 3/7] In order for the script to update the application, docker compose had to be modified to use the newly pulled images, rather than building them from a dockerfile --- app/docker-compose.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/docker-compose.yml b/app/docker-compose.yml index 4d44b40725..6ba5b44f21 100644 --- a/app/docker-compose.yml +++ b/app/docker-compose.yml @@ -1,19 +1,19 @@ version: "3" services: proxy: - build: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/proxy + image: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/proxy restart: on-failure ports: - 8888:8888 - 9901:9901 backend_tests: - build: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/backend + image: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/backend volumes: - "./backend:/app" command: bash -c "find src -name '**.py' | ENTR_INOTIFY_WORKAROUND=1 entr -d pytest src" restart: on-failure backend: - build: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/backend + image: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/backend environment: MEDIA_SERVER_SECRET_KEY: 1c40f0f493eea6e0c2dec15c8c1d32c25f2f4b4dacf3a7a255d8d2ab56fa9677 MEDIA_SERVER_BEARER_TOKEN: aabbcbaa02883911 @@ -29,13 +29,13 @@ services: - 1752:1752 - 1753:1753 media_tests: - build: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/media + image: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/media command: pytest src restart: on-failure environment: MEDIA_SERVER_FROM_ENV: 0 media: - build: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/media + image: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/media environment: MAIN_SERVER_ADDRESS: "backend:1753" MEDIA_SERVER_SECRET_KEY: 1c40f0f493eea6e0c2dec15c8c1d32c25f2f4b4dacf3a7a255d8d2ab56fa9677 From 287fdfb1e3f0aab8874eb3216e6c440bcdf2abbc Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 19 Aug 2020 00:46:22 +1000 Subject: [PATCH 4/7] defined images in docker-compose.prod.yml --- app/docker-compose.prod.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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: From 9d673d1911492ab39a3dc5cf52bffad3101bd54c Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 19 Aug 2020 00:49:03 +1000 Subject: [PATCH 5/7] formatting --- app/deployment/auto_deploy.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/deployment/auto_deploy.py b/app/deployment/auto_deploy.py index f1e88e0103..3b7ebce332 100644 --- a/app/deployment/auto_deploy.py +++ b/app/deployment/auto_deploy.py @@ -6,12 +6,13 @@ 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): +def get_database_container(docker_client, container_id): return docker_client.containers.get(container_id) @@ -21,7 +22,7 @@ def main(config): #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"]) + 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"]: @@ -29,8 +30,7 @@ def main(config): #run docker compose subprocess.Popen(["docker-compose", "up", "--force-recreate", "--build", "-d"],cwd=config["working_directory"]) - subprocess.Popen(["docker", "image", "prune", "-f"]) - + subprocess.Popen(["docker", "image", "prune", "-f"]) def pull_image(docker_client, image_repository): From c214c1b1e5a629b5c69782d1abc5502bed8f8db6 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 19 Aug 2020 00:53:28 +1000 Subject: [PATCH 6/7] reverted --- app/docker-compose.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/docker-compose.yml b/app/docker-compose.yml index 6ba5b44f21..53180e5a78 100644 --- a/app/docker-compose.yml +++ b/app/docker-compose.yml @@ -1,19 +1,19 @@ version: "3" services: proxy: - image: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/proxy + build: proxy restart: on-failure ports: - 8888:8888 - 9901:9901 backend_tests: - image: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/backend - volumes: + build: backend + volumes: - "./backend:/app" command: bash -c "find src -name '**.py' | ENTR_INOTIFY_WORKAROUND=1 entr -d pytest src" restart: on-failure backend: - image: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/backend + build: backend environment: MEDIA_SERVER_SECRET_KEY: 1c40f0f493eea6e0c2dec15c8c1d32c25f2f4b4dacf3a7a255d8d2ab56fa9677 MEDIA_SERVER_BEARER_TOKEN: aabbcbaa02883911 @@ -29,13 +29,13 @@ services: - 1752:1752 - 1753:1753 media_tests: - image: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/media + build: media command: pytest src restart: on-failure environment: MEDIA_SERVER_FROM_ENV: 0 media: - image: 694904428454.dkr.ecr.us-east-1.amazonaws.com/couchers/media + build: media environment: MAIN_SERVER_ADDRESS: "backend:1753" MEDIA_SERVER_SECRET_KEY: 1c40f0f493eea6e0c2dec15c8c1d32c25f2f4b4dacf3a7a255d8d2ab56fa9677 From d1177b31f37ae65e6523e32754605e094fca9e89 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 19 Aug 2020 01:09:37 +1000 Subject: [PATCH 7/7] made script executable --- app/deployment/auto_deploy.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 app/deployment/auto_deploy.py diff --git a/app/deployment/auto_deploy.py b/app/deployment/auto_deploy.py old mode 100644 new mode 100755