Skip to content

Commit

Permalink
Merge branch 'deployment-feature-add-deployment-script' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
aapeliv committed Aug 18, 2020
2 parents c879595 + d1177b3 commit a89fd4e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
41 changes: 41 additions & 0 deletions app/deployment/auto_deploy.py
Original file line number Diff line number Diff line change
@@ -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())
16 changes: 16 additions & 0 deletions app/deployment/deploy_conf.yaml
Original file line number Diff line number Diff line change
@@ -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'
6 changes: 3 additions & 3 deletions app/docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion app/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a89fd4e

Please sign in to comment.