Skip to content

ci: add envs to deployment file #2

ci: add envs to deployment file

ci: add envs to deployment file #2

Workflow file for this run

name: Deploy to EC2
on:
push:
branches:
- develop
- main
- feat/deploy-on-aws # Remove this after testing it, Do not merge without removeing this line
jobs:
build-and-push:
runs-on: ubuntu-latest
timeout-minutes: 10
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/arm64
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ github.sha }}
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_EC2_HOST }}
username: ${{ secrets.AWS_EC2_USERNAME }}
key: ${{ secrets.AWS_EC2_SSH_PRIVATE_KEY }}
script: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest
docker stop ${{ github.event.repository.name }}-${{vars.ENV}} || true
docker rm ${{ github.event.repository.name }}-${{vars.ENV}} || true
docker run -d -p ${{vars.PORT}}:${{vars.PORT}} \
--name ${{ github.event.repository.name }}-${{vars.ENV}} \
--network=${{vars.DOCKER_NETWORK}} \
-e BOT_PUBLIC_KEY=${{secrets.BOT_PUBLIC_KEY}} \
-e CLOUDINARY_API_KEY=${{secrets.CLOUDINARY_API_KEY}} \
-e CLOUDINARY_API_SECRET_KEY=${{secrets.CLOUDINARY_API_SECRET_KEY}} \
-e CLOUDINARY_CLOUD_NAME=${{secrets.CLOUDINARY_CLOUD_NAME}} \
-e CRON_JOB_PUBLIC_KEY=${{secrets.CRON_JOB_PUBLIC_KEY}} \
-e DISCORD_BASE_URL=${{vars.DISCORD_BASE_URL}} \
-e ENABLE_CONSOLE_LOGS=${{vars.ENABLE_CONSOLE_LOGS}} \
-e EVENT_100MS_APP_ACCESS_KEY=${{secrets.EVENT_100MS_APP_ACCESS_KEY}} \
-e EVENT_100MS_APP_SECRET=${{secrets.EVENT_100MS_APP_SECRET}} \
-e EXTERNAL_SERVICE_PUBLIC_KEY=${{secrets.EXTERNAL_SERVICE_PUBLIC_KEY}} \
-e FIRESTORE_CONFIG=${{secrets.FIRESTORE_CONFIG}} \
-e GITHUB_CLIENT_ID=${{secrets.GITHUB_CLIENT_ID}} \
-e GITHUB_CLIENT_SECRET=${{secrets.GITHUB_CLIENT_SECRET}} \
-e GITHUB_PERSONAL_ACCESS_TOKEN=${{secrets.GITHUB_PERSONAL_ACCESS_TOKEN}} \
-e IDENTITY_SERVICE_URL=${{secrets.IDENTITY_SERVICE_URL}} \
-e INTEGRATIONS_NEWRELIC_APPNAME=${{secrets.INTEGRATIONS_NEWRELIC_APPNAME}} \
-e INTEGRATIONS_NEWRELIC_LICENSEKEY=${{secrets.INTEGRATIONS_NEWRELIC_LICENSEKEY}} \
-e NODE_ENV=${{vars.ENV}} \
-e PRIVATE_KEY=${{secrets.PRIVATE_KEY}} \
-e PUBLIC_KEY=${{secrets.PUBLIC_KEY}} \
-e RDS_SERVERLESS_PRIVATE_KEY=${{secrets.RDS_SERVERLESS_PRIVATE_KEY}} \
-e RDS_SERVERLESS_PUBLIC_KEY=${{secrets.RDS_SERVERLESS_PUBLIC_KEY}} \
-e RDS_SERVERLESS_TTL=${{secrets.RDS_SERVERLESS_TTL}} \
-e SERVICES_RDSAPI_BASEURL=${{secrets.SERVICES_RDSAPI_BASEURL}} \
-e USER_TOKEN_REFRESH_TTL=${{secrets.USER_TOKEN_REFRESH_TTL}} \
-e USER_TOKEN_TTL=${{secrets.USER_TOKEN_TTL}} \
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}