add github workflow #1
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
name: Deploy to EC2 | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set SHA-COMMIT | |
id: vars | |
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: back | |
platforms: linux/amd64 | |
push: true | |
tags: | | |
ghcr.io/tinhtq/example-project-backend:latest | |
ghcr.io/tinhtq/example-project-backend:${{ steps.vars.outputs.sha_short }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: front | |
platforms: linux/amd64 | |
push: true | |
tags: | | |
ghcr.io/tinhtq/example-project-frontend:latest | |
ghcr.io/tinhtq/example-project-frontend:${{ steps.vars.outputs.sha_short }} | |
# deploy: | |
# needs: build | |
# runs-on: ubuntu-latest | |
# timeout-minutes: 5 | |
# steps: | |
# - name: Deploy | |
# uses: appleboy/[email protected] | |
# with: | |
# host: ${{ secrets.EC2_HOST }} | |
# username: ${{ secrets.EC2_USERNAME }} | |
# key: ${{ secrets.KEY }} | |
# port: ${{ secrets.PORT }} | |
# command_timeout: 30m | |
# script: | | |
# cd ${{ vars.DIRECTORY }} | |
# docker compose pull | |
# docker compose up -d |