fix build to run if any files outside ignore are changed #34
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: Build Image 🏗️ and Deploy to VPS 🚀 | |
| # Builds the Docker image and deploys it to the VPS. | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| # Don't run full build on only public or mdx changes | |
| paths-ignore: | |
| - "!public/**" | |
| - "!mdx/**" | |
| - "!LICENSE" | |
| - "!README.md" | |
| - "!.gitignore" | |
| - "!.dockerignore" | |
| - "!.prettierignore" | |
| release: | |
| types: [published] | |
| jobs: | |
| build-versioned: | |
| runs-on: ubuntu-latest | |
| name: Built Versioned Image | |
| if: github.event_name == 'release' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ secrets.DOCKERHUB_USERNAME }}/sourcedepth.com | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/sourcedepth.com:${{ github.event.release.tag_name }} | |
| ${{ secrets.DOCKERHUB_USERNAME }}/sourcedepth.com:latest | |
| annotations: ${{ steps.meta.outputs.annotations }} | |
| build-latest: | |
| runs-on: ubuntu-latest | |
| name: Build Latest Image | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ secrets.DOCKERHUB_USERNAME }}/sourcedepth.com | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/sourcedepth.com:latest | |
| annotations: ${{ steps.meta.outputs.annotations }} | |
| deploy: | |
| runs-on: ubuntu-latest | |
| name: Deploy to VPS | |
| needs: build-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Update files on VPS | |
| uses: appleboy/scp-action@v1 | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_KEY }} | |
| port: ${{ secrets.SSH_PORT }} | |
| passphrase: ${{ secrets.SSH_PASSPHRASE }} | |
| source: "./public,./mdx,./docker-compose.yml,./nginx" | |
| target: "~/sourcedepth.com/" | |
| overwrite: true | |
| - name: Build and restart Docker containers | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_KEY }} | |
| port: ${{ secrets.SSH_PORT }} | |
| passphrase: ${{ secrets.SSH_PASSPHRASE }} | |
| script: | | |
| cd ~/sourcedepth.com | |
| docker compose down | |
| docker compose build --pull --no-cache | |
| docker compose up -d | |
| docker system prune -f |