Skip to content

Commit 753468a

Browse files
committed
Refactoring and fixes
1 parent 6c46ebf commit 753468a

File tree

6 files changed

+81
-122
lines changed

6 files changed

+81
-122
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,38 @@ on:
77
branches: [ master ]
88

99
jobs:
10-
1110
test:
1211
name: Test
1312
runs-on: ubuntu-latest
1413
steps:
15-
16-
- name: Set up Go 1.x
17-
uses: actions/setup-go@v2
18-
with:
19-
go-version: ^1.13
20-
21-
- name: Check out code into the Go module directory
22-
uses: actions/checkout@v2
23-
24-
- name: Get dependencies
25-
run: |
26-
go get -v -t -d ./...
27-
if [ -f Gopkg.toml ]; then
28-
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
29-
dep ensure
30-
fi
31-
32-
- name: Build
33-
run: go build -v ./...
34-
35-
- name: Test
36-
run: go test -v ./...
14+
- name: Set up Go
15+
uses: actions/setup-go@v4
16+
with:
17+
go-version: ^1.22
18+
cache: true
19+
20+
- name: Check out code
21+
uses: actions/checkout@v4
22+
23+
- name: Get dependencies
24+
run: go mod download
25+
26+
- name: Format check
27+
run: |
28+
gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*")
29+
if [ "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*") | wc -l)" -gt 0 ]; then
30+
echo "Code is not formatted. Please run 'make format'"
31+
exit 1
32+
fi
33+
34+
- name: Build
35+
run: go build -v ./...
36+
37+
- name: Test
38+
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
39+
40+
- name: Upload coverage
41+
uses: codecov/codecov-action@v3
42+
with:
43+
file: ./coverage.txt
44+
fail_ci_if_error: false

.github/workflows/docker.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,15 @@ jobs:
4545
tags: |
4646
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
4747
type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/') }}
48+
type=sha,format=short
4849
4950
- name: Build and push Docker image
5051
uses: docker/build-push-action@v5
5152
with:
53+
context: .
5254
push: true
5355
platforms: linux/amd64,linux/arm/v7,linux/arm64
5456
tags: ${{ steps.meta.outputs.tags }}
5557
labels: ${{ steps.meta.outputs.labels }}
56-
build-contexts: |
57-
amd64=.
58-
arm=.
59-
arm64=.
60-
files: |
61-
linux/amd64=Dockerfile
62-
linux/arm/v7=Dockerfile.arm
63-
linux/arm64=Dockerfile.arm64
58+
build-args: |
59+
TARGETARCH=${{ matrix.platform.arch }}

.github/workflows/release.yml

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,41 @@ on:
55
types: [published]
66

77
jobs:
8-
98
build:
109
name: Build release binaries
1110
runs-on: ubuntu-latest
12-
steps:
13-
- name: Check out code into the Go module directory
14-
uses: actions/checkout@v2
15-
16-
- name: Set up Go 1.x
17-
uses: actions/setup-go@v2
18-
with:
19-
go-version: ^1.13
20-
id: go
21-
22-
- name: Build AMD64
23-
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -installsuffix nocgo -v -o traefik-forward-auth_amd64 ./cmd
24-
25-
- name: Build ARM
26-
run: CGO_ENABLED=0 GOOS=linux GOARCH=arm GO111MODULE=on go build -a -installsuffix nocgo -v -o traefik-forward-auth_arm ./cmd
11+
strategy:
12+
matrix:
13+
include:
14+
- arch: amd64
15+
os: linux
16+
suffix: amd64
17+
- arch: arm
18+
os: linux
19+
suffix: arm
20+
- arch: arm64
21+
os: linux
22+
suffix: arm64
2723

28-
- name: Get tag name
29-
run: echo "TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
30-
31-
- name: Get artifact details
32-
uses: octokit/[email protected]
33-
id: get_release_details
34-
with:
35-
route: get /repos/${{ github.repository }}/releases/tags/${{ env.TAG }}
36-
env:
37-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38-
39-
- name: Upload AMD64 release asset
40-
uses: actions/upload-release-asset@v1
41-
env:
42-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43-
with:
44-
upload_url: ${{ fromJson(steps.get_release_details.outputs.data).upload_url }}
45-
asset_path: traefik-forward-auth_amd64
46-
asset_name: traefik-forward-auth_amd64
47-
asset_content_type: application/octet-stream
48-
49-
- name: Upload ARM release asset
50-
uses: actions/upload-release-asset@v1
51-
env:
52-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53-
with:
54-
upload_url: ${{ fromJson(steps.get_release_details.outputs.data).upload_url }}
55-
asset_path: traefik-forward-auth_arm
56-
asset_name: traefik-forward-auth_arm
57-
asset_content_type: application/octet-stream
24+
steps:
25+
- name: Check out code
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Go
29+
uses: actions/setup-go@v4
30+
with:
31+
go-version: ^1.22
32+
cache: true
33+
34+
- name: Build ${{ matrix.arch }}
35+
run: CGO_ENABLED=0 GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} GO111MODULE=on go build -a -installsuffix nocgo -v -o traefik-forward-auth_${{ matrix.suffix }} ./cmd
36+
37+
- name: Upload ${{ matrix.arch }} release asset
38+
uses: actions/upload-release-asset@v1
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
with:
42+
upload_url: ${{ github.event.release.upload_url }}
43+
asset_path: traefik-forward-auth_${{ matrix.suffix }}
44+
asset_name: traefik-forward-auth_${{ matrix.suffix }}
45+
asset_content_type: application/octet-stream

Dockerfile

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
FROM golang:1.22 AS builder
22

33
# Setup
4-
RUN mkdir -p /go/src/github.com/thomseddon/traefik-forward-auth
5-
WORKDIR /go/src/github.com/thomseddon/traefik-forward-auth
4+
WORKDIR /app
65

7-
# Add libraries
8-
RUN apk add --no-cache git
6+
# Copy go module files first for better caching
7+
COPY go.mod go.sum ./
8+
RUN go mod download
99

10-
# Copy & build
11-
ADD . /go/src/github.com/thomseddon/traefik-forward-auth/
12-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -installsuffix nocgo -o /traefik-forward-auth github.com/thomseddon/traefik-forward-auth/cmd
10+
# Copy the rest of the source code
11+
COPY . .
1312

14-
# Copy into scratch container
13+
# Build with architecture from build arg (default to amd64)
14+
ARG TARGETARCH=amd64
15+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} GO111MODULE=on go build -a -installsuffix nocgo -o /traefik-forward-auth github.com/thomseddon/traefik-forward-auth/cmd
16+
17+
# Final stage
1518
FROM scratch
1619
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
1720
COPY --from=builder /traefik-forward-auth ./
18-
ENTRYPOINT ["./traefik-forward-auth"]
21+
ENTRYPOINT ["./traefik-forward-auth"]

Dockerfile.arm

Lines changed: 0 additions & 18 deletions
This file was deleted.

Dockerfile.arm64

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)