From 9dc51a5262c2cf905e59856acaf1280c22424e5f Mon Sep 17 00:00:00 2001 From: Truong Quang Tinh Date: Sat, 25 May 2024 07:55:35 +0700 Subject: [PATCH] add github workflow --- .github/workflows/deploy.yaml | 65 +++++++++++++++++++++++++++++++++++ .gitignore | 4 +++ 2 files changed, 69 insertions(+) create mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..47d3e4a --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,65 @@ +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/ssh-action@v1.0.3 + # 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 diff --git a/.gitignore b/.gitignore index e8f682b..642a2d1 100644 --- a/.gitignore +++ b/.gitignore @@ -88,3 +88,7 @@ sw.* # Vim swap files *.swp + +*tfstate* + +.terraform