From b0c2ed02905aea0a50108456ff24400dfec858e1 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Mon, 18 Jan 2021 16:55:33 +0100 Subject: [PATCH 01/27] add deploy step to deploy to pm ec2 instance using codedeploy --- .circleci/config.yml | 48 ++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ac50581..33d7466 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,6 @@ -version: 2 +version: 2.1 +orbs: + aws-code-deploy: circleci/aws-code-deploy@1.0.1 jobs: build: docker: @@ -82,43 +84,27 @@ jobs: - ./venv key: v1-dependencies-{{ checksum "requirements.txt" }} - deploy: - docker: - - image: buildpack-deps:trusty - steps: - - checkout - - run: - name: Deploy Develop to Heroku - command: | - git config --global user.email "eno.bassey@webspoons.com" - git config --global user.name "Eno Bassey" - git push -f https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git develop:master - deploy_gcp: # Deploy application to GCP staging - docker: - - image: cimg/node:15.5.1 - steps: - - checkout - - setup_remote_docker - - run: - name: Build and deploy application to staging - command: chmod +x scripts/deploy.sh && scripts/deploy.sh + deploy_aws: # Deploy application to AWS staging + + + + workflows: - version: 2 + version: 2.1 build-deploy: jobs: - build - - deploy: - requires: - - build - filters: - branches: - only: develop - - deploy_gcp: + - deploy_aws: requires: - build filters: branches: only: - - develop - - master + - development + - aws-code-deploy/deploy: + application-name: pm-deploy + bundle-bucket: myApplicationS3Bucket + bundle-key: pmS3BucketKey + deployment-group: pm-instance + service-role-arn: arn:aws:iam::362231138751:role/CodeDeployRole From 08bc528de31e2107b136391e9594c2a3a687e057 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Mon, 18 Jan 2021 16:57:54 +0100 Subject: [PATCH 02/27] add deploy step to deploy to pm ec2 instance using codedeploy --- .circleci/config.yml | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 33d7466..a1202d2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -83,25 +83,18 @@ jobs: paths: - ./venv key: v1-dependencies-{{ checksum "requirements.txt" }} - - deploy_aws: # Deploy application to AWS staging - - - - workflows: - version: 2.1 build-deploy: jobs: - build - - deploy_aws: - requires: - - build - filters: - branches: - only: - - development + # - deploy_aws: + # requires: + # - build + # filters: + # branches: + # only: + # - development - aws-code-deploy/deploy: application-name: pm-deploy bundle-bucket: myApplicationS3Bucket From e860b05f7e485a13b438c8e06a1e9c7c1905e4ef Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Mon, 18 Jan 2021 18:12:14 +0100 Subject: [PATCH 03/27] add appsec yaml file for codedeploy service --- appsec.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 appsec.yml diff --git a/appsec.yml b/appsec.yml new file mode 100644 index 0000000..b770235 --- /dev/null +++ b/appsec.yml @@ -0,0 +1,5 @@ +versionversion: 0.0 +os: linux +files: + - source: source + destination: /var/www/html/PM-API From f7e8f2042a91c52e860cc3d3eb2634d9c451da1b Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Mon, 18 Jan 2021 18:21:54 +0100 Subject: [PATCH 04/27] add appspec yaml file for codedeploy service --- appsec.yml => appspec.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename appsec.yml => appspec.yml (100%) diff --git a/appsec.yml b/appspec.yml similarity index 100% rename from appsec.yml rename to appspec.yml From e90a7ba06df4fffbbffab6e346aec2c54e174904 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Mon, 18 Jan 2021 18:46:53 +0100 Subject: [PATCH 05/27] change s3 bucket name --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a1202d2..80be496 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -97,7 +97,7 @@ workflows: # - development - aws-code-deploy/deploy: application-name: pm-deploy - bundle-bucket: myApplicationS3Bucket + bundle-bucket: pm-codedeploy-bucket bundle-key: pmS3BucketKey deployment-group: pm-instance service-role-arn: arn:aws:iam::362231138751:role/CodeDeployRole From 6b674d089682a0e542f696028e164a0486ea9854 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Thu, 21 Jan 2021 03:51:52 +0100 Subject: [PATCH 06/27] chenge codeploy configurations --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 80be496..2975805 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -96,8 +96,8 @@ workflows: # only: # - development - aws-code-deploy/deploy: - application-name: pm-deploy + application-name: pm-app bundle-bucket: pm-codedeploy-bucket bundle-key: pmS3BucketKey - deployment-group: pm-instance - service-role-arn: arn:aws:iam::362231138751:role/CodeDeployRole + deployment-group: pm-deploment-group + service-role-arn: arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole From 3e9de0c3d2cb623b0871705471c802288c61591f Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Thu, 21 Jan 2021 10:19:43 +0100 Subject: [PATCH 07/27] correct version key syntax error --- appspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appspec.yml b/appspec.yml index b770235..e442432 100644 --- a/appspec.yml +++ b/appspec.yml @@ -1,4 +1,4 @@ -versionversion: 0.0 +version: 0.0 os: linux files: - source: source From 95cbf4278f2d043d4d402216542cfa31ee550c6c Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Thu, 21 Jan 2021 10:50:58 +0100 Subject: [PATCH 08/27] change source value --- appspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appspec.yml b/appspec.yml index e442432..59d6cb7 100644 --- a/appspec.yml +++ b/appspec.yml @@ -1,5 +1,5 @@ version: 0.0 os: linux files: - - source: source + - source: / destination: /var/www/html/PM-API From 4fd98e9f2faa2651d30be8e0497d6873e70eac6d Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 11:39:42 +0100 Subject: [PATCH 09/27] add scipts for deployment --- scripts/install_dependencies | 9 +++++++++ scripts/start_server | 2 ++ 2 files changed, 11 insertions(+) create mode 100644 scripts/install_dependencies create mode 100644 scripts/start_server diff --git a/scripts/install_dependencies b/scripts/install_dependencies new file mode 100644 index 0000000..4bb2b72 --- /dev/null +++ b/scripts/install_dependencies @@ -0,0 +1,9 @@ +#!/bin/bash +sudo apt install python3-pip +pip3 install virtualenv +virtualenv pm-api +source pm-api/bin/activate +pip3 install -r requirements.txt +flask seed-database +bash redis.sh +python3 run.py db migrate \ No newline at end of file diff --git a/scripts/start_server b/scripts/start_server new file mode 100644 index 0000000..1c23213 --- /dev/null +++ b/scripts/start_server @@ -0,0 +1,2 @@ +#!/bin/bash +python3 run.py runserver \ No newline at end of file From a14487f901e082ff4ea2427b40915489c77e11c9 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 11:41:51 +0100 Subject: [PATCH 10/27] add scipts for deployment --- appspec.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/appspec.yml b/appspec.yml index 59d6cb7..09d2024 100644 --- a/appspec.yml +++ b/appspec.yml @@ -3,3 +3,10 @@ os: linux files: - source: / destination: /var/www/html/PM-API +hooks: + AfterInstall: + - location: scripts/install_dependencies + timeout: 300 + ApplicationStart: + - location: scripts/start_server + timeout: 300 \ No newline at end of file From cf037814fa4c1c1df79edfdc03daf01312bdd2a5 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 11:42:40 +0100 Subject: [PATCH 11/27] no changes --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 45f5b96..2cfd0cc 100755 --- a/.gitignore +++ b/.gitignore @@ -120,3 +120,4 @@ jwt-key.pub #redis locally redis-stable + From 4a68d96edb9b46d1d7188023b4a183679f78b954 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 11:49:17 +0100 Subject: [PATCH 12/27] add scipts for deployment --- scripts/install_dependencies | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install_dependencies b/scripts/install_dependencies index 4bb2b72..1cd7ce9 100644 --- a/scripts/install_dependencies +++ b/scripts/install_dependencies @@ -1,5 +1,5 @@ #!/bin/bash -sudo apt install python3-pip +sudo apt install -y python3-pip pip3 install virtualenv virtualenv pm-api source pm-api/bin/activate From e1f33aee18cb5cf54e5f018f2778416322ac4f1f Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 11:55:49 +0100 Subject: [PATCH 13/27] add scipts for deployment --- scripts/install_dependencies | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/install_dependencies b/scripts/install_dependencies index 1cd7ce9..7fc8c60 100644 --- a/scripts/install_dependencies +++ b/scripts/install_dependencies @@ -1,6 +1,7 @@ #!/bin/bash sudo apt install -y python3-pip pip3 install virtualenv +cd /var/www/html/PM-API virtualenv pm-api source pm-api/bin/activate pip3 install -r requirements.txt From acc4c0e1c623600fef7e3d2280799deddb151987 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 12:05:52 +0100 Subject: [PATCH 14/27] trigeer CI build --- scripts/install_dependencies | 2 +- scripts/start_server | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install_dependencies b/scripts/install_dependencies index 7fc8c60..b8f8a73 100644 --- a/scripts/install_dependencies +++ b/scripts/install_dependencies @@ -7,4 +7,4 @@ source pm-api/bin/activate pip3 install -r requirements.txt flask seed-database bash redis.sh -python3 run.py db migrate \ No newline at end of file +python3 run.py db migrate diff --git a/scripts/start_server b/scripts/start_server index 1c23213..ebb6d29 100644 --- a/scripts/start_server +++ b/scripts/start_server @@ -1,2 +1,2 @@ #!/bin/bash -python3 run.py runserver \ No newline at end of file +python3 run.py runserver From fa1d3b4320771670b8f20591387e632e832c4ab4 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 12:09:29 +0100 Subject: [PATCH 15/27] increase timout value for CI build --- appspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appspec.yml b/appspec.yml index 09d2024..a51c241 100644 --- a/appspec.yml +++ b/appspec.yml @@ -6,7 +6,7 @@ files: hooks: AfterInstall: - location: scripts/install_dependencies - timeout: 300 + timeout: 600 ApplicationStart: - location: scripts/start_server timeout: 300 \ No newline at end of file From 545cd07805d85aa1210b75b4fc59179279ca385e Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 12:27:15 +0100 Subject: [PATCH 16/27] remove redis and db start command --- scripts/install_dependencies | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/install_dependencies b/scripts/install_dependencies index b8f8a73..d9e240c 100644 --- a/scripts/install_dependencies +++ b/scripts/install_dependencies @@ -4,7 +4,4 @@ pip3 install virtualenv cd /var/www/html/PM-API virtualenv pm-api source pm-api/bin/activate -pip3 install -r requirements.txt -flask seed-database -bash redis.sh -python3 run.py db migrate +pip3 install -r requirements.txt \ No newline at end of file From bc62380f0d91bf2dbb29ad6808ca7bd1606512de Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 12:33:58 +0100 Subject: [PATCH 17/27] add require step to deploy workflow --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2975805..0d91103 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -101,3 +101,5 @@ workflows: bundle-key: pmS3BucketKey deployment-group: pm-deploment-group service-role-arn: arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole + requires: + - build From c634eb826d0734ed5d0502e089b2d2126e353bc3 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 12:47:06 +0100 Subject: [PATCH 18/27] add require step to deploy workflow --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0d91103..e851cbc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -103,3 +103,5 @@ workflows: service-role-arn: arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole requires: - build + + \ No newline at end of file From f44a151f6dc0ce380a69d3964ad28f4b79c16041 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 12:54:08 +0100 Subject: [PATCH 19/27] add require step to deploy workflow --- scripts/start_server | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/start_server b/scripts/start_server index ebb6d29..98a0e92 100644 --- a/scripts/start_server +++ b/scripts/start_server @@ -1,2 +1,3 @@ #!/bin/bash +cd /var/www/html/PM-API python3 run.py runserver From 5639bdda75973fe4023df36ff165b0a507ee5fb6 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 16:28:34 +0100 Subject: [PATCH 20/27] update dependencies scripts --- scripts/install_dependencies | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/install_dependencies b/scripts/install_dependencies index d9e240c..ae7e1b0 100644 --- a/scripts/install_dependencies +++ b/scripts/install_dependencies @@ -2,6 +2,5 @@ sudo apt install -y python3-pip pip3 install virtualenv cd /var/www/html/PM-API -virtualenv pm-api source pm-api/bin/activate pip3 install -r requirements.txt \ No newline at end of file From 01e4fd7d7039e566df878b15aed41e66a2c45ea4 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 16:28:57 +0100 Subject: [PATCH 21/27] update dependencies scripts --- scripts/install_dependencies | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install_dependencies b/scripts/install_dependencies index ae7e1b0..c42efb9 100644 --- a/scripts/install_dependencies +++ b/scripts/install_dependencies @@ -3,4 +3,4 @@ sudo apt install -y python3-pip pip3 install virtualenv cd /var/www/html/PM-API source pm-api/bin/activate -pip3 install -r requirements.txt \ No newline at end of file +pip install -r requirements.txt \ No newline at end of file From 1a15a82ad528a35cdb6d47b11c5fe5ed70002296 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Fri, 22 Jan 2021 16:29:20 +0100 Subject: [PATCH 22/27] update start scripts --- scripts/start_server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start_server b/scripts/start_server index 98a0e92..8994fef 100644 --- a/scripts/start_server +++ b/scripts/start_server @@ -1,3 +1,3 @@ #!/bin/bash cd /var/www/html/PM-API -python3 run.py runserver +python run.py runserver From f0fd7c082d5534480359242cf6ed0e422a99ad5b Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Sun, 24 Jan 2021 15:51:50 +0100 Subject: [PATCH 23/27] add user to codedeploy manifest --- appspec.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/appspec.yml b/appspec.yml index a51c241..b9d1fd2 100644 --- a/appspec.yml +++ b/appspec.yml @@ -7,6 +7,8 @@ hooks: AfterInstall: - location: scripts/install_dependencies timeout: 600 + runas: ubuntu ApplicationStart: - location: scripts/start_server - timeout: 300 \ No newline at end of file + timeout: 300 + runas: ubuntu \ No newline at end of file From 60067047e7d38c3dc49ed102c99438d3b7d15ed9 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Mon, 25 Jan 2021 08:48:16 +0100 Subject: [PATCH 24/27] increase python base image version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 99d7ac7..e9ec6e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-alpine +FROM python:3.8.7-alpine WORKDIR /usr/src ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 From 80cd130a873ecc388e92957d8138955824791a8d Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Mon, 25 Jan 2021 10:32:12 +0100 Subject: [PATCH 25/27] add redis and update start scripts --- Dockerfile | 4 ++-- appspec.yml | 7 +------ docker-compose.yml | 26 ++++++++++++++++++++------ scripts/start_server | 7 ++++++- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index e9ec6e5..ddd100d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ -FROM python:3.8.7-alpine +FROM python:3.8.7-buster WORKDIR /usr/src ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 ENV FLASK_APP=run.py ENV FLASK_ENV=development ENV FLASK_RUN_HOST 0.0.0.0 -RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev +RUN apt-get update && apt-get install -y postgresql gcc python3-dev musl-dev build-essential libssl-dev libffi-dev RUN pip install --upgrade pip COPY requirements.txt requirements.txt RUN pip install -r requirements.txt diff --git a/appspec.yml b/appspec.yml index b9d1fd2..b45a1cd 100644 --- a/appspec.yml +++ b/appspec.yml @@ -4,11 +4,6 @@ files: - source: / destination: /var/www/html/PM-API hooks: - AfterInstall: - - location: scripts/install_dependencies - timeout: 600 - runas: ubuntu ApplicationStart: - location: scripts/start_server - timeout: 300 - runas: ubuntu \ No newline at end of file + timeout: 300 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 6506796..ad5cf8a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,9 +5,13 @@ services: build: . depends_on: - db + - redis environment: + APP_ENV: development STAGE: test - SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://test:test@db/test + # SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://test:test@db/test + DATABASE_URL: postgresql://pm_admin:mypassword@db:5432/pm_db + REDIS_URL: redis://redis:6379 networks: - default ports: @@ -17,15 +21,25 @@ services: restart: always db: - environment: - POSTGRES_USER: test - POSTGRES_PASSWORD: test - POSTGRES_DB: test image: postgres:latest + environment: + - POSTGRES_USER=pm_admin + - POSTGRES_PASSWORD=mypassword + - POSTGRES_DB=pm_db networks: - default ports: - 5405:5432 restart: always volumes: - - ./postgres-data:/var/lib/postgresql/data \ No newline at end of file + - postgres_data:/var/lib/postgresql/data + + redis: + image: "redis:alpine" + networks: + - default + ports: + - "6379:6379" + +volumes: + postgres_data: \ No newline at end of file diff --git a/scripts/start_server b/scripts/start_server index 8994fef..2c169ef 100644 --- a/scripts/start_server +++ b/scripts/start_server @@ -1,3 +1,8 @@ #!/bin/bash cd /var/www/html/PM-API -python run.py runserver +docker-compose up -d +docker-compose exec api bash +python run.py db upgrade + + + From be99bf5defa1b939f97ab9eeddfdd44ea5c66b35 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Mon, 25 Jan 2021 10:54:21 +0100 Subject: [PATCH 26/27] update start scripts --- scripts/start_server | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/start_server b/scripts/start_server index 2c169ef..297c6df 100644 --- a/scripts/start_server +++ b/scripts/start_server @@ -1,8 +1,8 @@ #!/bin/bash cd /var/www/html/PM-API docker-compose up -d -docker-compose exec api bash -python run.py db upgrade + + From d534b2eb0b75af151444a326fb0a2c4faddef813 Mon Sep 17 00:00:00 2001 From: babalola taiwo Date: Mon, 25 Jan 2021 12:23:09 +0100 Subject: [PATCH 27/27] add branch filter object to deploy stage --- .circleci/config.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e851cbc..af90882 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -103,5 +103,8 @@ workflows: service-role-arn: arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole requires: - build + filters: + branches: + only: + - development - \ No newline at end of file