Skip to content

Commit 4eebeac

Browse files
committed
add both build and deploy jobs in CI
1 parent 8aa9c23 commit 4eebeac

File tree

1 file changed

+66
-37
lines changed

1 file changed

+66
-37
lines changed

.github/workflows/ci.yaml

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
name: build-docs
1+
name: deploy-docs
2+
23
on:
34
workflow_dispatch:
45
push:
5-
branches:
6-
- main
6+
branches: [ main ]
77

88
env:
99
REGISTRY: ghcr.io
1010
IMAGE_NAME: ${{ github.repository }}
11+
MODULE: hololinked-python-docs
1112

1213
jobs:
1314
build:
15+
name: build & sign docker image
1416
runs-on: ubuntu-latest
1517
permissions:
1618
contents: read
1719
packages: write
18-
# This is used to complete the identity challenge
19-
# with sigstore/fulcio when running outside of PRs.
2020
id-token: write
2121

2222
steps:
@@ -29,6 +29,9 @@ jobs:
2929
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
3030
with:
3131
cosign-release: 'v2.2.4'
32+
33+
- name: Set up Skaffold
34+
uses: hiberbee/[email protected]
3235

3336
# Set up BuildKit Docker container builder to be able to build
3437
# multi-platform images and export cache
@@ -45,39 +48,65 @@ jobs:
4548
username: ${{ github.actor }}
4649
password: ${{ secrets.GITHUB_TOKEN }}
4750

48-
# Extract metadata (tags, labels) for Docker
49-
# https://github.com/docker/metadata-action
50-
- name: Extract Docker metadata
51-
id: meta
52-
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
53-
with:
54-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
51+
# Build & push with skaffold, and write the build outputs to a JSON file
52+
- name: Build with Skaffold (push)
53+
run: |
54+
skaffold build \
55+
--default-repo=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} \
56+
--push \
57+
--file-output build.out.json \
58+
-m ${{ env.MODULE }}
59+
5560

56-
# Build and push Docker image with Buildx (don't push on PR)
57-
# https://github.com/docker/build-push-action
58-
- name: Build and push Docker image
59-
id: build-and-push
60-
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
61+
# Cosign sign each built image by digest from the skaffold build output (keyless with OIDC)
62+
- name: Cosign sign images
63+
run: |
64+
set -euo pipefail
65+
# Extract full refs (they include @sha256:...); sign each
66+
jq -r '.builds[].tag' build.out.json | while read -r REF; do
67+
echo "Signing $REF"
68+
cosign sign --yes "$REF"
69+
done
70+
71+
- name: Upload build artifacts for deploy
72+
uses: actions/upload-artifact@v4
6173
with:
62-
file: Dockerfile
63-
context: .
64-
target: prod
65-
push: true
66-
tags: ${{ steps.meta.outputs.tags }}
67-
labels: ${{ steps.meta.outputs.labels }}
68-
cache-from: type=gha
69-
cache-to: type=gha,mode=max
74+
name: skaffold-build-output
75+
path: build.out.json
76+
if-no-files-found: error
77+
7078

71-
# Sign the resulting Docker image digest except on PRs.
72-
# This will only write to the public Rekor transparency log when the Docker
73-
# repository is public to avoid leaking data. If you would like to publish
74-
# transparency data even for private images, pass --force to cosign below.
75-
# https://github.com/sigstore/cosign
76-
- name: Sign the published Docker image
79+
run-skaffold:
80+
name: deploy
81+
runs-on: ubuntu-latest
82+
needs: build
83+
permissions:
84+
contents: read
85+
id-token: write
86+
steps:
87+
- name: Checkout repository
88+
uses: actions/checkout@v4
89+
90+
- name: Set up Skaffold
91+
uses: hiberbee/[email protected]
92+
93+
- name: Configure kubeconfig
94+
if: ${{ secrets.KUBECONFIG_B64 != '' }}
95+
run: |
96+
mkdir -p ~/.kube
97+
echo "${KUBECONFIG_B64}" | base64 -d > ~/.kube/config
7798
env:
78-
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
79-
TAGS: ${{ steps.meta.outputs.tags }}
80-
DIGEST: ${{ steps.build-and-push.outputs.digest }}
81-
# This step uses the identity token to provision an ephemeral certificate
82-
# against the sigstore community Fulcio instance.
83-
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}
99+
KUBECONFIG_B64: ${{ secrets.KUBECONFIG_B64 }}
100+
101+
- name: Download build artifacts
102+
uses: actions/download-artifact@v4
103+
with:
104+
name: skaffold-build-output
105+
path: .
106+
107+
# Deploy using the exact images produced in the build job
108+
- name: Deploy with Skaffold
109+
run: |
110+
skaffold deploy \
111+
--build-artifacts build.out.json \
112+
-m ${{ env.MODULE }}

0 commit comments

Comments
 (0)