Skip to content

Commit

Permalink
fix: only build docker image when changes
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldapm committed May 11, 2024
1 parent 48105ea commit 8bd6417
Showing 1 changed file with 60 additions and 26 deletions.
86 changes: 60 additions & 26 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,73 @@ name: Deploy app to Alibaba Cloud ECS with SSH
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
deploy:
# The type of runner that the job will run on
changes:
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
outputs:
codes: ${{ steps.changes.outputs.codes }}
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Runs a set of commands using the runners shell
- name: Deploy to Alibaba cloud
uses: appleboy/ssh-action@master
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
codes:
- 'src/**'
- 'Dockerfile'
- package*.json
docker:
runs-on: ubuntu-latest
if: ${{ needs.changes.outputs.codes == 'true' }}
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 Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: 22
script: |
pm2 delete all
pm2 reset all
cd /root/ta-undika-backend
git pull origin master
npm install
git stash
npm run start
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: geraldapm/physweb-backend:latest
# deploy:
# # The type of runner that the job will run on
# runs-on: ubuntu-latest

# # Steps represent a sequence of tasks that will be executed as part of the job
# steps:
# # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# - uses: actions/checkout@v2

# # Runs a set of commands using the runners shell
# - name: Deploy to Alibaba cloud
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USERNAME }}
# password: ${{ secrets.PASSWORD }}
# port: 22
# script: |
# pm2 delete all
# pm2 reset all
# cd /root/ta-undika-backend
# git pull origin master
# npm install
# git stash
# npm run start

0 comments on commit 8bd6417

Please sign in to comment.