-
Notifications
You must be signed in to change notification settings - Fork 56
feat: publish container images to GHCR #695
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
Open
rizlas
wants to merge
9
commits into
nextcloud:main
Choose a base branch
from
ConsortiumGARR:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4c1b7d6
feat: build docker image via github actions
rizlas 997d5a1
Merge pull request #1 from ConsortiumGARR/gh
rizlas c50b887
ci: add upstream tag support, GHA layer cache and conditional version…
rizlas 0937b93
ci: use metadata-action for tag management, strip v prefix from upstr…
rizlas 90e3808
ci: use native runners matrix to eliminate QEMU overhead
rizlas 077da13
ci: fix lower casing
rizlas 55f70d0
chore: indentation
rizlas bb43000
ci: actions update
rizlas fd479e6
ci: fix tag naming pattern
rizlas 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,173 @@ | ||
| # Inspired by https://github.com/sredevopsorg/multi-arch-docker-github-workflow | ||
| name: Docker Image CI | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "[0-9]+.[0-9]+.[0-9]+" | ||
| workflow_dispatch: | ||
| inputs: | ||
| upstream_tag: | ||
| description: "Upstream tag of nextcloud/notify_push to build" | ||
| required: false | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ${{ matrix.runner }} | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - platform: linux/amd64 | ||
| runner: ubuntu-latest | ||
| - platform: linux/arm64 | ||
| runner: ubuntu-24.04-arm | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| repository: ${{ inputs.upstream_tag && 'nextcloud/notify_push' || github.repository }} | ||
| ref: ${{ inputs.upstream_tag || github.ref_name }} | ||
|
|
||
| - name: Log in to GitHub Packages | ||
| uses: docker/login-action@v4 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v4 | ||
|
|
||
| - name: Lower case docker image name | ||
| id: image | ||
| uses: ASzc/change-string-case-action@v8 | ||
| with: | ||
| string: ${{ github.repository }} | ||
|
|
||
| - name: Sanitize upstream tag | ||
| if: inputs.upstream_tag != '' | ||
| id: tag | ||
| run: echo "value=${INPUT_TAG#v}" >> $GITHUB_OUTPUT | ||
| env: | ||
| INPUT_TAG: ${{ inputs.upstream_tag }} | ||
|
|
||
| - name: Extract metadata | ||
| id: meta | ||
| uses: docker/metadata-action@v6 | ||
| with: | ||
| images: ghcr.io/${{ github.repository }} | ||
| tags: | | ||
| type=ref,event=tag | ||
| type=raw,value=latest | ||
| type=raw,value=${{ steps.tag.outputs.value }},enable=${{ inputs.upstream_tag != '' }} | ||
|
|
||
| - 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=ghcr.io/${{ steps.image.outputs.lowercase }},push-by-digest=true,name-canonical=true,push=true | ||
| cache-from: type=gha,scope=${{ matrix.platform }} | ||
| cache-to: type=gha,mode=max,scope=${{ matrix.platform }} | ||
|
|
||
| - name: Export digest | ||
| run: | | ||
| mkdir -p /tmp/digests | ||
| touch "/tmp/digests/${DIGEST#sha256:}" | ||
| env: | ||
| DIGEST: ${{ steps.build.outputs.digest }} | ||
|
|
||
| - name: Upload digest | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: digests-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} | ||
| path: /tmp/digests/* | ||
| if-no-files-found: error | ||
| retention-days: 1 | ||
|
|
||
| merge: | ||
| runs-on: ubuntu-latest | ||
| needs: build | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| steps: | ||
| - name: Download digests | ||
| uses: actions/download-artifact@v8 | ||
| with: | ||
| path: /tmp/digests | ||
| pattern: digests-* | ||
| merge-multiple: true | ||
|
|
||
| - name: Log in to GitHub Packages | ||
| uses: docker/login-action@v4 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v4 | ||
|
|
||
| - name: Lower case docker image name | ||
| id: image | ||
| uses: ASzc/change-string-case-action@v8 | ||
| with: | ||
| string: ${{ github.repository }} | ||
|
|
||
| - name: Sanitize upstream tag | ||
| if: inputs.upstream_tag != '' | ||
| id: tag | ||
| run: echo "value=${INPUT_TAG#v}" >> $GITHUB_OUTPUT | ||
| env: | ||
| INPUT_TAG: ${{ inputs.upstream_tag }} | ||
|
|
||
| - name: Extract metadata | ||
| id: meta | ||
| uses: docker/metadata-action@v6 | ||
| with: | ||
| images: ghcr.io/${{ github.repository }} | ||
| tags: | | ||
| type=ref,event=tag | ||
| type=raw,value=latest | ||
| type=raw,value=${{ steps.tag.outputs.value }},enable=${{ inputs.upstream_tag != '' }} | ||
|
|
||
| - name: Get timestamp | ||
| id: timestamp | ||
| run: echo "timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Create and push manifest | ||
| id: manifest | ||
| working-directory: /tmp/digests | ||
| continue-on-error: true | ||
| run: | | ||
| docker buildx imagetools create \ | ||
| $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | ||
| --annotation='index:org.opencontainers.image.description=${{ github.event.repository.description }}' \ | ||
| --annotation='index:org.opencontainers.image.created=${{ steps.timestamp.outputs.timestamp }}' \ | ||
| --annotation='index:org.opencontainers.image.url=${{ github.event.repository.url }}' \ | ||
| --annotation='index:org.opencontainers.image.source=${{ github.event.repository.url }}' \ | ||
| $(printf 'ghcr.io/${{ steps.image.outputs.lowercase }}@sha256:%s ' *) | ||
|
|
||
| - name: Create and push manifest (without annotations) | ||
| if: steps.manifest.outcome == 'failure' | ||
| working-directory: /tmp/digests | ||
| run: | | ||
| docker buildx imagetools create \ | ||
| $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | ||
| $(printf 'ghcr.io/${{ steps.image.outputs.lowercase }}@sha256:%s ' *) | ||
|
|
||
| - name: Inspect manifest | ||
| run: | | ||
| docker buildx imagetools inspect 'ghcr.io/${{ steps.image.outputs.lowercase }}:${{ steps.meta.outputs.version }}' | ||
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.
Uh oh!
There was an error while loading. Please reload this page.