-
Notifications
You must be signed in to change notification settings - Fork 1
174 lines (160 loc) · 6.41 KB
/
Copy pathbuild.yml
File metadata and controls
174 lines (160 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Build and Push Docker Images
on:
push:
branches:
- master
tags:
- "v*"
pull_request:
workflow_dispatch:
inputs:
docker:
description: 'Docker image to build'
required: false
default: 'all'
type: choice
options:
- all
- lnvps-api
- lnvps-api-admin
- lnvps-operator
- lnvps-nostr
- lnvps-host-info
env:
REGISTRY: registry.v0l.io
HOST_INFO_IMAGE: registry.v0l.io/lnvps-host-info
jobs:
# Decide, once, what tag to publish and whether to push:
# * master push -> :latest (rolling dev images)
# * tag push (v*) -> :<version> (immutable release images, e.g. 0.3.2)
# * PR / other dispatch -> build only, no push
setup:
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.meta.outputs.image_tag }}
push: ${{ steps.meta.outputs.push }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Compute image tag + push flag
id: meta
run: |
if [ "${{ github.event_name }}" = "push" ] && [[ "${{ github.ref }}" == refs/tags/v* ]]; then
# Release tag: strip the leading 'v' so the image tag matches the crate version.
TAG="${GITHUB_REF_NAME#v}"
# Guard: the root workspace version MUST match the release tag, so
# the published images are never mislabelled vs their crate version.
VER=$(awk '/^\[workspace.package\]/{f=1} f&&/^version[[:space:]]*=/{gsub(/.*=[[:space:]]*"|".*/,"");print;exit}' Cargo.toml)
if [ "$VER" != "$TAG" ]; then
echo "::error::root Cargo.toml [workspace.package] version ($VER) != release tag ($TAG). Bump the version before tagging."
exit 1
fi
echo "image_tag=$TAG" >> "$GITHUB_OUTPUT"
echo "push=true" >> "$GITHUB_OUTPUT"
elif [ "${{ github.event_name }}" = "push" ] && [ "${{ github.ref }}" = "refs/heads/master" ]; then
echo "image_tag=latest" >> "$GITHUB_OUTPUT"
echo "push=true" >> "$GITHUB_OUTPUT"
else
echo "image_tag=latest" >> "$GITHUB_OUTPUT"
echo "push=false" >> "$GITHUB_OUTPUT"
fi
# Build host-info as a multi-arch image first
build-host-info:
runs-on: ubuntu-latest
needs: setup
if: >
github.event_name == 'push' ||
github.event_name == 'pull_request' ||
(github.event_name == 'workflow_dispatch' && (github.event.inputs.docker == 'lnvps-host-info' || github.event.inputs.docker == 'all'))
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up QEMU
if: needs.setup.outputs.push == 'true'
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Docker Registry
if: needs.setup.outputs.push == 'true'
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 5
retry_wait_seconds: 15
# SYN drops in the AVS/GSL scrubbing path randomly kill handshakes
# under concurrent CI logins; retry to ride over transient drops.
command: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ env.REGISTRY }} -u registry --password-stdin
- name: Build and push lnvps-host-info
uses: docker/build-push-action@v6
with:
context: lnvps_host_util
file: lnvps_host_util/Dockerfile
platforms: ${{ needs.setup.outputs.push == 'true' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
push: ${{ needs.setup.outputs.push == 'true' }}
tags: ${{ env.HOST_INFO_IMAGE }}:${{ needs.setup.outputs.image_tag }}
cache-from: type=gha,scope=host-info
cache-to: type=gha,mode=max,scope=host-info
# Build main images after host-info is ready
build:
runs-on: ubuntu-latest
needs: [setup, build-host-info]
if: >
always() && (
github.event_name == 'push' ||
github.event_name == 'pull_request' ||
github.event_name == 'workflow_dispatch'
)
strategy:
fail-fast: false
# Limit concurrent registry logins/pushes so we don't trip the
# DDoS-mitigation SYN-rate limiter (AVS behind GSL) with a burst.
max-parallel: 2
matrix:
include:
- name: lnvps-api
file: lnvps_api/Dockerfile
image: registry.v0l.io/lnvps-api
- name: lnvps-api-admin
file: lnvps_api_admin/Dockerfile
image: registry.v0l.io/lnvps-api-admin
- name: lnvps-operator
file: lnvps_operator/Dockerfile
image: registry.v0l.io/lnvps-operator
- name: lnvps-nostr
file: lnvps_nostr/Dockerfile
image: registry.v0l.io/lnvps-nostr
- name: lnvps-agent
file: lnvps_agent/Dockerfile
image: registry.v0l.io/lnvps-agent
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Docker Registry
if: needs.setup.outputs.push == 'true'
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 5
retry_wait_seconds: 15
# SYN drops in the AVS/GSL scrubbing path randomly kill handshakes
# under concurrent CI logins; retry to ride over transient drops.
command: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ env.REGISTRY }} -u registry --password-stdin
- name: Build and push ${{ matrix.name }}
if: >
github.event_name == 'push' ||
github.event_name == 'pull_request' ||
(github.event_name == 'workflow_dispatch' && (github.event.inputs.docker == matrix.name || github.event.inputs.docker == 'all'))
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.file }}
push: ${{ needs.setup.outputs.push == 'true' }}
tags: ${{ matrix.image }}:${{ needs.setup.outputs.image_tag }}
cache-from: type=gha,scope=${{ matrix.name }}
cache-to: type=gha,mode=max,scope=${{ matrix.name }}
build-args: |
HOST_INFO_IMAGE=${{ env.HOST_INFO_IMAGE }}:${{ needs.setup.outputs.image_tag }}
REGISTRY_USER=registry
REGISTRY_PASS=${{ secrets.REGISTRY_TOKEN }}