Skip to content
This repository was archived by the owner on Dec 26, 2024. It is now read-only.

Commit 9d1ea5a

Browse files
authored
build: update workflows (#76)
* build: update workflows * build: depend on tests to pass
1 parent e770691 commit 9d1ea5a

File tree

2 files changed

+176
-26
lines changed

2 files changed

+176
-26
lines changed

.github/workflows/build.yaml

+120-26
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ on:
99
- 'v*'
1010
pull_request:
1111

12+
env:
13+
REGISTRY: ghcr.io
14+
REGISTRY_IMAGE: ghcr.io/${{ github.repository }}
15+
1216
permissions:
1317
contents: write
1418
packages: write
@@ -19,54 +23,61 @@ jobs:
1923
runs-on: ubuntu-latest
2024
steps:
2125
- name: Checkout
22-
uses: actions/checkout@v3
26+
uses: actions/checkout@v4
2327
with:
2428
fetch-depth: 0
2529

2630
- name: Set up Go
27-
uses: actions/setup-go@v3
31+
uses: actions/setup-go@v5
2832
with:
29-
go-version: '1.21'
33+
go-version: '1.22.0'
3034
cache: true
3135

3236
- name: Test
33-
run: go test -v ./...
37+
run: go run gotest.tools/gotestsum@latest --junitfile unit-tests.xml --format pkgname -- ./...
38+
39+
- name: Test Summary
40+
uses: test-summary/action@v2
41+
with:
42+
paths: "unit-tests.xml"
43+
if: always()
3444

3545
goreleaser:
3646
name: Build and publish Go binaries
3747
runs-on: ubuntu-latest
48+
needs: [test]
3849
steps:
3950
- name: Checkout
40-
uses: actions/checkout@v3
51+
uses: actions/checkout@v4
4152
with:
4253
fetch-depth: 0
4354

4455
- name: Set up Go
45-
uses: actions/setup-go@v3
56+
uses: actions/setup-go@v5
4657
with:
47-
go-version: '1.21'
58+
go-version: '1.22.0'
4859
cache: true
4960

5061
- name: Run GoReleaser build
51-
uses: goreleaser/goreleaser-action@v4
62+
uses: goreleaser/goreleaser-action@v5
5263
if: ${{ github.event_name == 'pull_request' }}
5364
with:
5465
distribution: goreleaser
5566
version: latest
56-
args: release --snapshot
67+
args: release --clean --skip=validate --skip=publish --parallelism 5 --snapshot
5768

5869
- name: Run GoReleaser build and publish tags
59-
uses: goreleaser/goreleaser-action@v4
70+
uses: goreleaser/goreleaser-action@v5
6071
if: startsWith(github.ref, 'refs/tags/')
6172
with:
6273
distribution: goreleaser
6374
version: latest
64-
args: release --rm-dist
75+
args: release --clean
6576
env:
6677
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6778

6879
- name: Upload assets
69-
uses: actions/upload-artifact@v3
80+
uses: actions/upload-artifact@v4
7081
with:
7182
name: omegabrr
7283
path: |
@@ -77,45 +88,128 @@ jobs:
7788
docker:
7889
name: Build and publish Docker images
7990
runs-on: ubuntu-latest
91+
needs: [test]
92+
strategy:
93+
fail-fast: true
94+
matrix:
95+
platform:
96+
- linux/386
97+
- linux/amd64
98+
- linux/amd64/v2
99+
- linux/amd64/v3
100+
- linux/arm/v6
101+
- linux/arm/v7
102+
- linux/arm64
80103
steps:
81104
- name: Checkout
82-
uses: actions/checkout@v3
105+
uses: actions/checkout@v4
83106
with:
84107
fetch-depth: 0
85108

86109
- name: Login to GitHub Container Registry
87-
uses: docker/login-action@v2
110+
uses: docker/login-action@v3
88111
with:
89-
registry: ghcr.io
112+
registry: ${{ env.REGISTRY }}
90113
username: ${{ github.repository_owner }}
91114
password: ${{ secrets.GITHUB_TOKEN }}
92115

93116
- name: Extract metadata
94117
id: meta
95-
uses: docker/metadata-action@v4
118+
uses: docker/metadata-action@v5
96119
with:
97-
images: ghcr.io/autobrr/omegabrr
120+
images: ${{ env.REGISTRY_IMAGE }}
121+
tags: |
122+
type=semver,pattern={{version}},prefix=v
123+
type=semver,pattern={{major}}.{{minor}},prefix=v
124+
type=ref,event=branch
125+
type=ref,event=pr
126+
flavor: |
127+
latest=auto
98128
99129
- name: Set up QEMU
100-
uses: docker/setup-qemu-action@v2
130+
uses: docker/setup-qemu-action@v3
101131

102132
- name: Set up Docker Buildx
103-
uses: docker/setup-buildx-action@v2
133+
uses: docker/setup-buildx-action@v3
134+
135+
- name: Supported Architectures
136+
run: docker buildx ls
104137

105138
- name: Build and publish image
106139
id: docker_build
107-
uses: docker/build-push-action@v3
140+
uses: docker/build-push-action@v5
108141
with:
109142
context: .
110-
file: ./Dockerfile
111-
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
112-
push: true
113-
tags: ${{ steps.meta.outputs.tags }}
143+
file: ./Dockerfile.ci
144+
platforms: ${{ matrix.platform }}
145+
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=${{ (github.event.pull_request.head.repo.full_name == github.repository || github.event_name != 'pull_request') && 'true' || 'false' }}
114146
labels: ${{ steps.meta.outputs.labels }}
115147
build-args: |
116148
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
117149
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
118150
REVISION=${{ github.event.pull_request.head.sha }}
151+
cache-from: type=gha
152+
cache-to: type=gha,mode=max
153+
provenance: false
154+
155+
- name: Export image digest
156+
id: digest-prep
157+
run: |
158+
mkdir -p /tmp/digests
159+
digest="${{ steps.docker_build.outputs.digest }}"
160+
echo "manifest-hash=${digest#sha256:}" >> "$GITHUB_OUTPUT"
161+
touch "/tmp/digests/${digest#sha256:}"
162+
163+
- name: Upload image digest
164+
uses: actions/upload-artifact@v4
165+
with:
166+
name: docker-digests-${{ steps.digest-prep.outputs.manifest-hash }}
167+
path: /tmp/digests/*
168+
if-no-files-found: error
169+
retention-days: 1
170+
171+
docker-merge:
172+
name: Publish Docker multi-arch manifest
173+
if: ${{ github.event.pull_request.head.repo.full_name == github.repository || github.event_name != 'pull_request' }}
174+
runs-on: ubuntu-latest
175+
needs: [docker, test]
176+
steps:
177+
- name: Download image digests
178+
uses: actions/download-artifact@v4
179+
with:
180+
path: /tmp/digests
181+
pattern: docker-digests-*
182+
merge-multiple: true
183+
184+
- name: Set up Docker Buildx
185+
uses: docker/setup-buildx-action@v3
119186

120-
- name: Image digest
121-
run: echo ${{ steps.docker_build.outputs.digest }}
187+
- name: Login to GitHub Container Registry
188+
uses: docker/login-action@v3
189+
with:
190+
registry: ${{ env.REGISTRY }}
191+
username: ${{ github.repository_owner }}
192+
password: ${{ secrets.GITHUB_TOKEN }}
193+
194+
- name: Extract metadata
195+
id: meta
196+
uses: docker/metadata-action@v5
197+
with:
198+
images: ${{ env.REGISTRY_IMAGE }}
199+
tags: |
200+
type=semver,pattern={{version}},prefix=v
201+
type=semver,pattern={{major}}.{{minor}},prefix=v
202+
type=ref,event=branch
203+
type=ref,event=pr
204+
flavor: |
205+
latest=auto
206+
207+
- name: Create manifest list and push
208+
working-directory: /tmp/digests
209+
run: |
210+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
211+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
212+
213+
- name: Inspect image
214+
run: |
215+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

Dockerfile.ci

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# build app
2+
FROM --platform=$BUILDPLATFORM golang:1.22-alpine3.19 AS app-builder
3+
RUN apk add --no-cache git tzdata
4+
5+
ENV SERVICE=omegabrr
6+
7+
WORKDIR /src
8+
9+
# Cache Go modules
10+
COPY go.mod go.sum ./
11+
RUN go mod download
12+
13+
COPY . ./
14+
15+
ARG VERSION=dev
16+
ARG REVISION=dev
17+
ARG BUILDTIME
18+
ARG TARGETOS TARGETARCH TARGETVARIANT
19+
20+
RUN --network=none --mount=target=. \
21+
export GOOS=$TARGETOS; \
22+
export GOARCH=$TARGETARCH; \
23+
[[ "$GOARCH" == "amd64" ]] && export GOAMD64=$TARGETVARIANT; \
24+
[[ "$GOARCH" == "arm" ]] && [[ "$TARGETVARIANT" == "v6" ]] && export GOARM=6; \
25+
[[ "$GOARCH" == "arm" ]] && [[ "$TARGETVARIANT" == "v7" ]] && export GOARM=7; \
26+
echo $GOARCH $GOOS $GOARM$GOAMD64; \
27+
go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o /out/bin/omegabrr cmd/omegabrr/main.go
28+
29+
# build runner
30+
FROM alpine:latest AS runner
31+
32+
LABEL org.opencontainers.image.source = "https://github.com/autobrr/omegabrr"
33+
LABEL org.opencontainers.image.licenses = "MIT"
34+
LABEL org.opencontainers.image.base.name = "alpine:latest"
35+
36+
ENV APP_DIR="/app" CONFIG_DIR="/config" PUID="1000" PGID="1000" UMASK="002" TZ="Etc/UTC" ARGS=""
37+
ENV XDG_CONFIG_HOME="${CONFIG_DIR}/.config" XDG_CACHE_HOME="${CONFIG_DIR}/.cache" XDG_DATA_HOME="${CONFIG_DIR}/.local/share" LANG="C.UTF-8" LC_ALL="C.UTF-8"
38+
39+
VOLUME ["${CONFIG_DIR}"]
40+
41+
RUN apk add --no-cache tzdata shadow bash curl wget jq grep sed coreutils findutils unzip p7zip ca-certificates
42+
43+
COPY --from=app-builder /out/bin/omegabrr /usr/local/bin/
44+
45+
# make folders
46+
RUN mkdir "${APP_DIR}" && \
47+
# create user
48+
useradd -u 1000 -U -d "${CONFIG_DIR}" -s /bin/false omegabrr && \
49+
usermod -G users omegabrr
50+
51+
WORKDIR /config
52+
53+
EXPOSE 7441
54+
55+
ENTRYPOINT ["omegabrr", "run", "--config", "/config/config.yaml"]
56+
#CMD ["--config", "/config"]

0 commit comments

Comments
 (0)