-
Notifications
You must be signed in to change notification settings - Fork 2
219 lines (187 loc) · 7 KB
/
backup-container.yaml
File metadata and controls
219 lines (187 loc) · 7 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
# Backup Container workflow for Torrust Tracker Deployer
#
# This workflow builds, tests, and publishes the backup Docker image.
# Following patterns from container.yaml workflow.
#
# Triggers:
# - Push to main/develop branches (only when backup container files change)
# - Pull requests to main/develop (only when backup container files change)
# - Manual dispatch
#
# Publishing:
# - Images are pushed to Docker Hub on push to main/develop (not PRs)
# - Requires Docker Hub credentials in repository secrets (dockerhub-torrust-backup environment)
name: Backup Container
on:
push:
branches:
- "develop"
- "main"
paths:
- "docker/backup/**"
- ".github/workflows/backup-container.yaml"
pull_request:
branches:
- "develop"
- "main"
paths:
- "docker/backup/**"
- ".github/workflows/backup-container.yaml"
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
DOCKER_HUB_USERNAME: torrust
jobs:
test:
name: Build & Test
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Image
uses: docker/build-push-action@v6
with:
# CRITICAL: Context must be ./docker/backup (not ./)
# Docker COPY/ADD commands resolve paths RELATIVE TO BUILD CONTEXT, not Dockerfile location.
# Setting context: ./docker/backup allows the Dockerfile to use simple relative paths like:
# COPY backup.sh /scripts/backup.sh
# This creates consistency between local builds and CI builds.
#
# Regression History: commit 9d297cc5 used context: . with full paths in Dockerfile
# (e.g., COPY docker/backup/backup.sh). This worked but was confusing and error-prone
# for future changes. The current approach is cleaner and prevents regression.
#
# See docker/backup/README.md "Building the Container" section for details.
context: ./docker/backup
file: ./docker/backup/Dockerfile
target: production
push: false
load: true
tags: torrust/tracker-backup:local
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Inspect Image
run: docker image inspect torrust/tracker-backup:local
- name: Verify Container Structure
run: |
echo "=== Verifying backup container structure ==="
echo "=== Checking backup script exists ==="
docker run --rm --entrypoint ls torrust/tracker-backup:local -lh /scripts/backup.sh
echo "=== Checking backup directories ==="
docker run --rm --entrypoint ls torrust/tracker-backup:local -ld /backups/mysql /backups/sqlite /backups/config
echo "=== Verifying tools installed ==="
docker run --rm --entrypoint which torrust/tracker-backup:local bash
docker run --rm --entrypoint which torrust/tracker-backup:local mysql
docker run --rm --entrypoint which torrust/tracker-backup:local sqlite3
docker run --rm --entrypoint which torrust/tracker-backup:local gzip
docker run --rm --entrypoint which torrust/tracker-backup:local tar
echo "=== Checking entrypoint ==="
docker inspect --format='{{.Config.Entrypoint}}' torrust/tracker-backup:local
- name: Test Container Execution
run: |
echo "=== Testing backup container without config (should fail gracefully) ==="
docker run --rm torrust/tracker-backup:local || true
context:
name: Context
needs: test
runs-on: ubuntu-latest
outputs:
continue: ${{ steps.check.outputs.continue }}
type: ${{ steps.check.outputs.type }}
steps:
- name: Check Context
id: check
run: |
if [[ "${{ github.repository }}" == "torrust/torrust-tracker-deployer" ]]; then
if [[ "${{ github.event_name }}" == "push" ]]; then
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "type=production" >> $GITHUB_OUTPUT
echo "continue=true" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
echo "type=development" >> $GITHUB_OUTPUT
echo "continue=true" >> $GITHUB_OUTPUT
fi
fi
fi
# Default: don't continue
if [[ -z "$(cat $GITHUB_OUTPUT 2>/dev/null)" ]]; then
echo "continue=false" >> $GITHUB_OUTPUT
fi
publish_development:
name: Publish (Development)
environment: dockerhub-torrust-backup
needs: context
if: needs.context.outputs.continue == 'true' && needs.context.outputs.type == 'development'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_HUB_USERNAME }}/tracker-backup
tags: |
type=ref,event=branch
type=sha,prefix=dev-
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push
uses: docker/build-push-action@v6
with:
context: ./docker/backup
file: ./docker/backup/Dockerfile
target: production
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
publish_production:
name: Publish (Production)
environment: dockerhub-torrust-backup
needs: context
if: needs.context.outputs.continue == 'true' && needs.context.outputs.type == 'production'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_HUB_USERNAME }}/tracker-backup
tags: |
type=raw,value=latest
type=ref,event=branch
type=sha
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push
uses: docker/build-push-action@v6
with:
context: ./docker/backup
file: ./docker/backup/Dockerfile
target: production
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max