Docker #80
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
name: Docker | |
# 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: | |
workflow_dispatch: | |
push: | |
branches: [ main ] | |
# Publish semver tags as releases. | |
tags: [ 'v*.*.*' ] | |
pull_request: | |
branches: [ main ] | |
env: | |
REGISTRY: docker.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: tugboatqa/cli | |
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@v2 | |
# Install the cosign tool except on PR | |
# https://github.com/sigstore/cosign-installer | |
# - name: Install cosign | |
# if: github.event_name != 'pull_request' | |
# # v3.4.0 | |
# uses: sigstore/cosign-installer@e1523de7571e31dbe865fd2e80c5c7c23ae71eb4 | |
# with: | |
# cosign-release: 'v2.2.3' | |
# Workaround: https://github.com/docker/build-push-action/issues/461 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf | |
- name: Login to DockerHub | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Get Tugboat Version JSON | |
id: tugboat_version_json | |
run: echo "::set-output name=json::$(curl --silent https://api.tugboat.qa/v3/version)" | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
# See https://github.com/docker/metadata-action/issues/147 | |
tags: | | |
type=ref,event=branch,enable=${{ !endsWith(github.ref, github.event.repository.default_branch) }} | |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} | |
type=raw,value=${{ fromJson(steps.tugboat_version_json.outputs.json).server }},enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} | |
type=sha,enable=false | |
flavor: | | |
latest=false | |
# 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@ad44023a93711e3deb337508980b4b5e9bcdc5dc | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
# # Sign the resulting Docker image digest except on PRs. | |
# - name: Sign image with a key | |
# if: ${{ github.event_name != 'pull_request' }} | |
# run: | | |
# images="" | |
# for tag in ${TAGS}; do | |
# images+="${tag}@${DIGEST} " | |
# done | |
# cosign sign --yes --key env://COSIGN_PRIVATE_KEY ${images} | |
# env: | |
# TAGS: ${{ steps.meta.outputs.tags }} | |
# COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }} | |
# COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }} | |
# DIGEST: ${{ steps.build-and-push.outputs.digest }} |