Skip to content

Commit

Permalink
Update git-release.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
tmknight authored Jan 15, 2024
1 parent e277182 commit c392b18
Showing 1 changed file with 107 additions and 32 deletions.
139 changes: 107 additions & 32 deletions .github/workflows/git-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ on:
workflows: ["Git Tag"]
types:
- "completed"

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# name of image
IMAGE: docker-autoheal
# github.repository as <account>/<repo>
IMAGE_NAME: tmknight/docker-autoheal
# cosign version
COSIGN_VER: 'v2.1.1'
# Build args
CONTEXT: .
DISTRO: alpine
RELEASE: stable

jobs:
get-tag:
name: "Get Tag From Package Version"
Expand Down Expand Up @@ -72,39 +85,101 @@ jobs:
- name: "Upload Binaries"
uses: "taiki-e/upload-rust-binary-action@v1"
with:
bin: "docker-autoheal"
bin: ${{ env.IMAGE }}
target: ${{ matrix.target }}
archive: $bin-${{ matrix.target }}
ref: refs/tags/v${{ needs.get-tag.outputs.pkg-version }}
token: ${{ secrets.GITHUB_TOKEN }}

# push-to-registry:
# name: "Push Docker image to Docker Hub"
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
# needs:
# - "get-tag"
# - "upload-assets"
# runs-on: "ubuntu-latest"
# steps:
# - name: "Check out the repo"
# uses: actions/checkout@v3

# - name: "Log in to Docker Hub"
# uses: "docker/login-action@v2"
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}

# - name: "Extract metadata (tags, labels) for Docker"
# id: "meta"
# uses: "docker/metadata-action@v4"
# with:
# images: "bwks/shazam"

# - name: "Build and push Docker image"
# uses: "docker/build-push-action@v3"
# with:
# context: .
# push: true
# tags: bwks/shazam:latest,bwks/shazam:v${{ needs.get-tag.outputs.pkg-version }}
# labels: ${{ steps.meta.outputs.labels }}
push-to-registry:
name: "Push Docker image to Docker Hub"
if: ${{ github.event.workflow_run.conclusion == 'success' }}
needs:
- "get-tag"
- "upload-assets"
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@v3

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3 #v3.1.1
with:
cosign-release: ${{ env.COSIGN_VER }}

# Setup QEMU for multi-arch
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: amd64,arm64

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
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@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch,enable=${{ github.event_name != 'schedule' }}
type=ref,event=tag
# type=raw,enable=${{ github.event_name == 'schedule' }},value=latest
type=raw,enable=true,value=latest
type=raw,enable=true,value=v${{ needs.get-tag.outputs.pkg-version }}
type=raw,enable=true,value=${{ env.DISTRO }}-${{ env.RELEASE }}
type=raw,enable=true,value=${{ env.DISTRO }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: ${{ env.CONTEXT }}
platforms: linux/amd64,linux/arm64
file: docker/${{ env.DISTRO }}/${{ env.RELEASE }}/${{ env.IMAGE }}.dockerfile
build-args: ${{ env.BUILD_ARGS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

0 comments on commit c392b18

Please sign in to comment.