Repository navigation
Improve Docker worflow to publish images #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1e31582
Add reusable docker image workflow
gmazoyer 27b1e65
Use workflow with `published: false` in classic CI
gmazoyer d0079f8
Add release workflow
gmazoyer 50dde53
Fix image name
gmazoyer 3c6d9ef
Also publish binaries
gmazoyer 1bf2a07
Use fixed Ubuntu version for runner
gmazoyer fbebc77
Use goreleaser to build binaries
gmazoyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| --- | ||
| name: Build And Push Docker image | ||
|
|
||
| "on": | ||
| workflow_call: | ||
| inputs: | ||
| publish: | ||
| type: boolean | ||
| description: Whether to publish the image to the registry | ||
| required: false | ||
| default: false | ||
| ref: | ||
| type: string | ||
| required: true | ||
| description: The git ref to build from | ||
| tags: | ||
| type: string | ||
| required: true | ||
| description: The tags for the docker image | ||
| labels: | ||
| type: string | ||
| required: true | ||
| description: The labels for the docker image | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ inputs.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| env: | ||
| DOCKERFILE: "Dockerfile" | ||
| REGISTRY_IMAGE: ${{ vars.HARBOR_HOST }}/${{ github.repository }} | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ${{ matrix.runner }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - platform: linux/amd64 | ||
| runner: ubuntu-24.04 | ||
| - platform: linux/arm64 | ||
| runner: ubuntu-24.04-arm | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ inputs.ref }} | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v4 | ||
|
|
||
| - name: Login to registry | ||
| if: ${{ inputs.publish }} | ||
| uses: docker/login-action@v4 | ||
| with: | ||
| registry: ${{ vars.HARBOR_HOST }} | ||
| username: ${{ secrets.HARBOR_USERNAME }} | ||
| password: ${{ secrets.HARBOR_PASSWORD }} | ||
|
|
||
| - name: Build and push by digest | ||
| id: build | ||
| uses: docker/build-push-action@v7 | ||
| with: | ||
| context: . | ||
| file: ${{ env.DOCKERFILE }} | ||
| provenance: false | ||
| platforms: ${{ matrix.platform }} | ||
| labels: ${{ inputs.labels }} | ||
| outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=${{ inputs.publish }} | ||
|
|
||
| - name: Export digest | ||
| if: ${{ inputs.publish }} | ||
| run: | | ||
| mkdir -p /tmp/digests | ||
| digest="${{ steps.build.outputs.digest }}" | ||
| touch "/tmp/digests/${digest#sha256:}" | ||
|
|
||
| - name: Upload digest | ||
| if: ${{ inputs.publish }} | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: digests-${{ matrix.runner }} | ||
| path: /tmp/digests/* | ||
| if-no-files-found: error | ||
| retention-days: 1 | ||
|
|
||
| merge: | ||
| runs-on: ubuntu-latest | ||
| if: ${{ inputs.publish }} | ||
| needs: build | ||
| steps: | ||
| - name: Download digests | ||
| uses: actions/download-artifact@v7 | ||
| with: | ||
| path: /tmp/digests | ||
| pattern: digests-* | ||
| merge-multiple: true | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v4 | ||
|
|
||
| - name: Login to registry | ||
| uses: docker/login-action@v4 | ||
| with: | ||
| registry: ${{ vars.HARBOR_HOST }} | ||
| username: ${{ secrets.HARBOR_USERNAME }} | ||
| password: ${{ secrets.HARBOR_PASSWORD }} | ||
|
|
||
| - name: Create manifest list and push | ||
| working-directory: /tmp/digests | ||
| env: | ||
| TAGS: ${{ inputs.tags }} | ||
| run: | | ||
| tag_args=$(echo "$TAGS" | xargs printf -- '--tag %s\n') | ||
| digest_args=$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) | ||
| docker buildx imagetools create $tag_args $digest_args |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| --- | ||
| version: 2 | ||
|
|
||
| before: | ||
| hooks: | ||
| - rustup default stable | ||
| - cargo install --locked cargo-zigbuild | ||
|
|
||
| builds: | ||
| - id: infrahub-git-credential | ||
| builder: rust | ||
| binary: infrahub-git-credential | ||
| command: zigbuild | ||
| flags: | ||
| - --release | ||
| - --bin | ||
| - infrahub-git-credential | ||
| targets: | ||
| - x86_64-unknown-linux-musl | ||
| - aarch64-unknown-linux-musl | ||
| - x86_64-apple-darwin | ||
| - aarch64-apple-darwin | ||
|
|
||
| - id: infrahub-git-askpass | ||
| builder: rust | ||
| binary: infrahub-git-askpass | ||
| command: zigbuild | ||
| flags: | ||
| - --release | ||
| - --bin | ||
| - infrahub-git-askpass | ||
| targets: | ||
| - x86_64-unknown-linux-musl | ||
| - aarch64-unknown-linux-musl | ||
| - x86_64-apple-darwin | ||
| - aarch64-apple-darwin | ||
|
|
||
| universal_binaries: | ||
| - ids: | ||
| - infrahub-git-credential | ||
| replace: true | ||
| - ids: | ||
| - infrahub-git-askpass | ||
| replace: true | ||
|
|
||
| archives: | ||
| - formats: | ||
| - tar.gz | ||
| name_template: >- | ||
| {{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }} | ||
|
|
||
| checksum: | ||
| name_template: checksums.txt | ||
|
|
||
| release: | ||
| prerelease: auto |
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:smart: