Repository navigation
137 lines (128 loc) · 6.41 KB
/
Copy pathdocker-build.yml
File metadata and controls
137 lines (128 loc) · 6.41 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Nightly Build Orchestrator
on:
workflow_dispatch: # allows us to trigger runs manually in the GitHub UI
inputs:
node_ref:
description: 'nodejs/node commit SHA to build (default: tip of the default branch)'
type: string
required: false
default: ''
platform:
description: 'Platform(s) to build'
type: choice
options:
- all
- linux/amd64 (linux/arm64 keeps its previous image)
- linux/arm64 (linux/amd64 keeps its previous image)
default: all
repository_dispatch: # sent by nodejs/node's daily workflow once it has built main
types: [node-daily]
schedule:
# Fallback in case the dispatches from nodejs/node stop arriving.
- cron: '0 6 * * 0' # runs weekly
# nodejs/node's daily workflow dispatches a `node-daily` event with the commit it builds successfully.
#
# The resolve job picks the commit once, so every platform builds the same one.
# Each platform builds in its own job on a native runner and pushes its own nightly-linux-<arch> and nightly-<sha>-linux-<arch> tags.
# Then, the merge workflow combines the platform tags into `nightly` and the immutable `nightly-<sha>`.
#
# If any platform fails, the others still push their own platform tags, but `nightly` is not updated.
# The failed run flags the broken platform in an issue.
jobs:
resolve:
if: ${{ github.ref == format('refs/heads/{0}', vars.NIGHTLY_BRANCH) }}
runs-on: ubuntu-slim
outputs:
sha: ${{ steps.resolve.outputs.sha }}
steps:
- name: Resolve the nodejs/node commit
id: resolve
env:
NODE_REF: ${{ github.event.client_payload.sha || inputs.node_ref }}
run: |
if [ -z "$NODE_REF" ]; then
NODE_REF=$(git ls-remote https://github.com/nodejs/node.git refs/heads/main | cut -f1)
fi
if [[ ! "$NODE_REF" =~ ^[0-9a-f]{40}$ ]]; then
echo "::error::NODE_REF must be a full commit SHA, got: $NODE_REF"
exit 1
fi
echo "sha=$NODE_REF" >> "$GITHUB_OUTPUT"
docker:
needs: [resolve]
strategy:
fail-fast: false
matrix:
arch: ${{ fromJSON(startsWith(inputs.platform, 'linux/amd64') && '["amd64"]' || startsWith(inputs.platform, 'linux/arm64') && '["arm64"]' || '["amd64", "arm64"]') }}
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-26.04-arm' || 'ubuntu-26.04' }}
steps: # See https://docs.docker.com/build/ci/github-actions/multi-platform/
- name: Login to DockerHub
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0
with: # these are defined in the GitHub Secrets UI
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Build and push
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
platforms: linux/${{ matrix.arch }}
push: true
build-args: NODE_REF=${{ needs.resolve.outputs.sha }}
labels: org.nodejs.node.commit=${{ needs.resolve.outputs.sha }}
tags: |
${{ vars.DOCKERHUB_IMAGE }}:nightly-linux-${{ matrix.arch }}
${{ vars.DOCKERHUB_IMAGE }}:nightly-${{ needs.resolve.outputs.sha }}-linux-${{ matrix.arch }}
# Only runs when every platform in this run built successfully (the default for `needs`).
merge:
needs: [resolve, docker]
uses: $/.github/workflows/docker-merge.yml
secrets: inherit
with:
# A single-platform run has no nightly-<sha> image for the other platform, so it only updates `nightly`.
sha: ${{ (inputs.platform || 'all') == 'all' && needs.resolve.outputs.sha || '' }}
# GitHub only notifies whoever triggered a run (for repository_dispatches it is the bot account)
# So when an automatic run fails, open a tracking issue (or comment on the open one), and close it once a run succeeds.
# Manual runs are skipped: GitHub already notifies whoever started them.
report:
needs: [resolve, docker, merge]
if: ${{ !cancelled() && github.event_name != 'workflow_dispatch' && needs.resolve.result != 'skipped' }}
runs-on: ubuntu-slim
permissions:
actions: read # to list the failed jobs
issues: write
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
FAILED: ${{ contains(needs.*.result, 'failure') }}
NODE_REF: ${{ needs.resolve.outputs.sha || github.event.client_payload.sha || 'tip of the default branch' }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
steps:
- name: Open, update, or close the tracking issue
run: |
issue=$(gh issue list --label "nightly-build-failure" --state open --json number --jq '.[0].number // empty')
if [ "$FAILED" = true ]; then
failed_jobs=$(gh run view "$GITHUB_RUN_ID" --json jobs --jq '.jobs[] | select(.conclusion == "failure") | "- " + .name')
details=$(printf 'Run: %s\nTrigger: %s\nnodejs/node commit: %s\n\nFailed jobs:\n%s' "$RUN_URL" "$GITHUB_EVENT_NAME" "$NODE_REF" "$failed_jobs")
if [ -n "$issue" ]; then
gh issue comment "$issue" --body "$(printf 'Still failing.\n\n%s' "$details")"
else
gh issue create --label "nightly-build-failure" --title 'Nightly image build is failing' \
--body "$(printf '@nodejs/devcontainer the nightly tag was not updated because a build failed.\n\n%s' "$details")"
fi
elif [ -n "$issue" ]; then
gh issue close "$issue" --comment "Fixed: $RUN_URL built successfully and tagged nightly."
fi
# GitHub disables scheduled workflows in public repositories after 60 days without repository activity.
# This repo often goes a long time without reasonable updates, yet we want the images to continue building.
# Re-enabling the workflow on every automatic run resets that timer, so the weekly fallback keeps running even when the repo is quiet.
keepalive:
if: ${{ github.event_name != 'workflow_dispatch' }}
runs-on: ubuntu-slim
permissions:
actions: write
steps:
- name: Keep the scheduled trigger enabled
run: gh api -X PUT "repos/${GITHUB_REPOSITORY}/actions/workflows/docker-build.yml/enable"
env:
GH_TOKEN: ${{ github.token }}