-
Notifications
You must be signed in to change notification settings - Fork 2
210 lines (178 loc) · 5.74 KB
/
container.yaml
File metadata and controls
210 lines (178 loc) · 5.74 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
# Container workflow for Torrust Tracker Deployer
#
# This workflow builds, tests, and publishes the deployer Docker image.
# Following patterns from torrust/torrust-tracker container.yaml workflow.
#
# Triggers:
# - Push to main/develop branches
# - Pull requests to main/develop
# - Manual dispatch
#
# Publishing:
# - Images are pushed to Docker Hub on push to main/develop (not PRs)
# - Requires Docker Hub credentials in repository secrets
name: Container
on:
push:
branches:
- "develop"
- "main"
paths:
- "src/**"
- "Cargo.toml"
- "Cargo.lock"
- "docker/deployer/**"
- ".github/workflows/container.yaml"
pull_request:
branches:
- "develop"
- "main"
paths:
- "src/**"
- "Cargo.toml"
- "Cargo.lock"
- "docker/deployer/**"
- ".github/workflows/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@v4
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Image
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/deployer/Dockerfile
target: release
push: false
load: true
tags: torrust-tracker-deployer:local
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Inspect Image
run: docker image inspect torrust-tracker-deployer:local
- name: Verify Tools
run: |
echo "=== Verifying installed tools ==="
docker run --rm torrust-tracker-deployer:local --version || true
echo "=== Checking OpenTofu ==="
docker run --rm --entrypoint tofu torrust-tracker-deployer:local version
echo "=== Checking Ansible ==="
docker run --rm --entrypoint ansible torrust-tracker-deployer:local --version
echo "=== Checking SSH ==="
docker run --rm --entrypoint ssh torrust-tracker-deployer:local -V
echo "=== Checking Git ==="
docker run --rm --entrypoint git torrust-tracker-deployer:local --version
- name: Test Help Output
run: |
docker run --rm torrust-tracker-deployer:local --help
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
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@v4
- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_HUB_USERNAME }}/tracker-deployer
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: .
file: ./docker/deployer/Dockerfile
target: release
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
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@v4
- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_HUB_USERNAME }}/tracker-deployer
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: .
file: ./docker/deployer/Dockerfile
target: release
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max