From a8c59ca84e63e14cbf50eae9136eb1fdd62be11b Mon Sep 17 00:00:00 2001 From: Aman Dalmia Date: Fri, 30 Apr 2021 12:22:54 +0530 Subject: [PATCH 1/6] TEMP: make UUID writeable --- plio/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plio/serializers.py b/plio/serializers.py index c7625b2b..e85ca104 100644 --- a/plio/serializers.py +++ b/plio/serializers.py @@ -37,7 +37,7 @@ class Meta: "created_at", "updated_at", ] - read_only_fields = ["uuid"] + # read_only_fields = ["uuid"] def to_representation(self, instance): response = super().to_representation(instance) From 12ddfcbf3b5dfd795bdadad453e65db407f6da28 Mon Sep 17 00:00:00 2001 From: Aman Dalmia Date: Fri, 30 Apr 2021 23:36:49 +0530 Subject: [PATCH 2/6] TEMP: workflow change for deployment to prod --- .github/workflows/deploy_to_ecs_prod.yml | 1 + .github/workflows/deploy_to_ecs_staging.yml | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy_to_ecs_prod.yml b/.github/workflows/deploy_to_ecs_prod.yml index e7f1183e..153bbcbc 100644 --- a/.github/workflows/deploy_to_ecs_prod.yml +++ b/.github/workflows/deploy_to_ecs_prod.yml @@ -1,6 +1,7 @@ # This workflow will build and push a new container image to Amazon ECR on: + pull_request: release: types: [published] diff --git a/.github/workflows/deploy_to_ecs_staging.yml b/.github/workflows/deploy_to_ecs_staging.yml index 90020308..d2d95fb5 100644 --- a/.github/workflows/deploy_to_ecs_staging.yml +++ b/.github/workflows/deploy_to_ecs_staging.yml @@ -1,7 +1,6 @@ # This workflow will build and push a new container image to Amazon ECR on: - pull_request: push: branches: ["master"] From 9153808a89ef224f7bbc0a962d6396c0792c0e7f Mon Sep 17 00:00:00 2001 From: Aman Dalmia Date: Sat, 1 May 2021 01:52:21 +0530 Subject: [PATCH 3/6] DOC: update documentation for deployment with RDS production instructions --- docs/DEPLOYMENT.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md index bc2b792c..c1507e4a 100644 --- a/docs/DEPLOYMENT.md +++ b/docs/DEPLOYMENT.md @@ -210,7 +210,26 @@ Follow the steps below to set up the staging environment on AWS. Setting up a production environment on AWS is almost the same as staging. Additionally, take care of the following things: 1. Rename all services as `plio-backend-production` or a similar naming convention. 2. Change all the environment variables to the corresponding values for the production environment. -3. Go with auto-scaling option when creating a new service from ECS. +3. We chose to use the same instance for the production and staging RDS instance while using a separate user and database for each environment to optimize for cost. + 1. Once the RDS instance is created after following the step above, create the production DB in the same instance. + 2. Connect to your RDS instance + ```sh + psql -h your-db-instance-endpoint.aws-region.rds.amazonaws.com -p 5432 -U master_username + ``` + 3. Ensure that you are in the `psql` shell - now you are connected to your RDS instance. + 4. Create a new database using the `psql` shell + ``` + postgres=> CREATE DATABASE plio_production; + ``` + 5. Create a new user + ``` + postgres=> CREATE USER postgres_prod WITH PASSWORD 'YOUR_PASSWORD'; + ``` + 6. Grant the newly created user all the privileges to the production DB + ``` + postgres=> GRANT ALL PRIVILEGES ON DATABASE plio_production TO postgres_prod; + ``` +4. Go with auto-scaling option when creating a new service from ECS. 1. When creating a service or when updating it, navigate to the service auto-scaling section. 2. Select `Configure Service Auto Scaling to adjust your service's desired count`. 3. Set minimum number of tasks to `1`. This is the minimum count of running tasks when scale-in operation happen. From 35c1e4b1edbc4ec2f5f89070a061189226e96833 Mon Sep 17 00:00:00 2001 From: Aman Dalmia Date: Sat, 1 May 2021 02:58:34 +0530 Subject: [PATCH 4/6] FIX: make UUID read-only again --- plio/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plio/serializers.py b/plio/serializers.py index e85ca104..c7625b2b 100644 --- a/plio/serializers.py +++ b/plio/serializers.py @@ -37,7 +37,7 @@ class Meta: "created_at", "updated_at", ] - # read_only_fields = ["uuid"] + read_only_fields = ["uuid"] def to_representation(self, instance): response = super().to_representation(instance) From 43b63264091e78700c39fa7e585a9121255869a4 Mon Sep 17 00:00:00 2001 From: Aman Dalmia Date: Sat, 1 May 2021 03:00:58 +0530 Subject: [PATCH 5/6] FIX: fixed github workflows of deployment to the correct values --- .github/workflows/deploy_to_ecs_prod.yml | 1 - .github/workflows/deploy_to_ecs_staging.yml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy_to_ecs_prod.yml b/.github/workflows/deploy_to_ecs_prod.yml index 153bbcbc..e7f1183e 100644 --- a/.github/workflows/deploy_to_ecs_prod.yml +++ b/.github/workflows/deploy_to_ecs_prod.yml @@ -1,7 +1,6 @@ # This workflow will build and push a new container image to Amazon ECR on: - pull_request: release: types: [published] diff --git a/.github/workflows/deploy_to_ecs_staging.yml b/.github/workflows/deploy_to_ecs_staging.yml index d2d95fb5..90020308 100644 --- a/.github/workflows/deploy_to_ecs_staging.yml +++ b/.github/workflows/deploy_to_ecs_staging.yml @@ -1,6 +1,7 @@ # This workflow will build and push a new container image to Amazon ECR on: + pull_request: push: branches: ["master"] From 66a4e807642cd9f4899d96b7b21f84049a7fd490 Mon Sep 17 00:00:00 2001 From: Aman Dalmia Date: Sat, 1 May 2021 12:45:29 +0530 Subject: [PATCH 6/6] Update docs/DEPLOYMENT.md Co-authored-by: deepansh96 --- docs/DEPLOYMENT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md index c1507e4a..e0fb8378 100644 --- a/docs/DEPLOYMENT.md +++ b/docs/DEPLOYMENT.md @@ -210,7 +210,7 @@ Follow the steps below to set up the staging environment on AWS. Setting up a production environment on AWS is almost the same as staging. Additionally, take care of the following things: 1. Rename all services as `plio-backend-production` or a similar naming convention. 2. Change all the environment variables to the corresponding values for the production environment. -3. We chose to use the same instance for the production and staging RDS instance while using a separate user and database for each environment to optimize for cost. +3. We chose to use the same RDS instance for production and staging, but a separate user and database for each environment to optimize for cost. 1. Once the RDS instance is created after following the step above, create the production DB in the same instance. 2. Connect to your RDS instance ```sh