diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index bae54c4..d13af3e 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -18,9 +18,7 @@ permissions: read-all # Start the job on all push # ############################# on: - push: - branches-ignore: [master, main] - # Remove the line above to run when pushing to master + # Only on pull requests (for approval) pull_request: branches: [master, main] diff --git a/.github/workflows/publish_image.yaml b/.github/workflows/publish_image.yaml new file mode 100644 index 0000000..e3d08b9 --- /dev/null +++ b/.github/workflows/publish_image.yaml @@ -0,0 +1,83 @@ +--- +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 diff --git a/code/oak-d-lite-module/create_image.sh b/code/oak-d-lite-module/create_image.sh index 51adea7..69d307c 100755 --- a/code/oak-d-lite-module/create_image.sh +++ b/code/oak-d-lite-module/create_image.sh @@ -1,2 +1,2 @@ #!/bin/bash -docker build -t depthai-freisa:latest . \ No newline at end of file +docker build -t depthai-freisa:latest .