Skip to content

CI: add timeout, network, image #3

CI: add timeout, network, image

CI: add timeout, network, image #3

name: Deploy to EC2
on:
push:
branches:
- develop
- feat/aws-deploy # Remove before merting this PR to dev
jobs:
build-and-push:
runs-on: ubuntu-latest
timeout-minutes: 10
environment: 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
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ github.sha }}
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 }}:${{ github.sha }}
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}} \
--expose 4010 \
--network=${{vars.DOCKER_NETWORK}} \
-e GIN_MODE=${{vars.GIN_MODE}}
-e JWT_SECRET=${{secrets.JWT_SECRET}} \
-e JWT_VALIDITY_IN_HOURS=${{vars.JWT_VALIDITY_IN_HOURS}} \
-e JWT_ISSUER=${{vars.JWT_ISSUER}} \
-e PORT=${{vars.PORT}} \
-e DOMAIN=${{vars.DOMAIN}} \
-e AUTH_REDIRECT_URL=${{vars.AUTH_REDIRECT_URL}} \
-e DB_URL=postgresql://${{secrets.POSTGRES_USER}}:${{secrets.POSTGRES_PASSWORD}}@${{secrets.DB_HOST}}:${{secrets.DB_PORT}}/${{secrets.POSTGRES_DB}}?sslmode=disable \
-e DB_MAX_OPEN_CONNECTIONS=${{vars.DB_MAX_OPEN_CONNECTIONS}} \
-e GOOGLE_CLIENT_ID=${{secrets.GOOGLE_CLIENT_ID}} \
-e GOOGLE_CLIENT_SECRET=${{secrets.GOOGLE_CLIENT_SECRET}} \
-e GOOGLE_REDIRECT_URL=${{vars.GOOGLE_REDIRECT_URL}} \
-e ALLOWED_ORIGINS=${{vars.ALLOWED_ORIGINS}} \
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}