-
Notifications
You must be signed in to change notification settings - Fork 6
200 lines (165 loc) · 6.3 KB
/
controller.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
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
name: Controller CI/CD
on: push
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest"]
go-version: ["1.17", "1.18"]
defaults:
run:
working-directory: ./controller
steps:
- uses: actions/checkout@v2
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Run tests
env:
# We aim to be CGO free to improve compatibility. Disabling it in the CI should help with that goal.
CGO_ENABLED: 0
ENCODARR_CONFIG_DIR: ${{ runner.temp }}
run: go test ./...
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest"]
go-version: ["1.18"]
go-os-arch:
[
"linux/amd64",
"linux/arm64",
"linux/arm",
"windows/amd64",
"darwin/amd64",
"darwin/arm64",
]
defaults:
run:
working-directory: ./controller
steps:
- uses: actions/checkout@v2
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Compute GOOS and GOARCH
env:
IFS: "/"
run: |
echo "COMP_GOOS=$(echo ${{ matrix.go-os-arch }} | cut -d/ -f1 -)" >> $GITHUB_ENV
echo "COMP_GOARCH=$(echo ${{ matrix.go-os-arch }} | cut -d/ -f2 -)" >> $GITHUB_ENV
- name: Set suffix (windows)
if: contains(matrix.go-os-arch, 'windows')
run: echo "EXEC_SUFFIX=.exe" >> $GITHUB_ENV
- name: Set suffix (literally everything else)
if: "!contains(matrix.go-os-arch, 'windows')"
run: echo "EXEC_SUFFIX=$("")" >> $GITHUB_ENV
- name: Set version for ldflags (tag ref)
if: startsWith(github.ref, 'refs/tags/')
run: echo "LDFLAGS_VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV
- name: Set version for ldflags (non-tag ref)
if: "!startsWith(github.ref, 'refs/tags/')"
# Makes the embedded version "{branch-name}-development"
run: echo "LDFLAGS_VERSION=$(echo ${GITHUB_REF:11})-development" >> $GITHUB_ENV
- name: Build executable
env:
# We aim to be CGO free to improve compatibility. Disabling it in the CI should help with enforcing that goal.
CGO_ENABLED: 0
GOARM: 7
GOOS: ${{ env.COMP_GOOS }}
GOARCH: ${{ env.COMP_GOARCH }}
run: go build -o encodarr-controller-${{ env.COMP_GOOS }}-${{ env.COMP_GOARCH }}${{ env.EXEC_SUFFIX }} -ldflags="-X 'github.com/BrenekH/encodarr/controller/globals.Version=${{ env.LDFLAGS_VERSION }}'" cmd/main.go
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: encodarr-controller-${{ env.COMP_GOOS }}-${{ env.COMP_GOARCH }}${{ env.EXEC_SUFFIX }}
path: ${{ github.workspace }}/controller/encodarr-controller-${{ env.COMP_GOOS }}-${{ env.COMP_GOARCH }}${{ env.EXEC_SUFFIX }}
deploy-container-images-tags:
runs-on: ubuntu-latest
needs: [test, build]
if: github.repository_owner == 'BrenekH' && github.actor != 'dependabot[bot]' # Ensure secrets are defined
steps:
- uses: actions/checkout@v2
- name: Generate Docker Metadata
id: meta
uses: crazy-max/ghaction-docker-meta@v2
with:
images: |
brenekh/encodarr-controller
ghcr.io/brenekh/encodarr-controller
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-controller-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-controller-buildx-
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set version for ldflags (tag ref)
if: startsWith(github.ref, 'refs/tags/')
run: echo "LDFLAGS_VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV
- name: Set version for ldflags (non-tag ref)
if: "!startsWith(github.ref, 'refs/tags/')"
# Makes the embedded version "{branch-name}-development"
run: echo "LDFLAGS_VERSION=$(echo ${GITHUB_REF:11})-development" >> $GITHUB_ENV
- name: Build and push container images/tags
uses: docker/build-push-action@v2
with:
context: ./controller
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
build-args: LDFLAGS_VERSION=${{ env.LDFLAGS_VERSION }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Move cache
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
upload-binaries-to-gh-releases:
runs-on: ubuntu-latest
needs: [test, build]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Download build artifacts
uses: actions/download-artifact@v2
with:
path: ${{ github.workspace }}/build-artifacts
- name: Upload to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ github.workspace }}/build-artifacts/*/*
tag: ${{ github.ref }}
overwrite: true
file_glob: true