-
Notifications
You must be signed in to change notification settings - Fork 44
133 lines (113 loc) · 3.41 KB
/
container.yaml
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
name: Container
on:
push:
branches:
- "develop"
- "main"
tags:
- "v*"
pull_request:
branches:
- "develop"
- "main"
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: Test (Docker)
runs-on: ubuntu-latest
strategy:
matrix:
target: [debug, release]
steps:
- id: setup
name: Setup Toolchain
uses: docker/setup-buildx-action@v2
- id: build
name: Build
uses: docker/build-push-action@v4
with:
file: ./Containerfile
push: false
load: true
target: ${{ matrix.target }}
tags: torrust-tracker:local
cache-from: type=gha
cache-to: type=gha
- id: inspect
name: Inspect
run: docker image inspect torrust-tracker:local
- id: checkout
name: Checkout Repository
uses: actions/checkout@v4
- id: compose
name: Compose
run: docker compose build
context:
name: Context
needs: test
runs-on: ubuntu-latest
outputs:
continue: ${{ steps.check.outputs.continue }}
steps:
- id: check
name: Check Context
run: |
if [[ "${{ github.event_name }}" == "push" && ( "${{ github.ref }}" == "refs/heads/main" || "${{ github.ref }}" == "refs/heads/develop" || "${{ github.ref }}" == "refs/heads/docker" ) ]] ||
[[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [[ "${{ github.repository }}" == "torrust/torrust-tracker" ]]; then
echo "Context is torrust/torrust-tracker, and push is: main, develop, docker, or a tag of v*.*.*"
echo "continue=true" >> $GITHUB_OUTPUT
fi
fi
secrets:
name: Secrets
needs: context
environment: dockerhub-torrust
if: needs.context.outputs.continue == 'true'
runs-on: ubuntu-latest
outputs:
continue: ${{ steps.check.outputs.continue }}
steps:
- id: check
name: Check
env:
DOCKER_HUB_ACCESS_TOKEN: "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}"
if: "${{ env.DOCKER_HUB_ACCESS_TOKEN != '' }}"
run: echo "continue=true" >> $GITHUB_OUTPUT
publish:
name: Publish
environment: dockerhub-torrust
needs: secrets
if: needs.secrets.outputs.continue == 'true'
runs-on: ubuntu-latest
steps:
- id: meta
name: Docker meta
uses: docker/metadata-action@v4
with:
images: |
"${{ secrets.DOCKER_HUB_USERNAME }}/${{secrets.DOCKER_HUB_REPOSITORY_NAME }}"
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- id: login
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- id: setup
name: Setup Toolchain
uses: docker/setup-buildx-action@v2
- name: Build and push
uses: docker/build-push-action@v4
with:
file: ./Containerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha