Merge pull request #48 from B-AROL-O/ci/fix-duplicate-jobs #7
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: "Publish Docker Image" | |
env: | |
REGISTRY: "ghcr.io" | |
IMAGE_NAME: "${{ github.repository }}" | |
on: | |
push: # Only run after merge to main, when these files change | |
branches: [master, main] | |
paths: | |
- "code/oak-d-lite-module/Dockerfile" | |
- "code/oak-d-lite-module/requirements.txt" | |
- "code/oak-d-lite-module/vision_webserver.py" | |
- ".github/workflows/publish_image.yaml" # This file | |
# Publish semver tags as releases. | |
tags: ["v*.*.*"] | |
pull_request: | |
branches: [master, main] | |
workflow_dispatch: | |
jobs: | |
build: | |
name: Publish Docker Image | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
attestations: write | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install cosign | |
if: github.event_name != 'pull_request' | |
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 | |
with: | |
cosign-release: "v2.2.4" | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3.0.0 | |
# 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@v3.0.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5.0.0 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v6 | |
with: | |
context: code/oak-d-lite-module/ | |
push: ${{ github.event_name != 'pull_request' }} # Don't push on PR | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- 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}" | |
# EOF |