forked from sgoudelis/ground-station
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.drone.yml
More file actions
305 lines (270 loc) · 9.24 KB
/
.drone.yml
File metadata and controls
305 lines (270 loc) · 9.24 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
kind: pipeline
type: docker
name: default
timeout: 360
platform:
os: linux
arch: arm64
trigger:
event:
- push
- pull_request
- tag
- custom
clone:
disable: true
steps:
- name: clone
image: plugins/git
settings:
depth: 50
skip_verify: true
tags: true
- name: build-and-deploy-amd64
image: docker:cli
depends_on:
- clone
environment:
DOCKER_HOST: tcp://192.168.60.98:2375
when:
event:
exclude:
- tag
commands:
# Extract version with proper debugging
- VERSION_BASE=$(cat backend/server/version.json | grep -o '"version"[[:space:]]*:[[:space:]]*"[^"]*"' | cut -d'"' -f4)
- echo "Extracted VERSION_BASE=$VERSION_BASE"
# Get git hash
- GIT_SHA=$(git rev-parse --short HEAD)
- echo "Extracted GIT_SHA=$GIT_SHA"
# Set environment type
- if [ "$DRONE_BRANCH" = "main" ]; then ENV_TYPE="production"; else ENV_TYPE="development"; fi
- echo "ENV_TYPE=$ENV_TYPE"
# Get build date
- BUILD_DATE=$(date -u +'%Y%m%d')
- echo "BUILD_DATE=$BUILD_DATE"
# Make a full version string
- FULL_VERSION=$VERSION_BASE-$DRONE_BRANCH-$GIT_SHA
- echo "FULL_VERSION=$FULL_VERSION"
# Build the new image for amd64 with build args
- docker build --platform linux/amd64 --build-arg GS_ENVIRONMENT=$ENV_TYPE --build-arg GIT_COMMIT=$GIT_SHA --build-arg BUILD_DATE=$BUILD_DATE --build-arg BUILD_VERSION=$FULL_VERSION -t ground-station:$FULL_VERSION .
# Tag the image for Docker Hub
- docker tag ground-station:$FULL_VERSION sgoudelis/ground-station:$FULL_VERSION
- docker tag ground-station:$FULL_VERSION sgoudelis/ground-station:latest
- docker tag ground-station:$FULL_VERSION sgoudelis/ground-station:$ENV_TYPE-latest
# Stop and remove the existing container if it exists
- docker rm -f ground-station-prod || true
# Run the new container with the versioned image (using host networking for mDNS discovery)
- docker run -d --network host --device=/dev/bus/usb --restart=unless-stopped --privileged --name ground-station-prod -v /media/pool1/volumes/ground-station-data:/app/backend/data -e GS_ENVIRONMENT=$ENV_TYPE -e GR_BUFFER_TYPE=vmcirc_mmap_tmpfile sgoudelis/ground-station:$FULL_VERSION
# Check that it's running
- sleep 5
- |
CONTAINER_STATUS=$(docker inspect --format='{{.State.Status}}' ground-station-prod)
if [ "$CONTAINER_STATUS" != "running" ]; then
echo "Container is not running: $CONTAINER_STATUS"
docker logs ground-station-prod
exit 1
fi
# Display container info and version
- echo "✅ New container version $FULL_VERSION ($ENV_TYPE) is running on AMD64 host port 7000"
- docker ps | grep ground-station-prod
- name: build-and-deploy-rpi5
image: docker:cli
depends_on:
- clone
environment:
DOCKER_HOST: tcp://192.168.60.52:2375
when:
event:
exclude:
- tag
commands:
# Extract version with proper debugging
- VERSION_BASE=$(cat backend/server/version.json | grep -o '"version"[[:space:]]*:[[:space:]]*"[^"]*"' | cut -d'"' -f4)
- echo "Extracted VERSION_BASE=$VERSION_BASE"
# Get git hash
- GIT_SHA=$(git rev-parse --short HEAD)
- echo "Extracted GIT_SHA=$GIT_SHA"
# Set environment type
- if [ "$DRONE_BRANCH" = "main" ]; then ENV_TYPE="production"; else ENV_TYPE="development"; fi
- echo "ENV_TYPE=$ENV_TYPE"
# Get build date
- BUILD_DATE=$(date -u +'%Y%m%d')
- echo "BUILD_DATE=$BUILD_DATE"
# Make a full version string
- FULL_VERSION=$VERSION_BASE-$DRONE_BRANCH-$GIT_SHA
- echo "FULL_VERSION=$FULL_VERSION"
# Build the new image for arm64 (RPi5) with build args
- docker build --platform linux/arm64 --build-arg GS_ENVIRONMENT=$ENV_TYPE --build-arg GIT_COMMIT=$GIT_SHA --build-arg BUILD_DATE=$BUILD_DATE --build-arg BUILD_VERSION=$FULL_VERSION -t ground-station:$FULL_VERSION .
# Tag the image
- docker tag ground-station:$FULL_VERSION sgoudelis/ground-station:$FULL_VERSION-arm64
- docker tag ground-station:$FULL_VERSION sgoudelis/ground-station:latest-arm64
- docker tag ground-station:$FULL_VERSION sgoudelis/ground-station:$ENV_TYPE-latest-arm64
# Stop and remove the existing container if it exists
- docker rm -f ground-station-prod || true
# Run the new container with the versioned image (use local image, not registry, with host networking for mDNS discovery)
- docker run -d --network host --device=/dev/bus/usb --restart=unless-stopped --privileged --name ground-station-prod -v /home/sgoudelis/ground-station-data:/app/backend/data -e GS_ENVIRONMENT=$ENV_TYPE -e GR_BUFFER_TYPE=vmcirc_mmap_tmpfile ground-station:$FULL_VERSION
# Check that it's running
- sleep 5
- |
CONTAINER_STATUS=$(docker inspect --format='{{.State.Status}}' ground-station-prod)
if [ "$CONTAINER_STATUS" != "running" ]; then
echo "Container is not running: $CONTAINER_STATUS"
docker logs ground-station-prod
exit 1
fi
# Display container info and version
- echo "✅ New container version $FULL_VERSION ($ENV_TYPE) is running on RPi5 host port 7000"
- docker ps | grep ground-station-prod
- name: verify-docker-connection
image: docker:cli
environment:
DOCKER_HOST: tcp://192.168.60.98:2375
commands:
- docker info
- echo "Docker connection verified"
depends_on:
- clone
when:
event:
- tag
- name: docker-auth
image: docker:cli
environment:
DOCKER_HOST: tcp://192.168.60.98:2375
DOCKER_USERNAME:
from_secret: docker_username
DOCKER_PASSWORD:
from_secret: docker_password
commands:
- echo "Attempting Docker Hub authentication..."
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- echo "✅ Docker Hub authentication successful"
depends_on:
- verify-docker-connection
when:
event:
- tag
- name: ghcr-auth
image: docker:cli
environment:
DOCKER_HOST: tcp://192.168.60.98:2375
GHCR_TOKEN:
from_secret: ghcr_token
commands:
- echo "Authenticating to GitHub Container Registry..."
- echo "$GHCR_TOKEN" | docker login ghcr.io -u sgoudelis --password-stdin
- echo "✅ GHCR authentication successful"
depends_on:
- docker-auth
# AMD64 Build
- name: build-amd64
image: plugins/docker:21
timeout: 240
settings:
username: sgoudelis
password:
from_secret: ghcr_token
registry: ghcr.io
repo: ghcr.io/sgoudelis/ground-station
tags:
- "${DRONE_TAG##v}-amd64"
- latest-amd64
dockerfile: Dockerfile
platforms:
- linux/amd64
build_args:
- GS_ENVIRONMENT=production
- "GIT_COMMIT=${DRONE_COMMIT_SHA}"
- "BUILD_DATE=${DRONE_BUILD_STARTED}"
- "BUILD_VERSION=${DRONE_TAG##v}"
buildkit: true
cache_from:
- ghcr.io/sgoudelis/ground-station:latest-amd64
- ghcr.io/sgoudelis/ground-station:latest
pull: true
daemon_off: true
custom_dns: 8.8.8.8
environment:
DOCKER_HOST: tcp://192.168.60.98:2375
depends_on:
- ghcr-auth
when:
event:
- tag
# ARM64 Build (on remote Jetson Orin)
- name: build-arm64
image: plugins/docker:21
timeout: 480
settings:
username: sgoudelis
password:
from_secret: ghcr_token
registry: ghcr.io
repo: ghcr.io/sgoudelis/ground-station
tags:
- "${DRONE_TAG##v}-arm64"
- latest-arm64
dockerfile: Dockerfile
platforms:
- linux/arm64
build_args:
- GS_ENVIRONMENT=production
- "GIT_COMMIT=${DRONE_COMMIT_SHA}"
- "BUILD_DATE=${DRONE_BUILD_STARTED}"
- "BUILD_VERSION=${DRONE_TAG##v}"
buildkit: true
cache_from:
- ghcr.io/sgoudelis/ground-station:latest-arm64
- ghcr.io/sgoudelis/ground-station:latest
pull: true
daemon_off: true
custom_dns: 8.8.8.8
environment:
DOCKER_HOST: tcp://192.168.60.51:2375
depends_on:
- ghcr-auth
when:
event:
- tag
# Create manifest for multi-arch
- name: manifest
image: plugins/manifest
settings:
username:
from_secret: ghcr_username
password:
from_secret: ghcr_token
target: "ghcr.io/sgoudelis/ground-station:${DRONE_TAG##v}"
template: "ghcr.io/sgoudelis/ground-station:${DRONE_TAG##v}-ARCH"
platforms:
- linux/amd64
- linux/arm64
depends_on:
- build-amd64
- build-arm64
when:
event:
- tag
# Create latest manifest
- name: manifest-latest
image: plugins/manifest
settings:
username:
from_secret: ghcr_username
password:
from_secret: ghcr_token
target: ghcr.io/sgoudelis/ground-station:latest
template: ghcr.io/sgoudelis/ground-station:latest-ARCH
platforms:
- linux/amd64
- linux/arm64
depends_on:
- manifest
when:
event:
- tag
volumes:
- name: docker-sock
host:
path: /var/run/docker.sock