Skip to content

Commit

Permalink
Deploy backend to lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sumi-k committed Sep 18, 2023
1 parent b387090 commit 0bc81a7
Show file tree
Hide file tree
Showing 16 changed files with 1,266 additions and 319 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/deploy-backend-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: DeployBackendDev

on:
push:

jobs:
deploy-dev:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/[email protected]

- uses: actions/setup-node@v1
with:
node-version: "18"

- 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: Checkout
uses: actions/[email protected]

- uses: actions/setup-go@v2
with:
go-version: "^1.20"

- 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.zip main
aws s3 cp canopas_serverless_dev.zip s3://canopas-dev-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-dev-lambda-handlers,
LambdaUrl=canopas_serverless_dev.zip,
LambdaTimeout=10,
LambdaRoleArnName=${{ secrets.LAMBDA_ROLE_ARN_NAME }},
LambdaFunctionArnName=${{ secrets.DEV_LAMBDA_FUNCTION_ARN_NAME }},
LambdaRoleName=canopas-dev-lambda-role,
LambdaName=canopas-dev-lambda-function,
ApiGatewayName=canopas-dev-lambda-api,
CustomDomainName=test-api.canopas.com
79 changes: 79 additions & 0 deletions .github/workflows/deploy-backend-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: DeployBackendDev

on:
push:
branches:
- "master"

jobs:
deploy-dev:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/[email protected]

- uses: actions/setup-node@v1
with:
node-version: "18"

- 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: Checkout
uses: actions/[email protected]

- uses: actions/setup-go@v2
with:
go-version: "^1.20"

- 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.zip main
aws s3 cp canopas_serverless_dev.zip s3://canopas-dev-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-dev-lambda-handlers,
LambdaUrl=canopas_serverless_dev.zip,
LambdaTimeout=10,
LambdaRoleArnName=${{ secrets.LAMBDA_ROLE_ARN_NAME }},
LambdaFunctionArnName=${{ secrets.DEV_LAMBDA_FUNCTION_ARN_NAME }},
LambdaRoleName=canopas-dev-lambda-role,
LambdaName=canopas-dev-lambda-function,
ApiGatewayName=canopas-dev-lambda-api,
CustomDomainName=test-api.canopas.com
Original file line number Diff line number Diff line change
Expand Up @@ -40,48 +40,17 @@ 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
run: |
bash ./deploy/deploy-ecr-image.sh dev-backend ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/canopas-website-backend
- 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- "master"

jobs:
deploy-prod:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -39,49 +39,18 @@ 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
run: |
bash ./deploy/deploy-ecr-image.sh prod-backend ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/canopas-website-backend
- 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
2 changes: 1 addition & 1 deletion blogs/blog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"utils"

"github.com/gin-gonic/gin"
"github.com/tj/assert"
"github.com/stretchr/testify/assert"
)

func Test_Unique_Int_Success(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions blogs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/aws/aws-sdk-go v1.44.83
github.com/gin-gonic/gin v1.9.0
github.com/sirupsen/logrus v1.9.0
github.com/tj/assert v0.0.3
github.com/stretchr/testify v1.8.1
utils v0.0.0-00010101000000-000000000000
)

Expand Down Expand Up @@ -44,7 +44,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
go.opencensus.io v0.23.0 // indirect
Expand Down
3 changes: 0 additions & 3 deletions blogs/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU=
Expand Down Expand Up @@ -734,7 +732,6 @@ gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
22 changes: 12 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ require (
contact v0.0.0-00010101000000-000000000000
contribution v0.0.0-00010101000000-000000000000
db v0.0.0
github.com/aws/aws-lambda-go v1.41.0
github.com/awslabs/aws-lambda-go-api-proxy v0.14.0
github.com/gin-contrib/cors v1.4.0
github.com/gin-contrib/gzip v0.0.6
github.com/gin-gonic/gin v1.9.1
github.com/jmoiron/sqlx v1.3.5
github.com/sirupsen/logrus v1.9.3
jobs v0.0.0-00010101000000-000000000000
leave v0.0.0-00010101000000-000000000000
notification v0.0.0-00010101000000-000000000000
Expand All @@ -41,14 +43,14 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/recaptchaenterprise/v2 v2.7.2 // indirect
github.com/aws/aws-sdk-go v1.44.322 // indirect
github.com/bytedance/sonic v1.10.0 // indirect
github.com/bytedance/sonic v1.10.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.15.0 // indirect
github.com/go-playground/validator/v10 v10.15.4 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -59,24 +61,24 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/arch v0.4.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/arch v0.5.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/api v0.136.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230807174057-1744710a1577 // indirect
Expand Down
Loading

0 comments on commit 0bc81a7

Please sign in to comment.