-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
75ae5b7
commit ad2a2ec
Showing
1 changed file
with
54 additions
and
17 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,46 +1,83 @@ | ||
--- | ||
name: "Publish Docker Image" | ||
|
||
permissions: | ||
packages: write | ||
contents: read | ||
attestations: write | ||
id-token: write | ||
|
||
env: | ||
OAK_MODULE_DIR: "code/oak-d-lite-module" | ||
REGISTRY: "ghcr.io" | ||
IMAGE_NAME: "${{ github.repository }}:latest" | ||
|
||
on: | ||
push: # Only run after merge to main, when these files change | ||
branches: [master, main] | ||
branches: [$default-branch] | ||
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: [$default-branch] | ||
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: Log into GHCR | ||
run: docker login "${{ env.REGISTRY }}" -u "${{ github.repository_owner }}" --password "${{ secrets.GITHUB_TOKEN }}" | ||
- name: Install cosign | ||
if: github.event_name != 'pull_request' | ||
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 | ||
with: | ||
cosign-release: "v2.2.4" | ||
|
||
- name: Build Docker Image | ||
run: | | ||
pushd "$OAK_MODULE_DIR" | ||
docker build -t "${{ env.IMAGE_NAME }}" . | ||
popd | ||
- 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@v5.0.0 | ||
with: | ||
context: . | ||
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: Push Docker Image | ||
run: docker push "${{ env.IMAGE_NAME }}" | ||
- 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 |