ci: build own Docker image from newsdiff app source #1
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 and push Docker image | |
| on: | |
| push: | |
| branches: [main] | |
| tags: ["v*"] | |
| workflow_dispatch: | |
| schedule: | |
| # Rebuild weekly to pick up latest newsdiff app image layers | |
| - cron: '0 6 * * 1' | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ghcr.io/rmdes/newsdiff-deploy | |
| jobs: | |
| validate: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Validate docker-compose.yml | |
| env: | |
| ORIGIN: https://example.com | |
| POSTGRES_PASSWORD: ci-test-password | |
| run: docker compose config --quiet | |
| - name: Check nginx config syntax | |
| run: | | |
| docker run --rm \ | |
| -v "$PWD/nginx.conf:/etc/nginx/nginx.conf:ro" \ | |
| --add-host app:127.0.0.1 \ | |
| --add-host bot:127.0.0.1 \ | |
| nginx:alpine nginx -t | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: validate | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| # Clone the app source to build from | |
| - name: Clone newsdiff app | |
| run: git clone --depth 1 https://github.com/rmdes/newsdiff.git app | |
| - uses: docker/setup-buildx-action@v3 | |
| - uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: docker/metadata-action@v5 | |
| id: meta | |
| with: | |
| images: ${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch | |
| type=semver,pattern={{version}} | |
| type=sha | |
| - uses: docker/build-push-action@v6 | |
| with: | |
| context: ./app | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |