-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploy: backend on lambda and frontend on ec2-ecs
- Loading branch information
Showing
19 changed files
with
604 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: DeployBackendDev | ||
|
||
on: | ||
push: | ||
branches: | ||
- "master" | ||
|
||
jobs: | ||
deploy-backend-dev: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
contents: read | ||
steps: | ||
- name: Checkout | ||
uses: actions/[email protected] | ||
|
||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: "^1.20" | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions-backend-access | ||
aws-region: ap-south-1 | ||
|
||
- name: Build backend and deploy to S3 | ||
run: | | ||
apt-get update && apt-get install -y zip | ||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go | ||
zip canopas_serverless_dev_${{ github.sha }}.zip main | ||
aws s3 cp canopas_serverless_dev_${{ github.sha }}.zip s3://canopas-lambda-handlers | ||
- name: Deploy cloudformation stack | ||
id: canopas-website-dev-lambda-stack | ||
uses: aws-actions/aws-cloudformation-github-deploy@v1 | ||
with: | ||
name: canopas-website-dev-lambda-stack | ||
template: infrastructure/backend.yml | ||
capabilities: CAPABILITY_IAM,CAPABILITY_NAMED_IAM | ||
timeout-in-minutes: "10" | ||
no-fail-on-empty-changeset: "1" | ||
parameter-overrides: >- | ||
EnvName=dev, | ||
Sender=${{ secrets.SENDER }}, | ||
ContactSender=${{ secrets.CONTACT_SENDER }}, | ||
JobsReceiver=${{ secrets.JOBS_RECEIVER }}, | ||
ContactReceiver=${{ secrets.CONTACT_RECEIVER }}, | ||
AccessKeyId=${{ secrets.ACCESS_KEY_ID }}, | ||
SecretAccessKey=${{ secrets.SECRET_ACCESS_KEY }}, | ||
Region=${{ secrets.AWS_REGION }}, | ||
DbUsername=${{ secrets.DB_USERNAME }}, | ||
DbPassword=${{ secrets.DB_PASSWORD }}, | ||
DbHost=${{ secrets.DB_HOST }}, | ||
DbPort=${{ secrets.DB_PORT }}, | ||
DbName=${{ secrets.DB_NAME }}, | ||
RecaptchaConfigJSONBase64=${{ secrets.RECAPTCHA_CONFIG_JSON_BASE64 }}, | ||
RecaptchaSiteKey=${{ secrets.RECAPTCHA_SITE_KEY }}, | ||
RecaptchaProjectId=${{ secrets.RECAPTCHA_PROJECT_ID }}, | ||
JobsSpreadsheetId=${{ secrets.JOBS_SPREADSHEET_ID }}, | ||
GithubAccessToken=${{ secrets.PERSONAL_ACCESS_TOKEN_GITHUB }}, | ||
ResourcesURL=${{secrets.RESOURCES_URL}}, | ||
LambdaBucket=canopas-lambda-handlers, | ||
LambdaUrl=canopas_serverless_dev_${{ github.sha }}.zip, | ||
LambdaTimeout=10, | ||
LambdaRoleName=canopas-dev-lambda-role, | ||
LambdaName=canopas-dev-lambda-function, | ||
ApiGatewayName=canopas-dev-lambda-api, | ||
CustomDomainName=${{ secrets.DEV_SERVERLESS_DOMAIN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: DeployBackendProd | ||
|
||
on: | ||
push: | ||
branches: | ||
- "master" | ||
|
||
jobs: | ||
deploy-backend-prod: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
contents: read | ||
steps: | ||
- name: Checkout | ||
uses: actions/[email protected] | ||
|
||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: "^1.20" | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions-backend-access | ||
aws-region: ap-south-1 | ||
|
||
- name: Build backend and deploy to S3 | ||
run: | | ||
apt-get update && apt-get install -y zip | ||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go | ||
zip canopas_serverless_prod_${{ github.sha }}.zip main | ||
aws s3 cp canopas_serverless_prod_${{ github.sha }}.zip s3://canopas-lambda-handlers | ||
- name: Deploy cloudformation stack | ||
id: canopas-website-prod-lambda-stack | ||
uses: aws-actions/aws-cloudformation-github-deploy@v1 | ||
with: | ||
name: canopas-website-prod-lambda-stack | ||
template: infrastructure/backend.yml | ||
capabilities: CAPABILITY_IAM,CAPABILITY_NAMED_IAM | ||
timeout-in-minutes: "10" | ||
no-fail-on-empty-changeset: "1" | ||
parameter-overrides: >- | ||
EnvName=prod, | ||
Sender=${{ secrets.SENDER }}, | ||
ContactSender=${{ secrets.CONTACT_SENDER }}, | ||
JobsReceiver=${{ secrets.JOBS_RECEIVER }}, | ||
ContactReceiver=${{ secrets.CONTACT_RECEIVER }}, | ||
AccessKeyId=${{ secrets.ACCESS_KEY_ID }}, | ||
SecretAccessKey=${{ secrets.SECRET_ACCESS_KEY }}, | ||
Region=${{ secrets.AWS_REGION }}, | ||
DbUsername=${{ secrets.DB_USERNAME }}, | ||
DbPassword=${{ secrets.DB_PASSWORD }}, | ||
DbHost=${{ secrets.DB_HOST }}, | ||
DbPort=${{ secrets.DB_PORT }}, | ||
DbName=${{ secrets.DB_NAME }}, | ||
RecaptchaConfigJSONBase64=${{ secrets.RECAPTCHA_CONFIG_JSON_BASE64 }}, | ||
RecaptchaSiteKey=${{ secrets.RECAPTCHA_SITE_KEY }}, | ||
RecaptchaProjectId=${{ secrets.RECAPTCHA_PROJECT_ID }}, | ||
JobsSpreadsheetId=${{ secrets.JOBS_SPREADSHEET_ID }}, | ||
GithubAccessToken=${{ secrets.PERSONAL_ACCESS_TOKEN_GITHUB }}, | ||
ResourcesURL=${{secrets.RESOURCES_URL}}, | ||
LambdaBucket=canopas-lambda-handlers, | ||
LambdaUrl=canopas_serverless_prod_${{ github.sha }}.zip, | ||
LambdaTimeout=10, | ||
LambdaRoleName=canopas-prod-lambda-role, | ||
LambdaName=canopas-prod-lambda-function, | ||
ApiGatewayName=canopas-prod-lambda-api, | ||
CustomDomainName=${{ secrets.PROD_SERVERLESS_DOMAIN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
name: DeployDev | ||
name: DeployFrontendDev | ||
|
||
on: | ||
repository_dispatch: | ||
types: [deploy-blog-dev] | ||
push: | ||
branches: | ||
- "master" | ||
|
||
jobs: | ||
deploy-dev: | ||
deploy-frontend-dev: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
|
@@ -17,7 +19,7 @@ jobs: | |
|
||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: "18" | ||
node-version: "20" | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
|
@@ -30,7 +32,6 @@ jobs: | |
cd nginx | ||
sed -i "s|WEBSITE_URL|dev-stack.canopas.com|g" conf.d/default.conf | ||
sed -i "s|API_URL|dev-stack-api.canopas.com|g" conf.d/default.conf | ||
sed -i "s|ARTICLES_URL|development.dzkjozipsd9ra.amplifyapp.com|g" conf.d/default.conf | ||
bash ./../deploy/deploy-ecr-image.sh dev-nginx ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/canopas-website-nginx | ||
- name: Build frontend and push on ECR | ||
|
@@ -40,48 +41,24 @@ jobs: | |
sh ./../deploy/generate-sitemap.sh https://dev-stack.canopas.com https://dev-stack-api.canopas.com | ||
bash ./../deploy/deploy-ecr-image.sh dev-frontend ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/canopas-website-frontend | ||
- name: Checkout | ||
uses: actions/[email protected] | ||
|
||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: "^1.17.5" | ||
|
||
- name: Build backend and push on ECR | ||
- name: Get latest blog image tag | ||
id: get_blog_image_tag | ||
run: | | ||
bash ./deploy/deploy-ecr-image.sh dev-backend ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/canopas-website-backend | ||
aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-south-1.amazonaws.com | ||
echo "::set-output name=blogImageTag::$(aws ecr describe-images --repository-name canopas-blog --output text --query 'sort_by(imageDetails,& imagePushedAt)[*].imageTags[*]' | grep -w 'dev' | tr '\t' '\n' | tail -1)" | ||
- name: Deploy cloudformation stack | ||
id: canopas-website-dev-ECS-EC2-stack | ||
uses: aws-actions/aws-cloudformation-github-deploy@v1 | ||
with: | ||
name: canopas-website-dev-ECS-EC2-stack | ||
template: infrastructure/template.yml | ||
template: infrastructure/frontend.yml | ||
capabilities: CAPABILITY_IAM,CAPABILITY_NAMED_IAM | ||
timeout-in-minutes: "10" | ||
no-fail-on-empty-changeset: "1" | ||
parameter-overrides: >- | ||
EnvName=dev, | ||
Sender=${{ secrets.SENDER }}, | ||
ContactSender=${{ secrets.CONTACT_SENDER }}, | ||
JobsReceiver=${{ secrets.JOBS_RECEIVER }}, | ||
ContactReceiver=${{ secrets.CONTACT_RECEIVER }}, | ||
AccessKeyId=${{ secrets.ACCESS_KEY_ID }}, | ||
SecretAccessKey=${{ secrets.SECRET_ACCESS_KEY }}, | ||
Region=${{ secrets.AWS_REGION }}, | ||
DbUsername=${{ secrets.DB_USERNAME }}, | ||
DbPassword=${{ secrets.DB_PASSWORD }}, | ||
DbHost=${{ secrets.DB_HOST }}, | ||
DbPort=${{ secrets.DB_PORT }}, | ||
DbName=${{ secrets.DB_NAME }}, | ||
RecaptchaConfigJSONBase64=${{ secrets.RECAPTCHA_CONFIG_JSON_BASE64 }}, | ||
RecaptchaSiteKey=${{ secrets.RECAPTCHA_SITE_KEY }}, | ||
RecaptchaProjectId=${{ secrets.RECAPTCHA_PROJECT_ID }}, | ||
JobsSpreadsheetId=${{ secrets.JOBS_SPREADSHEET_ID }}, | ||
JobsSheetId=${{ secrets.JOBS_SHEET_ID }}, | ||
GithubAccessToken=${{ secrets.PERSONAL_ACCESS_TOKEN_GITHUB }}, | ||
ResourcesURL=${{secrets.RESOURCES_URL}}, | ||
ClusterName=canopas-website-dev, | ||
ImageTag=${{ github.sha }}-${{ github.run_attempt }}-dev-frontend, | ||
BackendImageTag=${{ github.sha }}-${{ github.run_attempt }}-dev-backend, | ||
NginxImageTag=${{ github.sha }}-${{ github.run_attempt }}-dev-nginx | ||
NginxImageTag=${{ github.sha }}-${{ github.run_attempt }}-dev-nginx, | ||
BlogImageTag=${{steps.get_blog_image_tag.outputs.blogImageTag}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
name: DeployProd | ||
name: DeployFrontendProd | ||
|
||
on: | ||
repository_dispatch: | ||
types: [deploy-blog-prod] | ||
push: | ||
branches: | ||
- "master" | ||
|
||
jobs: | ||
deploy-prod: | ||
deploy-frontend-prod: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
|
@@ -16,7 +19,7 @@ jobs: | |
|
||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: "18" | ||
node-version: "20" | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
|
@@ -29,7 +32,6 @@ jobs: | |
cd nginx | ||
sed -i "s|WEBSITE_URL|canopas.com|g" conf.d/default.conf | ||
sed -i "s|API_URL|prod-stack-api.canopas.com|g" conf.d/default.conf | ||
sed -i "s|ARTICLES_URL|articles.canopas.com|g" conf.d/default.conf | ||
bash ./../deploy/deploy-ecr-image.sh prod-nginx ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/canopas-website-nginx | ||
- name: Build frontend and push on ECR | ||
|
@@ -39,49 +41,25 @@ jobs: | |
mv src/config.prod.js src/config.js | ||
sh ./../deploy/generate-sitemap.sh https://canopas.com https://prod-stack-api.canopas.com | ||
bash ./../deploy/deploy-ecr-image.sh prod-frontend ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/canopas-website-frontend | ||
- name: Checkout | ||
uses: actions/[email protected] | ||
|
||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: "^1.17.5" | ||
- name: Build backend and push on ECR | ||
- name: Get latest blog image tag | ||
id: get_blog_image_tag | ||
run: | | ||
bash ./deploy/deploy-ecr-image.sh prod-backend ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/canopas-website-backend | ||
aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-south-1.amazonaws.com | ||
echo "::set-output name=blogImageTag::$(aws ecr describe-images --repository-name canopas-blog --output text --query 'sort_by(imageDetails,& imagePushedAt)[*].imageTags[*]' | grep -w 'prod' | tr '\t' '\n' | tail -1)" | ||
- name: Deploy cloudformation stack | ||
id: canopas-website-prod-ECS-EC2-stack | ||
uses: aws-actions/aws-cloudformation-github-deploy@v1 | ||
with: | ||
name: canopas-website-prod-ECS-EC2-stack | ||
template: infrastructure/template.yml | ||
template: infrastructure/frontend.yml | ||
capabilities: CAPABILITY_IAM,CAPABILITY_NAMED_IAM | ||
timeout-in-minutes: "10" | ||
no-fail-on-empty-changeset: "1" | ||
parameter-overrides: >- | ||
EnvName=prod, | ||
Sender=${{ secrets.SENDER }}, | ||
ContactSender=${{ secrets.CONTACT_SENDER }}, | ||
JobsReceiver=${{ secrets.JOBS_RECEIVER }}, | ||
ContactReceiver=${{ secrets.CONTACT_RECEIVER }}, | ||
AccessKeyId=${{ secrets.ACCESS_KEY_ID }}, | ||
SecretAccessKey=${{ secrets.SECRET_ACCESS_KEY }}, | ||
Region=${{ secrets.AWS_REGION }}, | ||
DbUsername=${{ secrets.DB_USERNAME }}, | ||
DbPassword=${{ secrets.DB_PASSWORD }}, | ||
DbHost=${{ secrets.DB_HOST }}, | ||
DbPort=${{ secrets.DB_PORT }}, | ||
DbName=${{ secrets.DB_NAME }}, | ||
RecaptchaConfigJSONBase64=${{ secrets.RECAPTCHA_CONFIG_JSON_BASE64 }}, | ||
RecaptchaSiteKey=${{ secrets.RECAPTCHA_SITE_KEY }}, | ||
RecaptchaProjectId=${{ secrets.RECAPTCHA_PROJECT_ID }}, | ||
JobsSpreadsheetId=${{ secrets.JOBS_SPREADSHEET_ID }}, | ||
JobsSheetId=${{ secrets.JOBS_SHEET_ID }}, | ||
GithubAccessToken=${{ secrets.PERSONAL_ACCESS_TOKEN_GITHUB }}, | ||
ResourcesURL=${{secrets.RESOURCES_URL}}, | ||
ClusterName=canopas-website-prod, | ||
ImageTag=${{ github.sha }}-${{ github.run_attempt }}-prod-frontend, | ||
BackendImageTag=${{ github.sha }}-${{ github.run_attempt }}-prod-backend, | ||
NginxImageTag=${{ github.sha }}-${{ github.run_attempt }}-prod-nginx | ||
NginxImageTag=${{ github.sha }}-${{ github.run_attempt }}-prod-nginx, | ||
BlogImageTag=${{steps.get_blog_image_tag.outputs.blogImageTag}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.