Skip to content

Instantly share code, notes, and snippets.

@tgmarinho
Created April 10, 2024 13:56
Show Gist options
  • Save tgmarinho/0ccad0b8cdc3d4b21485df015ce9e41d to your computer and use it in GitHub Desktop.
Save tgmarinho/0ccad0b8cdc3d4b21485df015ce9e41d to your computer and use it in GitHub Desktop.
main branch - .github/actions
name: Deploy COMPANY API & Cronjobs API Production
concurrency:
group: production-api-${{ github.ref }}
on:
push:
branches:
- main
env:
AWS_REGION: "us-east-1"
EBS_APPLICATION_NAME: "COMPANY Production"
EBS_ENVIRONMENT_TO_DEPLOY: "COMPANY-API-prod"
CROBJOBS_EBS_ENVIRONMENT_TO_DEPLOY: "COMPANY-Cronjob-API-prod"
COMPANY_ADMIN_ENDPOINT: "admin.company.com"
COMPANY_FACILITY_ENDPOINT: "facility.company.com"
COMPANY_CRONJOBS_ENDPOINT: "cronjob.company.com"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
# - name: Update environment.dev.ts deploy
# run: |
# sed -i 's|https://dev-admin.company.com|https://${{ env.COMPANY_ADMIN_ENDPOINT }}|' src/config/config.js
# sed -i 's|https://dev-facility.company.com|https://${{ env.COMPANY_FACILITY_ENDPOINT }}|' src/config/config.js
# sed -i 's|https://cronjob-dev.company.com|https://${{ env.COMPANY_CRONJOBS_ENDPOINT }}|' src/config/config.js
- name: Create Temporary Dev Procfile
run: |
echo "web: npm start" > Procfile
- name: Allow legacy peer dependency (Fixes NPM install)
run: |
echo '
legacy-peer-deps=true
ignore-scripts=true
' > .npmrc
- name: Create dev ecosystem.config.js
run: |
echo '{
"apps": [
{
"name": "app",
"script": "src/server.js",
"instances": 1,
"autorestart": true,
"node_args": "--max_old_space_size=4096",
"watch": false,
"time": true,
"log_type": "json",
"env": {
"NODE_ENV": "production"
}
}
]
}' > ecosystem.config.json
- name: Set short git commit SHA
id: vars
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
- name: Generate deployment package
run: zip -r deploy.zip . -x '*.git*'
- name: Deploy to API to EB
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ env.EBS_APPLICATION_NAME }}
environment_name: ${{ env.EBS_ENVIRONMENT_TO_DEPLOY }}
version_label: ${{ env.EBS_ENVIRONMENT_TO_DEPLOY }}-${{ env.COMMIT_SHORT_SHA }}
region: ${{ env.AWS_REGION }}
wait_for_environment_recovery: 60
use_existing_version_if_available: true
deployment_package: deploy.zip
- name: Deploy to Cronjobs API to EB
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ env.EBS_APPLICATION_NAME }}
environment_name: ${{ env.CROBJOBS_EBS_ENVIRONMENT_TO_DEPLOY }}
version_label: ${{ env.CROBJOBS_EBS_ENVIRONMENT_TO_DEPLOY }}-${{ env.COMMIT_SHORT_SHA }}
region: ${{ env.AWS_REGION }}
wait_for_environment_recovery: 60
use_existing_version_if_available: true
deployment_package: deploy.zip
name: Deploy COMPANY API & Cronjobs API Staging
concurrency:
group: staging-api-${{ github.ref }}
on:
push:
branches:
- staging
env:
AWS_REGION: "us-east-1"
EBS_APPLICATION_NAME: "COMPANY Staging"
EBS_ENVIRONMENT_TO_DEPLOY: "COMPANY-API-staging"
CROBJOBS_EBS_ENVIRONMENT_TO_DEPLOY: "COMPANY-Cronjob-API-staging"
COMPANY_ADMIN_ENDPOINT: "uat-admin.company.com"
COMPANY_FACILITY_ENDPOINT: "uat-facility.company.com"
COMPANY_CRONJOBS_ENDPOINT: "cronjob-uat.company.com"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
# - name: Update environment.dev.ts
# run: |
# sed -i 's|https://dev-admin.company.com|https://${{ env.COMPANY_ADMIN_ENDPOINT }}|' src/config/config.js
# sed -i 's|https://dev-facility.company.com|https://${{ env.COMPANY_FACILITY_ENDPOINT }}|' src/config/config.js
# sed -i 's|https://cronjob-dev.company.com|https://${{ env.COMPANY_CRONJOBS_ENDPOINT }}|' src/config/config.js
- name: Create Temporary Dev Procfile
run: |
echo "web: npm start" > Procfile
- name: Create dev ecosystem.config.js
run: |
echo '{
"apps": [
{
"name": "app",
"script": "src/server.js",
"instances": 1,
"autorestart": true,
"watch": false,
"time": true,
"log_type": "json",
"env": {
"NODE_ENV": "uat"
}
}
]
}' > ecosystem.config.json
- name: Set short git commit SHA
id: vars
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
- name: Generate deployment package
run: zip -r deploy.zip . -x '*.git*'
- name: Deploy to API to EB
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ env.EBS_APPLICATION_NAME }}
environment_name: ${{ env.EBS_ENVIRONMENT_TO_DEPLOY }}
version_label: ${{ env.EBS_ENVIRONMENT_TO_DEPLOY }}-${{ env.COMMIT_SHORT_SHA }}
region: ${{ env.AWS_REGION }}
wait_for_environment_recovery: 60
use_existing_version_if_available: true
deployment_package: deploy.zip
- name: Deploy to Cronjobs API to EB
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ env.EBS_APPLICATION_NAME }}
environment_name: ${{ env.CROBJOBS_EBS_ENVIRONMENT_TO_DEPLOY }}
version_label: ${{ env.CROBJOBS_EBS_ENVIRONMENT_TO_DEPLOY }}-${{ env.COMMIT_SHORT_SHA }}
region: ${{ env.AWS_REGION }}
wait_for_environment_recovery: 60
use_existing_version_if_available: true
deployment_package: deploy.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment