Repository navigation
112 lines (107 loc) · 4.76 KB
/
Copy pathdeploy.yml
File metadata and controls
112 lines (107 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Deploys main to your team URL (deploy contract: README.md).
#
# The job builds the root Dockerfile with this commit's SHA baked in, pushes it to your registry as
# app:<sha> and app:latest, and runs .github/fagdag/rollout.sh. That redeploys your container, fails
# unless Scaleway reports it ready, then waits up to 60 s for GET /health to answer 200 with this
# commit's SHA as its version. If any of that fails, it points app:latest back at the version that
# was live before (which keeps serving) and the job fails, with the container's error_message and
# its logs since the job started in the last step.
#
# You own this file. Add your own gates (tests, Hurl examples, review checks) as jobs that the
# deploy job `needs`; they run on GitHub-hosted runners. If you break it, you lose your own ticks.
#
# The organisers set the config: the secrets SCW_ACCESS_KEY and SCW_SECRET_KEY (your push key) and
# the variables SCW_REGISTRY, SCW_CONTAINER_ID, SCW_ORGANIZATION_ID and TEAM_URL. Don't change them.
name: deploy
on:
push:
branches: [main]
# Every deploy restarts the container (~30 s before it answers), and the harness's checks that hit the
# switchover get no response: tick 109 failed checks in every feature after a run of docs-only pushes.
# So a push that changes only these files doesn't deploy. A push that also touches anything else still does.
paths-ignore:
- '**.md'
- 'workflow/**'
- '.claude/**'
- 'specs/**'
- 'examples/**'
# The image is built from the Dockerfile, pom.xml and src/ only: a workflow or script change needs no restart.
# (Run the workflow by hand from the Actions tab if you do want a deploy.)
- '.github/**'
workflow_dispatch:
# One deploy at a time; a newer push waits rather than cancelling a deploy halfway.
concurrency:
group: deploy
cancel-in-progress: false
permissions:
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 15
env:
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
# The scw CLI won't run without it, even with a key.
SCW_DEFAULT_ORGANIZATION_ID: ${{ vars.SCW_ORGANIZATION_ID }}
SCW_REGISTRY: ${{ vars.SCW_REGISTRY }}
SCW_CONTAINER_ID: ${{ vars.SCW_CONTAINER_ID }}
IMAGE: ${{ vars.SCW_REGISTRY }}/app
SHA: ${{ github.sha }}
steps:
- name: Note the start time
run: echo "ROLLOUT_STARTED_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >>"$GITHUB_ENV"
- uses: actions/checkout@v5
- name: Install the Scaleway CLI
uses: scaleway/action-scw@2e34a1eb35cf3cac627f24643a101fea269cbd83 # v0.0.3
with:
version: v2.65.2
- name: Log in to the registry
run: echo "$SCW_SECRET_KEY" | docker login "${SCW_REGISTRY%%/*}" --username nologin --password-stdin
- name: Build and push
run: |
echo "Building $SHA as $IMAGE:$SHA and $IMAGE:latest"
docker build --platform linux/amd64 --build-arg "GIT_SHA=$SHA" --tag "$IMAGE:$SHA" --tag "$IMAGE:latest" .
docker push "$IMAGE:$SHA"
docker push "$IMAGE:latest"
- name: Roll out
id: rollout
env:
ROLLOUT_URL: ${{ vars.TEAM_URL }}
ROLLOUT_SHA: ${{ github.sha }}
ROLLOUT_IMAGE: app
run: .github/fagdag/rollout.sh
# Only when the rollout failed: build errors are in the step above it. Image pull errors only
# show up in error_message; a crash on start-up shows up in the logs.
- name: Logs
if: ${{ failure() && steps.rollout.outcome == 'failure' }}
run: |
sleep 15 # Cockpit takes a few seconds to ingest the lines.
echo "error_message: $(scw container container get "$SCW_CONTAINER_ID" -o json | jq -r '.error_message // "(none)"')" || true
.github/fagdag/logs.sh --tail 200 --since "$ROLLOUT_STARTED_AT"
# The unit tests run after the deploy and are NOT a gate: the suite is thin and partly wrong.
# To make them one, move this job before deploy and add `needs: tests` to the deploy job.
tests:
needs: deploy
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
continue-on-error: true
timeout-minutes: 15
steps:
- uses: actions/checkout@v5
- uses: actions/setup-java@v5
with:
distribution: temurin
# Same Java as the Dockerfile and pom.xml (Spring Boot 4 on Java 25). With 11 the job failed:
# "release version 25 not supported".
java-version: "25"
- name: Cache ~/.m2
uses: actions/cache@v4
with:
path: |
~/.m2/repository
~/.m2/wrapper
key: m2-${{ hashFiles('**/pom.xml', '.mvn/wrapper/maven-wrapper.properties') }}
restore-keys: m2-
- name: Unit tests
run: ./mvnw -B test