Skip to content

Commit d4868c3

Browse files
authored
CI: redeploy ok-dspace on pushes to clarin-v7 (#175)
* CI: redeploy the ok-dspace test environment on pushes to the default branch Sends a repository_dispatch to ufal/dspace-k8s once the images this environment consumes have actually been pushed. That repository pins the tag to git and an in-cluster reconciler applies it, so this job records a version and nothing more - no deployment step and no cluster credential exists here, or anywhere in GitHub. Runs only for pushes to the default branch of the canonical repository, so a pull request builds images but never triggers a deploy. The token is a fine-grained PAT scoped to ufal/dspace-k8s with Contents: write, which is what POST /repos/{owner}/{repo}/dispatches requires. A workflow's own GITHUB_TOKEN cannot act on another repository, so this credential is unavoidable; it is held as an organisation secret shared with this repository. * Address review: name what this job actually does The section header said "Redeploy" and the step was called "Trigger deployment", but this job only sends a repository_dispatch - the deploying happens in ufal/dspace-k8s and, ultimately, in the cluster. Renamed both so the workflow logs say what ran. Also names `clarin-v7` explicitly instead of "the default branch", since that is the literal value the guard matches and the two could drift apart. * Address review: drop unneeded token permissions from the dispatch job The job authenticates with a fine-grained PAT and never uses GITHUB_TOKEN, but inherited the workflow-level permissions anyway - including `packages: write` in dspace-angular, which it has no use for. `permissions: {}` limits what a compromised third-party action could reach from this job. * Address review: dispatch with gh instead of a third-party action peter-evans/repository-dispatch@v4 ran with the deploy PAT in its environment to make a single POST. ubuntu-latest already ships gh and jq, so the same call is three lines with no third-party code in the credential's blast radius. jq builds the payload from an --arg rather than interpolating the sha into a JSON string, so the value is a JSON string by construction. The request body is identical to what the action sent. The permissions comment no longer justifies itself by third-party actions, since there are none here now; permissions: {} still stands on its own, because the job authenticates with the PAT and never touches GITHUB_TOKEN.
1 parent 7b4769e commit d4868c3

1 file changed

Lines changed: 42 additions & 8 deletions

File tree

.github/workflows/docker.yml

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,45 @@ jobs:
6262
REDEPLOY_SANDBOX_URL: ${{ secrets.REDEPLOY_SANDBOX_URL }}
6363
REDEPLOY_DEMO_URL: ${{ secrets.REDEPLOY_DEMO_URL }}
6464

65-
# deploy:
66-
# needs: dspace-angular
67-
# uses: ufal/dspace-angular/.github/workflows/deploy.yml@clarin-v7
68-
# if: ${{ github.event_name != 'pull_request' }}
69-
# with:
70-
# INSTANCE: '5'
71-
# IMPORT: false
72-
# secrets: inherit
65+
###########################################################################
66+
# Notify ufal/dspace-k8s of a new build, for the ok-dspace test environment
67+
###########################################################################
68+
# Replaces the old commented-out deploy stub, which targeted the dataquest
69+
# docker-compose instances (dev-5/dev-8) we no longer have access to.
70+
#
71+
# Runs only for pushes to `clarin-v7` - currently the default branch, named
72+
# explicitly here because that is exactly what the guard below matches - and
73+
# only after the image this environment consumes has actually been pushed.
74+
#
75+
# This job records a new version; it does not deploy. It sends a
76+
# repository_dispatch to ufal/dspace-k8s, which pins the tag to git, and a
77+
# reconciler inside that cluster applies it. No deployment step and no cluster
78+
# credential exists in this repository, or anywhere in GitHub.
79+
deploy-ok-dspace:
80+
if: github.repository == 'ufal/dspace-angular' && github.event_name == 'push' && github.ref_name == 'clarin-v7'
81+
# dspace-angular-dist, NOT dspace-angular: the latter builds the '-dev'
82+
# suffixed image, while the overlay runs the unsuffixed dist image.
83+
needs: [dspace-angular-dist]
84+
runs-on: ubuntu-latest
85+
# This job authenticates with a PAT and never uses GITHUB_TOKEN, so it needs
86+
# none of the workflow-level permissions at all.
87+
permissions: {}
88+
steps:
89+
# One POST, hand-rolled with the `gh` and `jq` that ubuntu-latest already
90+
# ships, rather than a third-party dispatch action: a single API call is
91+
# not worth a supply-chain dependency that runs with the PAT in its
92+
# environment.
93+
- name: Notify ufal/dspace-k8s
94+
env:
95+
# Fine-grained PAT, scoped to ufal/dspace-k8s only, Contents: write
96+
# (what POST /repos/{owner}/{repo}/dispatches requires).
97+
GH_TOKEN: ${{ secrets.OK_DSPACE_DEPLOY_TOKEN }}
98+
SHA: ${{ github.sha }}
99+
run: |
100+
set -euo pipefail
101+
# jq builds the payload from an --arg, so the value is a JSON string
102+
# by construction rather than by careful quoting.
103+
jq -n --arg sha "${SHA}" \
104+
'{event_type: "deploy-ok-dspace",
105+
client_payload: {component: "frontend", sha: $sha}}' \
106+
| gh api -X POST repos/ufal/dspace-k8s/dispatches --input -

0 commit comments

Comments
 (0)