diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 4c125938..3956de26 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -54,10 +54,107 @@ jobs: exit 1 fi + image: + name: Publish container image (pre-release) + runs-on: ubuntu-latest + needs: verify + permissions: + contents: read + packages: write + id-token: write + attestations: write + outputs: + digest: ${{ steps.build.outputs.digest }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0 + with: + platforms: linux/amd64,linux/arm64 + + - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 + + - uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # only the pre-release's own version; never latest or a floating major + - id: meta + uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 + with: + images: ghcr.io/${{ github.repository }} + tags: type=raw,value=${{ inputs.version }} + + - id: build + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Install cosign + uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 + + - name: Sign image + run: cosign sign --yes "ghcr.io/${{ github.repository }}@${{ steps.build.outputs.digest }}" + + - name: Attest image provenance + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 + with: + subject-name: ghcr.io/${{ github.repository }} + subject-digest: ${{ steps.build.outputs.digest }} + push-to-registry: true + + chart: + name: Publish Helm chart (pre-release) + runs-on: ubuntu-latest + needs: image + permissions: + contents: read + packages: write + id-token: write + attestations: write + env: + VERSION: ${{ inputs.version }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1 + + - name: Helm registry login + run: echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io -u "${{ github.actor }}" --password-stdin + + - name: Package and push chart + id: push + run: | + helm package charts/prow-github-app --version "$VERSION" --app-version "$VERSION" --destination . + out=$(helm push "prow-github-app-${VERSION}.tgz" "oci://ghcr.io/${{ github.repository }}/charts" 2>&1) + echo "$out" + echo "digest=$(echo "$out" | grep -oE 'sha256:[a-f0-9]{64}')" >> "$GITHUB_OUTPUT" + + - name: Install cosign + uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 + + - name: Sign chart + run: cosign sign --yes "ghcr.io/${{ github.repository }}/charts/prow-github-app@${{ steps.push.outputs.digest }}" + + - name: Attest chart provenance + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 + with: + subject-name: ghcr.io/${{ github.repository }}/charts/prow-github-app + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true + github-release: name: Create Pre-Release runs-on: ubuntu-latest - needs: verify + needs: [verify, image, chart] permissions: contents: write id-token: write # For cosign keyless signing diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 93dd6a93..a65efef6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,10 +42,114 @@ jobs: exit 1 fi + image: + name: Publish container image + runs-on: ubuntu-latest + needs: verify + permissions: + contents: read + packages: write + id-token: write # cosign keyless signing + attestations: write # GitHub artifact attestations + outputs: + digest: ${{ steps.build.outputs.digest }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0 + with: + platforms: linux/amd64,linux/arm64 + + - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 + + - uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # v3.2.0 → 3.2.0, 3.2, 3 and latest; a pre-release (anything with a '-') gets only its own version + - id: meta + uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}},enable=${{ !contains(github.ref_name, '-') }} + type=semver,pattern={{major}},enable=${{ !contains(github.ref_name, '-') }} + type=raw,value=latest,enable=${{ !contains(github.ref_name, '-') }} + + - id: build + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Install cosign + uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 + + # the multi-arch index digest, not a per-platform one + - name: Sign image + run: cosign sign --yes "ghcr.io/${{ github.repository }}@${{ steps.build.outputs.digest }}" + + - name: Attest image provenance + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 + with: + subject-name: ghcr.io/${{ github.repository }} + subject-digest: ${{ steps.build.outputs.digest }} + push-to-registry: true + + chart: + name: Publish Helm chart + runs-on: ubuntu-latest + needs: image + permissions: + contents: read + packages: write + id-token: write + attestations: write + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1 + + - name: Extract version from tag + run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV" + + - name: Helm registry login + run: echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io -u "${{ github.actor }}" --password-stdin + + # the chart's version and appVersion are the release; the image tag defaults to appVersion + - name: Package and push chart + id: push + run: | + helm package charts/prow-github-app --version "$VERSION" --app-version "$VERSION" --destination . + out=$(helm push "prow-github-app-${VERSION}.tgz" "oci://ghcr.io/${{ github.repository }}/charts" 2>&1) + echo "$out" + echo "digest=$(echo "$out" | grep -oE 'sha256:[a-f0-9]{64}')" >> "$GITHUB_OUTPUT" + + - name: Install cosign + uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 + + - name: Sign chart + run: cosign sign --yes "ghcr.io/${{ github.repository }}/charts/prow-github-app@${{ steps.push.outputs.digest }}" + + - name: Attest chart provenance + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 + with: + subject-name: ghcr.io/${{ github.repository }}/charts/prow-github-app + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true + github-release: name: Create GitHub Release runs-on: ubuntu-latest - needs: verify + needs: [verify, image, chart] permissions: contents: write id-token: write # For cosign keyless signing @@ -116,6 +220,21 @@ jobs: - uses: ${{ github.repository }}@${{ github.ref_name }} ``` + ## GitHub App (beta) + + Container image and Helm chart for [running Prow as a GitHub App](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/docs/github-app.md): + ```bash + docker pull ghcr.io/${{ github.repository }}@${{ needs.image.outputs.digest }} + helm install prow oci://ghcr.io/${{ github.repository }}/charts/prow-github-app --version ${{ env.VERSION }} + ``` + Both are signed with cosign (keyless) and carry SLSA provenance: + ```bash + cosign verify ghcr.io/${{ github.repository }}:${{ env.VERSION }} \ + --certificate-identity-regexp="https://github.com/${{ github.repository }}" \ + --certificate-oidc-issuer="https://token.actions.githubusercontent.com" + gh attestation verify oci://ghcr.io/${{ github.repository }}:${{ env.VERSION }} --repo ${{ github.repository }} + ``` + ## SBOM and provenance An SPDX 2.3 SBOM of the runtime dependencies, generated with diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59a77f49..4988ff1b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -104,3 +104,48 @@ jobs: path: coverage-e2e/ retention-days: 14 if-no-files-found: ignore + + # the Helm chart: lint on every run, and install the two topologies into a kind cluster against an + # image built from this very commit (loaded into kind, never pushed) + chart: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + - uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1 + - uses: helm/chart-testing-action@720270857a28afd41e2426521a7801db09e9b510 # v2.9.0 + - name: Lint + run: ct lint --config ct.yaml --all + - name: Unit tests + run: | + helm plugin install https://github.com/helm-unittest/helm-unittest --version 1.2.1 --verify=false + helm unittest charts/prow-github-app + - uses: helm/kind-action@1544676c07bb3570fcb70166beaa07c4528fd4aa # v1.15.1 + - name: Build the image from this commit and load it into kind + run: | + docker build -t prow-github-app:ci . + kind load docker-image prow-github-app:ci --name chart-testing + - name: Install (one replica) + run: | + helm install single charts/prow-github-app -f charts/prow-github-app/ci/single-values.yaml \ + --set image.repository=prow-github-app --set image.tag=ci --wait --timeout 120s + kubectl rollout status deploy/single-prow-github-app --timeout=60s + kubectl run curl --rm -i --restart=Never --image=curlimages/curl:8.11.1 -- -sf http://single-prow-github-app:8080/readyz + - name: Install (two replicas, external Redis) + run: | + kubectl apply -f charts/prow-github-app/ci/redis.yaml + kubectl rollout status deploy/ci-redis --timeout=60s + helm install ha charts/prow-github-app -f charts/prow-github-app/ci/ha-external-redis-values.yaml \ + --set image.repository=prow-github-app --set image.tag=ci --wait --timeout 120s + kubectl rollout status deploy/ha-prow-github-app --timeout=60s + test "$(kubectl get deploy ha-prow-github-app -o jsonpath='{.status.readyReplicas}')" = 2 + kubectl get pdb ha-prow-github-app + kubectl logs deploy/ha-prow-github-app --all-containers | grep -q '"redis: connected"' + - name: A signed ping reaches the HA service + run: | + body='{"zen":"x","hook_id":1}' + sig="sha256=$(printf '%s' "$body" | openssl dgst -sha256 -hmac ci-secret | sed 's/.* //')" + code=$(kubectl run curl --rm -i --restart=Never --image=curlimages/curl:8.11.1 -- -s -o /dev/null -w '%{http_code}' \ + -X POST http://ha-prow-github-app:8080/webhook -H 'x-github-delivery: ci-1' -H 'x-github-event: ping' -H "x-hub-signature-256: $sig" -d "$body" | head -c 3) + test "$code" = 200 diff --git a/Dockerfile b/Dockerfile index 8d2b1e19..bc82ecc1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,14 +2,19 @@ FROM node:24-slim AS build WORKDIR /app COPY package.json package-lock.json ./ RUN npm ci --ignore-scripts -COPY tsconfig.json tsconfig.core.json ./ +COPY tsconfig.json ./ COPY src ./src -RUN npm run build && npm run pack:server +# the server bundle only; the action and the Worker have their own builds and type checks in CI +RUN npx tsc --noEmit && npm run pack:server FROM node:24-slim +LABEL org.opencontainers.image.source="https://github.com/cncf/prow-github-actions" \ + org.opencontainers.image.description="Prow-style chat-ops for GitHub, as a GitHub App" \ + org.opencontainers.image.licenses="MIT" ENV NODE_ENV=production PORT=8080 USER node WORKDIR /app COPY --from=build /app/dist-server ./dist-server EXPOSE 8080 +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s CMD ["node", "-e", "fetch('http://127.0.0.1:'+(process.env.PORT||8080)+'/healthz').then(r=>process.exit(r.ok?0:1),()=>process.exit(1))"] CMD ["node", "dist-server/index.js"] diff --git a/__tests__/docsYamlExamples.test.ts b/__tests__/docsYamlExamples.test.ts index b970fb07..7f98a811 100644 --- a/__tests__/docsYamlExamples.test.ts +++ b/__tests__/docsYamlExamples.test.ts @@ -1,5 +1,6 @@ import { readdirSync, readFileSync, statSync } from 'node:fs' import * as path from 'node:path' +import Ajv from 'ajv/dist/2020' import * as yaml from 'js-yaml' import { describe, expect, it } from 'vitest' @@ -89,7 +90,7 @@ const sectionFields: Record = { const ownersKeys = ['approvers', 'reviewers', 'emeritus_approvers', 'emeritus_reviewers', 'filters', 'labels', 'options'] const workflowKeys = ['on', 'jobs', 'permissions', 'concurrency', 'steps', 'runs-on'] -type Kind = 'workflow' | 'owners' | 'prow' +type Kind = 'workflow' | 'owners' | 'prow' | 'helm' /** a job's `steps:` list quoted on its own, e.g. `- uses: cncf/prow-github-actions@v3` */ function isStepList(loaded: unknown): boolean { @@ -110,10 +111,24 @@ function isOwners(block: Block): boolean { return /OWNERS|`approvers`|`reviewers`/.test(block.intro) || (comment.startsWith('#') && comment.includes('OWNERS')) } +/** a Helm values example for charts/prow-github-app: its keys are the chart's top-level values */ +const chartDir = path.join(root, 'charts', 'prow-github-app') +const chartDefaults = yaml.load(readFileSync(path.join(chartDir, 'values.yaml'), 'utf8')) as Record +const chartSchema = JSON.parse(readFileSync(path.join(chartDir, 'values.schema.json'), 'utf8')) as object +const validateValues = new Ajv({ allErrors: true, strict: false }).compile(chartSchema) + +function isHelmValues(loaded: Record): boolean { + const keys = Object.keys(loaded) + return keys.length > 0 && keys.every(key => key in chartDefaults) +} + function classify(block: Block, loaded: unknown): Kind { if (isStepList(loaded) || !isMapping(loaded)) { return 'workflow' } + if (isHelmValues(loaded)) { + return 'helm' + } const keys = Object.keys(loaded) if (keys.some(key => workflowKeys.includes(key))) { return 'workflow' @@ -144,6 +159,11 @@ describe('every fenced yaml block in the guides', () => { const doc = isMapping(loaded) ? loaded : {} const kind = classify(block, loaded) + it.runIf(kind === 'helm')('is a values fragment the chart schema accepts on top of the defaults', () => { + const merged = { ...chartDefaults, ...doc, github: { ...(chartDefaults.github as object), appId: '1', privateKey: 'k', webhookSecret: 's', ...((doc.github as object | undefined) ?? {}) } } + expect(validateValues(merged), `${at}: ${JSON.stringify(validateValues.errors)}`).toBe(true) + }) + it.runIf(kind === 'owners')('parses as an OWNERS file naming somebody, with no key parseOwners would skip', () => { for (const key of Object.keys(doc)) { expect(ownersKeys, `${at}: unknown OWNERS key '${key}'`).toContain(key) diff --git a/__tests__/releaseWorkflows.test.ts b/__tests__/releaseWorkflows.test.ts index 998ba993..e386a1f5 100644 --- a/__tests__/releaseWorkflows.test.ts +++ b/__tests__/releaseWorkflows.test.ts @@ -119,3 +119,73 @@ describe('pre-release.yml version input', () => { expect(new RegExp(pattern as string).test(version)).toBe(accepted) }) }) + +describe.each([ + [releasePath, release], + [preReleasePath, preRelease], +])('%s publishes the App image and chart', (_file, workflow) => { + const image = workflow.jobs.image + const chart = workflow.jobs.chart + const publishPermissions = { 'contents': 'read', 'packages': 'write', 'id-token': 'write', 'attestations': 'write' } + + it('runs image after verify, chart after image, and the release after all three', () => { + expect(image.needs).toBe('verify') + expect(chart.needs).toBe('image') + expect(workflow.jobs['github-release'].needs).toEqual(['verify', 'image', 'chart']) + }) + + it('grants both publishing jobs exactly what pushing, signing and attesting need', () => { + expect(image.permissions).toEqual(publishPermissions) + expect(chart.permissions).toEqual(publishPermissions) + }) + + it('builds for amd64 and arm64 and pushes to ghcr.io under the repository', () => { + const build = steps(image).find(s => s.uses?.startsWith('docker/build-push-action@')) + expect(build?.with).toMatchObject({ platforms: 'linux/amd64,linux/arm64', push: true }) + const meta = steps(image).find(s => s.uses?.startsWith('docker/metadata-action@')) + expect(meta?.with?.images).toBe(`ghcr.io/${expression('github.repository')}`) + const login = steps(image).find(s => s.uses?.startsWith('docker/login-action@')) + expect(login?.with).toMatchObject({ registry: 'ghcr.io', password: expression('secrets.GITHUB_TOKEN') }) + }) + + it('signs and attests the image by the digest the build produced', () => { + const digest = expression('steps.build.outputs.digest') + expect(runOf(image, 'Sign image')).toContain(`@${digest}`) + const attest = steps(image).find(s => s.uses?.startsWith('actions/attest-build-provenance@')) + expect(attest?.with).toEqual({ 'subject-name': `ghcr.io/${expression('github.repository')}`, 'subject-digest': digest, 'push-to-registry': true }) + }) + + it('packages the chart at the release version, pushes it under /charts, then signs and attests that digest', () => { + const push = runOf(chart, 'Package and push chart') + expect(push).toContain('helm package charts/prow-github-app --version "$VERSION" --app-version "$VERSION"') + expect(push).toContain(`oci://ghcr.io/${expression('github.repository')}/charts`) + expect(push).toMatch(/sha256:\[a-f0-9\]\{64\}/) + const digest = expression('steps.push.outputs.digest') + expect(runOf(chart, 'Sign chart')).toContain(`charts/prow-github-app@${digest}`) + const attest = steps(chart).find(s => s.uses?.startsWith('actions/attest-build-provenance@')) + expect(attest?.with).toEqual({ 'subject-name': `ghcr.io/${expression('github.repository')}/charts/prow-github-app`, 'subject-digest': digest, 'push-to-registry': true }) + }) + + it('pins every action by sha', () => { + for (const uses of [...usesOf(image), ...usesOf(chart)]) { + expect(uses, uses).toMatch(/@[0-9a-f]{40}$/) + } + }) +}) + +describe('image tags', () => { + const tagsOf = (workflow: Workflow) => String(steps(workflow.jobs.image).find(s => s.uses?.startsWith('docker/metadata-action@'))?.with?.tags) + + it('a release gets its version, and the floating minor, major and latest only when it is not a pre-release', () => { + const tags = tagsOf(release) + expect(tags).toContain('type=semver,pattern={{version}}') + const gate = `enable=${expression('!contains(github.ref_name, \'-\')')}` + expect(tags).toContain(`type=semver,pattern={{major}}.{{minor}},${gate}`) + expect(tags).toContain(`type=semver,pattern={{major}},${gate}`) + expect(tags).toContain(`type=raw,value=latest,${gate}`) + }) + + it('a pre-release gets only its own version', () => { + expect(tagsOf(preRelease).trim()).toBe(`type=raw,value=${expression('inputs.version')}`) + }) +}) diff --git a/charts/prow-github-app/Chart.yaml b/charts/prow-github-app/Chart.yaml new file mode 100644 index 00000000..62df6594 --- /dev/null +++ b/charts/prow-github-app/Chart.yaml @@ -0,0 +1,14 @@ +apiVersion: v2 +name: prow-github-app +description: Prow-style chat-ops, OWNERS review and automatic merging for GitHub, running as a GitHub App +type: application +# version and appVersion are set by release.yml from the git tag; these are placeholders for local work +version: 0.0.0-dev +appVersion: 0.0.0-dev +home: https://github.com/cncf/prow-github-actions +sources: + - https://github.com/cncf/prow-github-actions +keywords: [prow, github, chatops, owners, lgtm] +maintainers: + - name: CNCF + url: https://github.com/cncf/prow-github-actions diff --git a/charts/prow-github-app/ci/ha-external-redis-values.yaml b/charts/prow-github-app/ci/ha-external-redis-values.yaml new file mode 100644 index 00000000..d32c9063 --- /dev/null +++ b/charts/prow-github-app/ci/ha-external-redis-values.yaml @@ -0,0 +1,6 @@ +# ct install: two replicas against a plain redis Deployment the job applies from ci/redis.yaml +replicaCount: 2 +github: + existingSecret: prow-ci-github +redis: + url: redis://ci-redis:6379 diff --git a/charts/prow-github-app/ci/redis.yaml b/charts/prow-github-app/ci/redis.yaml new file mode 100644 index 00000000..ae3b0dfb --- /dev/null +++ b/charts/prow-github-app/ci/redis.yaml @@ -0,0 +1,34 @@ +# a throwaway Redis for ct install's HA scenario; not part of the chart +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ci-redis +spec: + replicas: 1 + selector: + matchLabels: {app: ci-redis} + template: + metadata: + labels: {app: ci-redis} + spec: + containers: + - name: redis + image: redis:7-alpine + ports: [{containerPort: 6379}] +--- +apiVersion: v1 +kind: Service +metadata: + name: ci-redis +spec: + selector: {app: ci-redis} + ports: [{port: 6379}] +--- +apiVersion: v1 +kind: Secret +metadata: + name: prow-ci-github +stringData: + appId: '1' + privateKey: "-----BEGIN PRIVATE KEY-----\nnot-a-real-key\n-----END PRIVATE KEY-----" + webhookSecret: ci-secret diff --git a/charts/prow-github-app/ci/single-values.yaml b/charts/prow-github-app/ci/single-values.yaml new file mode 100644 index 00000000..5c090c42 --- /dev/null +++ b/charts/prow-github-app/ci/single-values.yaml @@ -0,0 +1,7 @@ +# ct install: one replica, no Redis; the image is the pre-pushed test tag ct's job sets +github: + appId: '1' + privateKey: "-----BEGIN PRIVATE KEY-----\nnot-a-real-key\n-----END PRIVATE KEY-----" + webhookSecret: ci-secret +cronjob: + enabled: false diff --git a/charts/prow-github-app/templates/NOTES.txt b/charts/prow-github-app/templates/NOTES.txt new file mode 100644 index 00000000..3bbb36ca --- /dev/null +++ b/charts/prow-github-app/templates/NOTES.txt @@ -0,0 +1,17 @@ +Prow is running as a GitHub App. + +Point the App's webhook at this release: +{{- if .Values.ingress.enabled }} +{{- range .Values.ingress.hosts }} + https://{{ .host }}/webhook +{{- end }} +{{- else }} + kubectl -n {{ .Release.Namespace }} port-forward svc/{{ include "prow-github-app.fullname" . }} 8080:{{ .Values.service.port }} + then relay deliveries to http://localhost:8080/webhook (smee.io or `gh webhook forward`), + or enable ingress.* and use https:///webhook. +{{- end }} + +Replicas: {{ .Values.replicaCount }}{{ if include "prow-github-app.redisConfigured" . }} (shared state through Redis){{ end }}. +Scheduled jobs ({{ .Values.prow.jobs }}): {{ if .Values.cronjob.enabled }}CronJob {{ include "prow-github-app.fullname" . }}-jobs, {{ .Values.cronjob.schedule | quote }}{{ else }}disabled{{ end }}. + +Docs: https://github.com/cncf/prow-github-actions/blob/main/docs/github-app.md diff --git a/charts/prow-github-app/templates/_helpers.tpl b/charts/prow-github-app/templates/_helpers.tpl new file mode 100644 index 00000000..0fabc757 --- /dev/null +++ b/charts/prow-github-app/templates/_helpers.tpl @@ -0,0 +1,85 @@ +{{- define "prow-github-app.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{- define "prow-github-app.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{- define "prow-github-app.labels" -}} +helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{ include "prow-github-app.selectorLabels" . }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{- define "prow-github-app.selectorLabels" -}} +app.kubernetes.io/name: {{ include "prow-github-app.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + +{{- define "prow-github-app.serviceAccountName" -}} +{{- if .Values.serviceAccount.create -}} +{{- default (include "prow-github-app.fullname" .) .Values.serviceAccount.name -}} +{{- else -}} +{{- default "default" .Values.serviceAccount.name -}} +{{- end -}} +{{- end -}} + +{{- define "prow-github-app.secretName" -}} +{{- default (include "prow-github-app.fullname" .) .Values.github.existingSecret -}} +{{- end -}} + +{{- define "prow-github-app.image" -}} +{{- printf "%s:%s" .Values.image.repository (default .Chart.AppVersion .Values.image.tag) -}} +{{- end -}} + +{{/* true when several replicas share state through Redis; the schema already requires a source when replicaCount > 1 */}} +{{- define "prow-github-app.redisConfigured" -}} +{{- if or .Values.redis.url .Values.redis.existingSecret -}}true{{- end -}} +{{- end -}} + +{{/* the env block both the Deployment and the CronJob use */}} +{{- define "prow-github-app.env" -}} +- name: GITHUB_APP_ID + valueFrom: + secretKeyRef: + name: {{ include "prow-github-app.secretName" . }} + key: appId +- name: GITHUB_APP_PRIVATE_KEY + valueFrom: + secretKeyRef: + name: {{ include "prow-github-app.secretName" . }} + key: privateKey +- name: GITHUB_WEBHOOK_SECRET + valueFrom: + secretKeyRef: + name: {{ include "prow-github-app.secretName" . }} + key: webhookSecret +{{- if .Values.redis.existingSecret }} +- name: REDIS_URL + valueFrom: + secretKeyRef: + name: {{ .Values.redis.existingSecret }} + key: {{ .Values.redis.existingSecretKey }} +{{- else if .Values.redis.url }} +- name: REDIS_URL + value: {{ .Values.redis.url | quote }} +{{- end }} +- name: PROW_REPLICAS + value: {{ .Values.replicaCount | quote }} +- name: PROW_SHUTDOWN_GRACE_MS + value: {{ sub (mul .Values.terminationGracePeriodSeconds 1000) 5000 | quote }} +{{- range .Values.extraEnv }} +- {{ toYaml . | nindent 2 | trim }} +{{- end }} +{{- end -}} diff --git a/charts/prow-github-app/templates/configmap.yaml b/charts/prow-github-app/templates/configmap.yaml new file mode 100644 index 00000000..c6b2cfba --- /dev/null +++ b/charts/prow-github-app/templates/configmap.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "prow-github-app.fullname" . }} + labels: {{- include "prow-github-app.labels" . | nindent 4 }} +data: + PROW_COMMANDS: {{ .Values.prow.commands | quote }} + PROW_JOBS: {{ .Values.prow.jobs | quote }} + PROW_MERGE_METHOD: {{ .Values.prow.mergeMethod | quote }} + PROW_CONFIG: {{ .Values.prow.config | quote }} + PROW_DRY_RUN: {{ .Values.prow.dryRun | toString | quote }} + {{- if .Values.github.apiUrl }} + GITHUB_API_URL: {{ .Values.github.apiUrl | quote }} + {{- end }} diff --git a/charts/prow-github-app/templates/cronjob.yaml b/charts/prow-github-app/templates/cronjob.yaml new file mode 100644 index 00000000..4337b678 --- /dev/null +++ b/charts/prow-github-app/templates/cronjob.yaml @@ -0,0 +1,48 @@ +{{- if .Values.cronjob.enabled }} +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ include "prow-github-app.fullname" . }}-jobs + labels: {{- include "prow-github-app.labels" . | nindent 4 }} +spec: + schedule: {{ .Values.cronjob.schedule | quote }} + concurrencyPolicy: Forbid + startingDeadlineSeconds: 600 + successfulJobsHistoryLimit: {{ .Values.cronjob.successfulJobsHistoryLimit }} + failedJobsHistoryLimit: {{ .Values.cronjob.failedJobsHistoryLimit }} + jobTemplate: + spec: + backoffLimit: 0 + template: + metadata: + labels: {{- include "prow-github-app.selectorLabels" . | nindent 12 }} + app.kubernetes.io/component: jobs + spec: + restartPolicy: Never + serviceAccountName: {{ include "prow-github-app.serviceAccountName" . }} + automountServiceAccountToken: false + {{- with .Values.imagePullSecrets }} + imagePullSecrets: {{- toYaml . | nindent 12 }} + {{- end }} + securityContext: + runAsNonRoot: true + runAsUser: 1000 + runAsGroup: 1000 + seccompProfile: + type: RuntimeDefault + containers: + - name: prow-jobs + image: {{ include "prow-github-app.image" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: ["dist-server/index.js", "cron"] + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: [ALL] + envFrom: + - configMapRef: + name: {{ include "prow-github-app.fullname" . }} + env: {{- include "prow-github-app.env" . | nindent 16 }} + resources: {{- toYaml .Values.resources | nindent 16 }} +{{- end }} diff --git a/charts/prow-github-app/templates/deployment.yaml b/charts/prow-github-app/templates/deployment.yaml new file mode 100644 index 00000000..55a8b75b --- /dev/null +++ b/charts/prow-github-app/templates/deployment.yaml @@ -0,0 +1,79 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "prow-github-app.fullname" . }} + labels: {{- include "prow-github-app.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + {{- if eq (int .Values.replicaCount) 1 }} + # one replica without shared stores: never run the old and the new pod together + strategy: + type: Recreate + {{- end }} + selector: + matchLabels: {{- include "prow-github-app.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "prow-github-app.selectorLabels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + annotations: + # roll the pods when what the ConfigMap or the inline Secret carries changes + checksum/config: {{ list .Values.prow .Values.github.apiUrl | toJson | sha256sum }} + {{- if not .Values.github.existingSecret }} + checksum/secret: {{ list .Values.github.appId .Values.github.privateKey .Values.github.webhookSecret | toJson | sha256sum }} + {{- end }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + serviceAccountName: {{ include "prow-github-app.serviceAccountName" . }} + automountServiceAccountToken: false + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} + {{- with .Values.imagePullSecrets }} + imagePullSecrets: {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + runAsNonRoot: true + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + seccompProfile: + type: RuntimeDefault + containers: + - name: prow + image: {{ include "prow-github-app.image" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: [ALL] + ports: + - name: http + containerPort: 8080 + envFrom: + - configMapRef: + name: {{ include "prow-github-app.fullname" . }} + env: {{- include "prow-github-app.env" . | nindent 12 }} + livenessProbe: + httpGet: { path: /healthz, port: http } + periodSeconds: 10 + readinessProbe: + httpGet: { path: /readyz, port: http } + periodSeconds: 5 + resources: {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.topologySpreadConstraints }} + topologySpreadConstraints: {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/prow-github-app/templates/ingress.yaml b/charts/prow-github-app/templates/ingress.yaml new file mode 100644 index 00000000..c9ac1b2e --- /dev/null +++ b/charts/prow-github-app/templates/ingress.yaml @@ -0,0 +1,32 @@ +{{- if .Values.ingress.enabled }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "prow-github-app.fullname" . }} + labels: {{- include "prow-github-app.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.ingress.className }} + ingressClassName: {{ . }} + {{- end }} + {{- with .Values.ingress.tls }} + tls: {{- toYaml . | nindent 4 }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ .pathType | default "Prefix" }} + backend: + service: + name: {{ include "prow-github-app.fullname" $ }} + port: + name: http + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/prow-github-app/templates/pdb.yaml b/charts/prow-github-app/templates/pdb.yaml new file mode 100644 index 00000000..19cfba7d --- /dev/null +++ b/charts/prow-github-app/templates/pdb.yaml @@ -0,0 +1,11 @@ +{{- if gt (int .Values.replicaCount) 1 }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "prow-github-app.fullname" . }} + labels: {{- include "prow-github-app.labels" . | nindent 4 }} +spec: + minAvailable: {{ .Values.podDisruptionBudget.minAvailable }} + selector: + matchLabels: {{- include "prow-github-app.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/charts/prow-github-app/templates/secret.yaml b/charts/prow-github-app/templates/secret.yaml new file mode 100644 index 00000000..91b6037e --- /dev/null +++ b/charts/prow-github-app/templates/secret.yaml @@ -0,0 +1,12 @@ +{{- if not .Values.github.existingSecret }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "prow-github-app.fullname" . }} + labels: {{- include "prow-github-app.labels" . | nindent 4 }} +type: Opaque +stringData: + appId: {{ required "github.appId is required (or set github.existingSecret)" .Values.github.appId | quote }} + privateKey: {{ required "github.privateKey is required (or set github.existingSecret)" .Values.github.privateKey | quote }} + webhookSecret: {{ required "github.webhookSecret is required (or set github.existingSecret)" .Values.github.webhookSecret | quote }} +{{- end }} diff --git a/charts/prow-github-app/templates/service.yaml b/charts/prow-github-app/templates/service.yaml new file mode 100644 index 00000000..0d8e712d --- /dev/null +++ b/charts/prow-github-app/templates/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "prow-github-app.fullname" . }} + labels: {{- include "prow-github-app.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + selector: {{- include "prow-github-app.selectorLabels" . | nindent 4 }} + ports: + - name: http + port: {{ .Values.service.port }} + targetPort: http diff --git a/charts/prow-github-app/templates/serviceaccount.yaml b/charts/prow-github-app/templates/serviceaccount.yaml new file mode 100644 index 00000000..223af2d3 --- /dev/null +++ b/charts/prow-github-app/templates/serviceaccount.yaml @@ -0,0 +1,11 @@ +{{- if .Values.serviceAccount.create }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "prow-github-app.serviceAccountName" . }} + labels: {{- include "prow-github-app.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: false +{{- end }} diff --git a/charts/prow-github-app/tests/schema_test.yaml b/charts/prow-github-app/tests/schema_test.yaml new file mode 100644 index 00000000..58f1d2f2 --- /dev/null +++ b/charts/prow-github-app/tests/schema_test.yaml @@ -0,0 +1,28 @@ +suite: values schema +templates: [deployment.yaml] +values: [./values/creds.yaml] +tests: + - it: refuses several replicas without a redis source + set: + replicaCount: 2 + asserts: + - failedTemplate: {} + - it: refuses a non-redis url + set: + replicaCount: 2 + redis.url: http://nope + asserts: + - failedTemplate: {} + - it: refuses missing credentials + set: + github.appId: '' + github.privateKey: '' + github.webhookSecret: '' + asserts: + - failedTemplate: {} + - it: accepts several replicas with a redis url + set: + replicaCount: 2 + redis.url: rediss://r + asserts: + - hasDocuments: {count: 1} diff --git a/charts/prow-github-app/tests/topology_test.yaml b/charts/prow-github-app/tests/topology_test.yaml new file mode 100644 index 00000000..a25da91e --- /dev/null +++ b/charts/prow-github-app/tests/topology_test.yaml @@ -0,0 +1,111 @@ +suite: topology +templates: + - deployment.yaml + - pdb.yaml + - secret.yaml + - cronjob.yaml +values: + - ./values/creds.yaml +tests: + - it: one replica recreates and has no pdb + template: deployment.yaml + asserts: + - equal: {path: spec.replicas, value: 1} + - equal: {path: spec.strategy.type, value: Recreate} + - notContains: + path: spec.template.spec.containers[0].env + content: {name: REDIS_URL} + any: true + - it: one replica renders no pdb + template: pdb.yaml + asserts: + - hasDocuments: {count: 0} + - it: several replicas roll, carry REDIS_URL and a pdb + set: + replicaCount: 3 + redis.url: redis://r:6379 + template: deployment.yaml + asserts: + - equal: {path: spec.replicas, value: 3} + - isNull: {path: spec.strategy} + - contains: + path: spec.template.spec.containers[0].env + content: {name: REDIS_URL, value: redis://r:6379} + - contains: + path: spec.template.spec.containers[0].env + content: {name: PROW_REPLICAS, value: '3'} + - it: several replicas render a pdb with minAvailable 1 + set: + replicaCount: 3 + redis.url: redis://r:6379 + template: pdb.yaml + asserts: + - hasDocuments: {count: 1} + - equal: {path: spec.minAvailable, value: 1} + - it: redis.existingSecret wins over redis.url + set: + replicaCount: 2 + redis.url: redis://ignored + redis.existingSecret: my-redis + redis.existingSecretKey: uri + template: deployment.yaml + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: REDIS_URL + valueFrom: {secretKeyRef: {name: my-redis, key: uri}} + - it: inline credentials render a Secret the env reads + template: secret.yaml + asserts: + - hasDocuments: {count: 1} + - equal: {path: stringData.appId, value: '42'} + - it: github.existingSecret suppresses the Secret and is what the env reads + set: + github.existingSecret: mine + github.appId: '' + github.privateKey: '' + github.webhookSecret: '' + template: secret.yaml + asserts: + - hasDocuments: {count: 0} + - it: the env reads github.existingSecret + set: + github.existingSecret: mine + github.appId: '' + github.privateKey: '' + github.webhookSecret: '' + template: deployment.yaml + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: GITHUB_APP_ID + valueFrom: {secretKeyRef: {name: mine, key: appId}} + - it: the cronjob runs the cron entry point on the schedule, never concurrently + template: cronjob.yaml + asserts: + - equal: + path: spec.schedule + value: '0 * * * *' + - equal: + path: spec.concurrencyPolicy + value: Forbid + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].args + value: [dist-server/index.js, cron] + - it: cronjob.enabled false renders nothing + set: + cronjob.enabled: false + template: cronjob.yaml + asserts: + - hasDocuments: {count: 0} + - it: the shutdown grace is five seconds under the pod's + set: + terminationGracePeriodSeconds: 45 + template: deployment.yaml + asserts: + - equal: {path: spec.template.spec.terminationGracePeriodSeconds, value: 45} + - contains: + path: spec.template.spec.containers[0].env + content: {name: PROW_SHUTDOWN_GRACE_MS, value: '40000'} diff --git a/charts/prow-github-app/tests/values/creds.yaml b/charts/prow-github-app/tests/values/creds.yaml new file mode 100644 index 00000000..9adca465 --- /dev/null +++ b/charts/prow-github-app/tests/values/creds.yaml @@ -0,0 +1,4 @@ +github: + appId: '42' + privateKey: "-----BEGIN PRIVATE KEY-----\nnot-a-real-key\n-----END PRIVATE KEY-----" + webhookSecret: s diff --git a/charts/prow-github-app/values.schema.json b/charts/prow-github-app/values.schema.json new file mode 100644 index 00000000..f75f85eb --- /dev/null +++ b/charts/prow-github-app/values.schema.json @@ -0,0 +1,70 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "replicaCount": { "type": "integer", "minimum": 1 }, + "image": { + "type": "object", + "properties": { + "repository": { "type": "string", "minLength": 1 }, + "tag": { "type": "string" }, + "pullPolicy": { "enum": ["Always", "IfNotPresent", "Never"] } + }, + "required": ["repository"] + }, + "github": { + "type": "object", + "properties": { + "appId": { "type": "string" }, + "privateKey": { "type": "string" }, + "webhookSecret": { "type": "string" }, + "existingSecret": { "type": "string" }, + "apiUrl": { "type": "string", "pattern": "^$|^https?://" } + }, + "anyOf": [ + { "properties": { "existingSecret": { "minLength": 1 } }, "required": ["existingSecret"] }, + { + "properties": { + "appId": { "minLength": 1 }, + "privateKey": { "minLength": 1 }, + "webhookSecret": { "minLength": 1 } + }, + "required": ["appId", "privateKey", "webhookSecret"] + } + ] + }, + "prow": { + "type": "object", + "properties": { + "commands": { "type": "string" }, + "jobs": { "type": "string" }, + "mergeMethod": { "enum": ["", "merge", "squash", "rebase"] }, + "config": { "type": "string" }, + "dryRun": { "type": "boolean" } + } + }, + "redis": { + "type": "object", + "properties": { + "url": { "type": "string", "pattern": "^$|^rediss?://" }, + "existingSecret": { "type": "string" }, + "existingSecretKey": { "type": "string", "minLength": 1 } + } + }, + "cronjob": { + "type": "object", + "properties": { + "enabled": { "type": "boolean" }, + "schedule": { "type": "string", "minLength": 9 } + } + }, + "terminationGracePeriodSeconds": { "type": "integer", "minimum": 10 } + }, + "if": { "properties": { "replicaCount": { "minimum": 2 } } }, + "then": { + "anyOf": [ + { "properties": { "redis": { "properties": { "url": { "minLength": 1 } }, "required": ["url"] } } }, + { "properties": { "redis": { "properties": { "existingSecret": { "minLength": 1 } }, "required": ["existingSecret"] } } } + ] + } +} diff --git a/charts/prow-github-app/values.yaml b/charts/prow-github-app/values.yaml new file mode 100644 index 00000000..afa959ca --- /dev/null +++ b/charts/prow-github-app/values.yaml @@ -0,0 +1,89 @@ +# Default values for prow-github-app. +# Register the GitHub App first: https://github.com/cncf/prow-github-actions/blob/main/docs/github-app.md#register-the-app + +image: + repository: ghcr.io/cncf/prow-github-actions + # defaults to the chart's appVersion + tag: '' + pullPolicy: IfNotPresent +imagePullSecrets: [] + +# More than one replica needs redis.url: the replicas share delivery dedupe and +# the per-pull-request lock through it. +replicaCount: 1 + +github: + # the App's id, private key (PEM) and webhook secret, either inline ... + appId: '' + privateKey: '' + webhookSecret: '' + # ... or from an existing Secret with keys appId, privateKey, webhookSecret + existingSecret: '' + # GitHub Enterprise Server REST root, e.g. https://ghes.example/api/v3 + apiUrl: '' + +# the same inputs the action takes; see docs/configuration.md +prow: + # space-separated /commands to enable; empty means every built-in command except /meow + commands: '' + # scheduled jobs the CronJob runs + jobs: lgtm + mergeMethod: '' + # explicit prow.yaml source, owner/repo:path[@ref] or an https:// url + config: '' + dryRun: false + +# Any Redis 6+ or Valkey; the chart does not ship one. For a quick development +# instance: kubectl create deployment redis --image=redis:7-alpine --port=6379 && kubectl expose deployment redis +redis: + # redis://host:6379 or rediss://...; required when replicaCount > 1 + url: '' + # or read the url from an existing Secret + existingSecret: '' + existingSecretKey: url + +cronjob: + enabled: true + schedule: '0 * * * *' + successfulJobsHistoryLimit: 3 + failedJobsHistoryLimit: 3 + +service: + type: ClusterIP + port: 8080 + +ingress: + enabled: false + className: '' + annotations: {} + hosts: [] + # - host: prow.example.com + # paths: [{ path: /webhook, pathType: Exact }] + tls: [] + +serviceAccount: + create: true + name: '' + annotations: {} + +podDisruptionBudget: + # created when replicaCount > 1 + minAvailable: 1 + +resources: + requests: + cpu: 100m + memory: 128Mi + limits: + memory: 256Mi + +# seconds SIGTERM waits for in-flight events before the pod is killed; the server itself waits PROW_SHUTDOWN_GRACE_MS (25 s) +terminationGracePeriodSeconds: 30 + +podAnnotations: {} +podLabels: {} +nodeSelector: {} +tolerations: [] +affinity: {} +topologySpreadConstraints: [] +extraEnv: [] diff --git a/ct.yaml b/ct.yaml new file mode 100644 index 00000000..63d34ecd --- /dev/null +++ b/ct.yaml @@ -0,0 +1,5 @@ +chart-dirs: [charts] +validate-maintainers: false +check-version-increment: false +target-branch: main +helm-extra-args: --timeout 120s diff --git a/docs/github-app.md b/docs/github-app.md index 7baa6745..8b310c8f 100644 --- a/docs/github-app.md +++ b/docs/github-app.md @@ -62,24 +62,80 @@ the organization (all repositories, or the ones Prow should manage). ## Run -A container image is built from the repository's `Dockerfile`: +### Kubernetes + +The chart and the image are published with every release, signed with cosign and +carrying SLSA provenance: + +```sh +kubectl create secret generic prow-github \ + --from-literal=appId=123456 \ + --from-literal=webhookSecret="$(openssl rand -hex 32)" \ + --from-file=privateKey=prow.private-key.pem + +helm install prow oci://ghcr.io/cncf/prow-github-actions/charts/prow-github-app \ + --version 3.4.0 \ + --set github.existingSecret=prow-github \ + --set ingress.enabled=true --set ingress.className=nginx \ + --set 'ingress.hosts[0].host=prow.example.com' \ + --set 'ingress.hosts[0].paths[0].path=/webhook' --set 'ingress.hosts[0].paths[0].pathType=Exact' +``` + +The webhook URL for the App is `https://prow.example.com/webhook`. The chart +creates a Deployment (liveness `/healthz`, readiness `/readyz`), a Service, the +Ingress above, a ServiceAccount, and a CronJob that runs the scheduled jobs +hourly (`cronjob.schedule`, `prow.jobs`). The `prow.*` values are the action's +inputs under other names; `github.apiUrl` points at a GitHub Enterprise Server. +`helm show values oci://ghcr.io/cncf/prow-github-actions/charts/prow-github-app --version 3.4.0` +lists everything. + +Two topologies: + +```yaml +# one replica: nothing shared, Recreate strategy; the default +replicaCount: 1 +``` + +```yaml +# several replicas: a Redis every replica shares; the chart refuses replicaCount > 1 without one +replicaCount: 3 +redis: + url: rediss://my-redis:6380 # or existingSecret / existingSecretKey +``` + +The chart ships no Redis: any Redis 6+ or Valkey will do, and for development +`kubectl create deployment redis --image=redis:7-alpine --port=6379 && kubectl expose deployment redis` +gives one at `redis://redis:6379`. Upgrade with `helm upgrade prow … --version X.Y.Z`; +the pods roll when configuration or inline credentials change. + +Verify what you install: + +```sh +cosign verify ghcr.io/cncf/prow-github-actions:3.4.0 \ + --certificate-identity-regexp="https://github.com/cncf/prow-github-actions" \ + --certificate-oidc-issuer="https://token.actions.githubusercontent.com" +gh attestation verify oci://ghcr.io/cncf/prow-github-actions:3.4.0 --repo cncf/prow-github-actions +gh attestation verify oci://ghcr.io/cncf/prow-github-actions/charts/prow-github-app:3.4.0 --repo cncf/prow-github-actions +``` + +### A container anywhere else ```sh -docker build -t prow-app . docker run -p 8080:8080 \ -e GITHUB_APP_ID=... -e GITHUB_WEBHOOK_SECRET=... \ -e GITHUB_APP_PRIVATE_KEY="$(cat prow.private-key.pem)" \ - prow-app + ghcr.io/cncf/prow-github-actions:3.4.0 ``` -`GET /healthz` answers `ok` (liveness); `GET /readyz` answers `ok` once the -stores below are reachable (readiness). `POST /webhook` verifies -`X-Hub-Signature-256`, answers `202` at once and handles the event afterwards. -A pull request's events run one at a time, in order, as the action's -`concurrency:` group arranges; a redelivered `X-GitHub-Delivery` id is handled -once. On `SIGTERM` the server stops accepting, lets in-flight events finish -(`PROW_SHUTDOWN_GRACE_MS`, default 25 000) and exits. For local testing, relay -deliveries with [smee.io](https://smee.io) or `gh webhook forward`. +(or `docker build -t prow-app .` from the repository.) `GET /healthz` answers +`ok` (liveness); `GET /readyz` answers `ok` once the stores below are reachable +(readiness). `POST /webhook` verifies `X-Hub-Signature-256`, answers `202` at +once and handles the event afterwards. A pull request's events run one at a +time, in order, as the action's `concurrency:` group arranges; a redelivered +`X-GitHub-Delivery` id is handled once. On `SIGTERM` the server stops accepting, +lets in-flight events finish (`PROW_SHUTDOWN_GRACE_MS`, default 25 000) and +exits. For local testing, relay deliveries with [smee.io](https://smee.io) or +`gh webhook forward`. ### One replica or several @@ -94,10 +150,6 @@ on one pull request; the server warns at startup when `PROW_REPLICAS` is above keys per event (`prow:delivery:`, a day; `prow:lock:`, a minute at most) and nothing else. -A minimal Kubernetes Deployment is one container with the variables above from a -Secret and a Service in front of port 8080; put your usual Ingress/TLS in front. -A Helm chart is on its way. - ## Scheduled jobs The action's `schedule:` trigger has no webhook equivalent, so the App runs the @@ -108,10 +160,9 @@ jobs itself: node dist-server/index.js cron ``` -On Kubernetes that is a `CronJob` running the same image with `args: ["dist-server/index.js", "cron"]` -and the same environment as the Deployment; hourly matches the templates. For a -single container with no scheduler, `PROW_CRON_INTERVAL=60` runs the jobs inside -the server every hour instead. +The chart's CronJob does exactly this (`cronjob.schedule`, hourly by default). +For a single container with no scheduler, `PROW_CRON_INTERVAL=60` runs the jobs +inside the server every hour instead. Each repository runs under its own installation token and state, four at a time; a repository that fails is logged and reported, and never stops the others. diff --git a/docs/releasing.md b/docs/releasing.md index 70e96e2f..49a91002 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -23,7 +23,12 @@ Both workflows: 3. **Sign the SBOM** with [cosign](https://github.com/sigstore/cosign) (keyless, via GitHub OIDC) and create a SLSA build provenance attestation covering both `dist/index.js` and the SBOM. -4. **Create a GitHub Release** with auto-generated release notes and the +4. **Publish the GitHub App** as a multi-arch container image + (`ghcr.io/cncf/prow-github-actions:X.Y.Z`, plus `X.Y`, `X` and `latest` for a + stable release) and a Helm chart + (`oci://ghcr.io/cncf/prow-github-actions/charts/prow-github-app:X.Y.Z`), each + signed with cosign and attested by digest. +5. **Create a GitHub Release** with auto-generated release notes and the following attached artifacts: - `prow-github-actions-.spdx.json` — the SBOM - `prow-github-actions-.spdx.json.bundle` — cosign signature bundle @@ -47,6 +52,10 @@ action: it checks out `cncf/prow-github-actions` at `job.workflow_sha`, the commit of the workflow file itself, so a tag or sha names both the workflow and the action bundle that runs. Nothing in it needs updating at release time. +The two ghcr.io packages were created by the first release that published them +and made public by hand (package settings → *Change visibility*); `GITHUB_TOKEN` +can publish to them but cannot change their visibility. + ## Cutting a stable release Everything but the tag lands through one pull request; the tag is pushed once diff --git a/eslint.config.mjs b/eslint.config.mjs index cb6a59c8..116231be 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -9,6 +9,8 @@ export default antfu({ 'node_modules/', '**/node_modules/**/', '.sisyphus/', + // Go templates, not yaml + 'charts/*/templates/**', ], }, { files: ['__tests__/**/*.test.ts'], diff --git a/package-lock.json b/package-lock.json index c4e7199b..20bad7bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "@types/node": "^24", "@vercel/ncc": "^0.45.0", "@vitest/coverage-v8": "^5.0.5", + "ajv": "^8.20.0", "eslint": "^10.13.0", "miniflare": "^4.20260730.0", "msw": "^3.0.3", @@ -4212,23 +4213,6 @@ "node": ">=22.0.0" } }, - "node_modules/@stryker-mutator/core/node_modules/ajv": { - "version": "8.20.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", - "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", - "dev": true, - "license": "MIT", - "dependencies": { - "fast-deep-equal": "^3.1.3", - "fast-uri": "^3.0.1", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, "node_modules/@stryker-mutator/core/node_modules/commander": { "version": "14.0.3", "resolved": "https://registry.npmjs.org/commander/-/commander-14.0.3.tgz", @@ -4239,13 +4223,6 @@ "node": ">=20" } }, - "node_modules/@stryker-mutator/core/node_modules/json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true, - "license": "MIT" - }, "node_modules/@stryker-mutator/instrumenter": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/@stryker-mutator/instrumenter/-/instrumenter-10.0.0.tgz", @@ -4968,16 +4945,16 @@ } }, "node_modules/ajv": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.15.0.tgz", - "integrity": "sha512-fgFx7Hfoq60ytK2c7DhnF8jIvzYgOMxfugjLOSMHjLIPgenqa7S7oaagATUq99mV6IYvN2tRmC0wnTYX6iPbMw==", + "version": "8.20.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", + "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", "dev": true, "license": "MIT", "dependencies": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" }, "funding": { "type": "github", @@ -6474,6 +6451,23 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint/node_modules/ajv": { + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.15.0.tgz", + "integrity": "sha512-fgFx7Hfoq60ytK2c7DhnF8jIvzYgOMxfugjLOSMHjLIPgenqa7S7oaagATUq99mV6IYvN2tRmC0wnTYX6iPbMw==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, "node_modules/eslint/node_modules/eslint-visitor-keys": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz", @@ -6515,6 +6509,13 @@ "node": ">= 4" } }, + "node_modules/eslint/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true, + "license": "MIT" + }, "node_modules/espree": { "version": "10.4.0", "resolved": "https://registry.npmjs.org/espree/-/espree-10.4.0.tgz", @@ -7378,9 +7379,9 @@ "license": "MIT" }, "node_modules/json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index 048b7fe8..61618b04 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "@types/node": "^24", "@vercel/ncc": "^0.45.0", "@vitest/coverage-v8": "^5.0.5", + "ajv": "^8.20.0", "eslint": "^10.13.0", "miniflare": "^4.20260730.0", "msw": "^3.0.3",