Something went wrong. Try again.
forked from bgpkit/monocle
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133name: Docker
on: push: # On merge/push to main → tag as bgpkit/monocle:main branches: - main paths: - "Dockerfile" - "docker-compose.yml" - "src/**" - "Cargo.toml" - "Cargo.lock" - ".dockerignore" - ".github/workflows/docker.yml" # On new version tag → tag as bgpkit/monocle:{version} and bgpkit/monocle:latest tags: - v[0-9]+.*
permissions: contents: read
jobs: build: strategy: fail-fast: false matrix: include: - platform: linux/amd64 architecture: amd64 runner: ubuntu-latest - platform: linux/arm64 architecture: arm64 runner: ubuntu-24.04-arm runs-on: ${{ matrix.runner }} steps: - name: Checkout uses: actions/checkout@v4
- name: Docker meta id: meta uses: docker/metadata-action@v6 with: images: bgpkit/monocle # On branch push to main: type=ref,event=branch → "main" # On tag push v1.3.0: type=semver → "1.3.0", "1.3", and "latest" tags: | type=ref,event=branch type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
- name: Login to Docker Hub uses: docker/login-action@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v4
- name: Build and push by digest id: build uses: docker/build-push-action@v7 with: context: . platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=bgpkit/monocle,push-by-digest=true,name-canonical=true,push=true cache-from: type=registry,ref=bgpkit/monocle:buildcache-${{ matrix.architecture }} cache-to: type=registry,ref=bgpkit/monocle:buildcache-${{ matrix.architecture }},mode=max
- name: Export digest run: | mkdir -p "${{ runner.temp }}/digests" digest="${{ steps.build.outputs.digest }}" touch "${{ runner.temp }}/digests/${digest#sha256:}"
- name: Upload digest uses: actions/upload-artifact@v4 with: name: digests-${{ matrix.architecture }} path: ${{ runner.temp }}/digests/* if-no-files-found: error retention-days: 1
merge: needs: build runs-on: ubuntu-latest steps: - name: Docker meta id: meta uses: docker/metadata-action@v6 with: images: bgpkit/monocle # On branch push to main: type=ref,event=branch → "main" # On tag push v1.3.0: type=semver → "1.3.0", "1.3", and "latest" tags: | type=ref,event=branch type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
- name: Login to Docker Hub uses: docker/login-action@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v4
- name: Download digests uses: actions/download-artifact@v4 with: path: ${{ runner.temp }}/digests pattern: digests-* merge-multiple: true
- name: Create and push manifest list working-directory: ${{ runner.temp }}/digests env: DOCKER_METADATA_OUTPUT_JSON: ${{ steps.meta.outputs.json }} run: | args=() while IFS= read -r tag; do args+=(--tag "$tag") done < <(jq -r '.tags[]' <<< "$DOCKER_METADATA_OUTPUT_JSON") for digest in *; do args+=("bgpkit/monocle@sha256:$digest") done docker buildx imagetools create "${args[@]}"