-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,73 +1,84 @@ | ||
name: Docker Image Publish | ||
name: Build and Push Docker Image | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
# Publish semver tags as releases. | ||
tags: [ 'v*.*.*' ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
env: | ||
# Use docker.io for Docker Hub if empty | ||
REGISTRY: ghcr.io | ||
# github.repository as <account>/<repo> | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
# This is used to complete the identity challenge | ||
# with sigstore/fulcio when running outside of PRs. | ||
id-token: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
# Install the cosign tool | ||
# https://github.com/sigstore/cosign-installer | ||
- name: Install cosign | ||
uses: sigstore/[email protected] | ||
if: github.event_name != 'pull_request' | ||
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 | ||
with: | ||
cosign-release: 'v2.2.2' | ||
cosign-release: 'v2.2.4' | ||
|
||
# Workaround: https://github.com/docker/build-push-action/issues/461 | ||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/[email protected] | ||
|
||
# Login against a Docker registry | ||
# https://github.com/docker/login-action | ||
- name: Log into registry ${{ env.REGISTRY }} | ||
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c | ||
if: github.event_name != 'pull_request' | ||
uses: docker/[email protected] | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Extract metadata (tags, labels) for Docker | ||
# https://github.com/docker/metadata-action | ||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | ||
- name: Extract Docker metadata for tags | ||
id: meta-tags | ||
if: startsWith(github.ref, 'refs/tags/') | ||
uses: docker/[email protected] | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=tag,pattern={{version}} | ||
type=raw,value=latest | ||
- name: Extract Docker metadata for branches | ||
id: meta-branches | ||
if: github.ref == 'refs/heads/main' | ||
uses: docker/[email protected] | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=raw,value=latest | ||
- name: Build and push Docker image for tags | ||
id: build-and-push-tags | ||
if: startsWith(github.ref, 'refs/tags/') | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta-tags.outputs.tags }} | ||
labels: ${{ steps.meta-tags.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
# Build and push Docker image with Buildx | ||
# https://github.com/docker/build-push-action | ||
- name: Build and push Docker image | ||
id: build-and-push | ||
uses: docker/build-push-action@v5 | ||
- name: Build and push Docker image for branches | ||
id: build-and-push-branches | ||
if: github.ref == 'refs/heads/main' | ||
uses: docker/[email protected] | ||
with: | ||
context: "{{defaultContext}}" | ||
context: . | ||
push: true | ||
#tags: ${{ steps.meta.outputs.tags }} | ||
tags: ghcr.io/${{ github.repository }}:latest | ||
labels: ${{ steps.meta.outputs.labels }} | ||
tags: ${{ steps.meta-branches.outputs.tags }} | ||
labels: ${{ steps.meta-branches.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |