|
| 1 | +name: Container Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - unstable |
| 7 | + - hotfixes |
| 8 | + - master |
| 9 | + tags: |
| 10 | + - 'v*' |
| 11 | + pull_request: |
| 12 | + |
| 13 | +jobs: |
| 14 | + pre_postgres: |
| 15 | + name: Path match check - postgres |
| 16 | + runs-on: ubuntu-latest |
| 17 | + # Map a step output to a job output |
| 18 | + outputs: |
| 19 | + should_skip: ${{ steps.skip_check.outputs.should_skip }} |
| 20 | + steps: |
| 21 | + - id: skip_check |
| 22 | + uses: fkirc/skip-duplicate-actions@master |
| 23 | + with: |
| 24 | + skip_after_successful_duplicate: false |
| 25 | + github_token: ${{ github.token }} |
| 26 | + paths: '["docker/Dockerfile.postgres.dev", ".github/workflows/containerbuild.yml"]' |
| 27 | + |
| 28 | + build_and_push_postgres: |
| 29 | + name: Postgres - build and push Docker image to GitHub Container Registry |
| 30 | + needs: pre_postgres |
| 31 | + if: ${{ needs.pre_postgres.outputs.should_skip != 'true' }} |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - name: Checkout codebase |
| 35 | + uses: actions/checkout@v4 |
| 36 | + |
| 37 | + - name: Set up QEMU |
| 38 | + uses: docker/setup-qemu-action@v3 |
| 39 | + |
| 40 | + - name: Set up Docker Buildx |
| 41 | + uses: docker/setup-buildx-action@v3 |
| 42 | + |
| 43 | + - name: Log in to Docker Hub |
| 44 | + if: github.event_name != 'pull_request' |
| 45 | + uses: docker/login-action@v3 |
| 46 | + with: |
| 47 | + registry: ghcr.io |
| 48 | + username: ${{ github.actor }} |
| 49 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + |
| 51 | + - name: Extract metadata (tags, labels) for Docker |
| 52 | + id: meta |
| 53 | + uses: docker/metadata-action@v5 |
| 54 | + with: |
| 55 | + images: ghcr.io/learningequality/postgres |
| 56 | + env: |
| 57 | + DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index |
| 58 | + |
| 59 | + - name: Build and push Docker image |
| 60 | + uses: docker/build-push-action@v5 |
| 61 | + with: |
| 62 | + context: ./docker |
| 63 | + file: ./docker/Dockerfile.postgres.dev |
| 64 | + platforms: linux/amd64,linux/arm64 |
| 65 | + push: ${{ github.event_name != 'pull_request' }} |
| 66 | + tags: ${{ steps.meta.outputs.tags }} |
| 67 | + labels: ${{ steps.meta.outputs.labels }} |
| 68 | + annotations: ${{ steps.meta.outputs.annotations }} |
| 69 | + |
| 70 | + pre_nginx: |
| 71 | + name: Path match check - nginx |
| 72 | + runs-on: ubuntu-latest |
| 73 | + # Map a step output to a job output |
| 74 | + outputs: |
| 75 | + should_skip: ${{ steps.skip_check.outputs.should_skip }} |
| 76 | + steps: |
| 77 | + - id: skip_check |
| 78 | + uses: fkirc/skip-duplicate-actions@master |
| 79 | + with: |
| 80 | + skip_after_successful_duplicate: false |
| 81 | + github_token: ${{ github.token }} |
| 82 | + paths: '["k8s/images/nginx/*", ".github/workflows/containerbuild.yml"]' |
| 83 | + |
| 84 | + build_nginx: |
| 85 | + name: nginx - test build of nginx Docker image |
| 86 | + needs: pre_nginx |
| 87 | + if: ${{ needs.pre_nginx.outputs.should_skip != 'true' }} |
| 88 | + runs-on: ubuntu-latest |
| 89 | + steps: |
| 90 | + - name: Checkout codebase |
| 91 | + uses: actions/checkout@v4 |
| 92 | + |
| 93 | + - name: Set up QEMU |
| 94 | + uses: docker/setup-qemu-action@v3 |
| 95 | + |
| 96 | + - name: Set up Docker Buildx |
| 97 | + uses: docker/setup-buildx-action@v3 |
| 98 | + |
| 99 | + - name: Build Docker image |
| 100 | + uses: docker/build-push-action@v5 |
| 101 | + with: |
| 102 | + context: ./ |
| 103 | + file: ./k8s/images/nginx/Dockerfile |
| 104 | + platforms: linux/amd64 |
| 105 | + push: false |
0 commit comments