Skip to content

Commit

Permalink
Update docker.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasyu888 authored Jul 18, 2023
1 parent fc122be commit d76b3dd
Showing 1 changed file with 79 additions and 42 deletions.
121 changes: 79 additions & 42 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,94 @@
# This workflow builds and pushes the docker image using docker's v2 action
# which requires explicitly setting up buildx and logging in

name: Build and publish container to Docker Hub
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
# schedule:
# - cron: '40 17 * * *'
push:
tags: ['v[0-9]*', '[0-9]+.[0-9]+*'] # Match tags that resemble a version
branches: [ "main" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
workflow_dispatch:

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
env:
DOCKER_REPO: ${{ secrets.DOCKER_REPO }} # Example: sagebionetworks/vcf2maf
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
- name: Checkout repository
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx

# 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
with:
cosign-release: 'v2.1.1'

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
-
name: Login to DockerHub
uses: docker/login-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@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Compute short commit SHA ID
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
-
name: Build and push (tagged release)
uses: docker/build-push-action@v3
if: ${{ github.event_name == 'push' }}
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@v2
with:
platforms: linux/amd64
context: .
push: true
tags: |
${{ env.DOCKER_REPO }}:latest
${{ env.DOCKER_REPO }}:${{ github.ref_name }}
${{ env.DOCKER_REPO }}:commit-${{ steps.vars.outputs.sha_short }}
-
name: Build and push (manual release)
uses: docker/build-push-action@v3
if: ${{ github.event_name == 'workflow_dispatch' }}
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# 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:
platforms: linux/amd64
context: .
push: true
tags: |
${{ env.DOCKER_REPO }}:commit-${{ steps.vars.outputs.sha_short }}
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 d76b3dd

Please sign in to comment.