|
| 1 | +name: Publish MongoDB Docker images |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: ["main"] |
| 7 | + paths: |
| 8 | + - mongodb/Dockerfile.* |
| 9 | + - .github/workflows/docker-mongodb.yml |
| 10 | + |
| 11 | +env: |
| 12 | + REGISTRY: index.docker.io |
| 13 | + IMAGE_NAME: binaryoverload/mongodb-client |
| 14 | + |
| 15 | +permissions: |
| 16 | + id-token: write |
| 17 | + attestations: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + publish_mongodb: |
| 21 | + name: Publish MongoDB Images |
| 22 | + runs-on: ubuntu-latest |
| 23 | + strategy: |
| 24 | + matrix: |
| 25 | + os: [ubuntu, alpine] |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Check out the repo |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Log in to Docker Hub |
| 32 | + uses: docker/login-action@v3 |
| 33 | + with: |
| 34 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 35 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 36 | + |
| 37 | + - name: Extract metadata (tags, labels) for Docker |
| 38 | + id: meta |
| 39 | + uses: docker/metadata-action@v5 |
| 40 | + with: |
| 41 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 42 | + tags: | |
| 43 | + type=raw,value=latest,enable=${{ matrix.os == 'ubuntu' }} |
| 44 | + type=raw,value=${{ matrix.os }} |
| 45 | +
|
| 46 | + - name: Set up Docker Buildx |
| 47 | + uses: docker/setup-buildx-action@v3 |
| 48 | + |
| 49 | + - name: Build and push Docker image |
| 50 | + id: push |
| 51 | + uses: docker/build-push-action@v5 |
| 52 | + with: |
| 53 | + context: ./mongodb |
| 54 | + platforms: linux/amd64,linux/arm64 |
| 55 | + file: ./mongodb/Dockerfile.${{ matrix.os }} |
| 56 | + push: true |
| 57 | + tags: ${{ steps.meta.outputs.tags }} |
| 58 | + labels: ${{ steps.meta.outputs.labels }} |
| 59 | + cache-from: type=gha |
| 60 | + cache-to: type=gha,mode=max |
| 61 | + |
| 62 | + - name: Attest |
| 63 | + uses: actions/attest-build-provenance@v2 |
| 64 | + id: attest |
| 65 | + with: |
| 66 | + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 67 | + subject-digest: ${{ steps.push.outputs.digest }} |
| 68 | + push-to-registry: true |
0 commit comments