Add detailed logging, auto-deployment, and bump to v2.1.4 #12
This file contains hidden or 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: Publish Docker image | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'package.json' | |
| - 'server.js' | |
| - 'cleanup.js' | |
| - 'Dockerfile' | |
| - '**.js' | |
| jobs: | |
| check_version: | |
| name: Check if version changed | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version_changed: ${{ steps.check.outputs.changed }} | |
| version: ${{ steps.get_version.outputs.version }} | |
| steps: | |
| - name: Check out the repo | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check if package.json version changed | |
| id: check | |
| run: | | |
| # Get the before and after commits from the push event | |
| BEFORE="${{ github.event.before }}" | |
| AFTER="${{ github.sha }}" | |
| echo "Comparing $BEFORE...$AFTER" | |
| if git diff $BEFORE $AFTER -- package.json | grep -q '"version"'; then | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| echo "Version changed detected" | |
| else | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| echo "No version change detected" | |
| fi | |
| - name: Get version from package.json | |
| id: get_version | |
| if: steps.check.outputs.changed == 'true' | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Version: $VERSION" | |
| push_to_registry: | |
| name: Push Docker image to Docker Hub | |
| runs-on: ubuntu-latest | |
| needs: check_version | |
| if: needs.check_version.outputs.version_changed == 'true' | |
| steps: | |
| - name: Check out the repo | |
| uses: actions/checkout@v4 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: | | |
| zeeguu/readability_server:${{ needs.check_version.outputs.version }} | |
| zeeguu/readability_server:latest | |
| labels: | | |
| org.opencontainers.image.version=${{ needs.check_version.outputs.version }} | |
| org.opencontainers.image.created=${{ github.event.head_commit.timestamp }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| deploy_to_server: | |
| name: Deploy to production server | |
| runs-on: ubuntu-latest | |
| needs: [check_version, push_to_registry] | |
| if: needs.check_version.outputs.version_changed == 'true' | |
| steps: | |
| - name: Deploy via SSH | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| script: | | |
| cd /home/zeeguu/ops/running/api | |
| docker compose pull readability_server | |
| docker compose up -d readability_server | |
| echo "Deployed readability_server version ${{ needs.check_version.outputs.version }}" |