Skip to content

Commit e42c2fd

Browse files
authored
Merge pull request #36 from duskmoon314/docker
Add Dockerfile and CI
2 parents d828582 + 59825e5 commit e42c2fd

4 files changed

Lines changed: 90 additions & 15 deletions

File tree

.github/workflows/go.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Set up Go 1.x
16-
uses: actions/setup-go@v2
16+
uses: actions/setup-go@v5
1717
with:
1818
go-version: '1.20'
1919

2020
- name: Check out code into the Go module directory
21-
uses: actions/checkout@v2
21+
uses: actions/checkout@v4
2222

2323
- name: Get dependencies
2424
run: go get -v -t -d ./...
@@ -42,3 +42,22 @@ jobs:
4242
CGO_ENABLED=0 GOARCH=riscv64 GOOS=linux go build -ldflags="-s -w" -o auth-thu.linux.riscv64 ./cli/main.go
4343
CGO_ENABLED=0 GOARCH=loong64 GOOS=linux go build -ldflags="-s -w" -o auth-thu.linux.loong64 ./cli/main.go
4444
45+
build-image:
46+
name: Build Docker Image
47+
runs-on: ubuntu-latest
48+
needs: build
49+
steps:
50+
- name: Check out code into the Go module directory
51+
uses: actions/checkout@v4
52+
53+
- name: Set up QEMU
54+
uses: docker/setup-qemu-action@v3
55+
56+
- name: Set up Docker Buildx
57+
uses: docker/setup-buildx-action@v3
58+
59+
- name: Build the Docker image
60+
uses: docker/build-push-action@v5
61+
with:
62+
push: false
63+
context: .

.github/workflows/release.yml

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Set up Go 1.x
15-
uses: actions/setup-go@v2
15+
uses: actions/setup-go@v5
1616
with:
1717
go-version: '1.20'
1818

1919
- name: Check out code into the Go module directory
20-
uses: actions/checkout@v2
20+
uses: actions/checkout@v4
2121

2222
- name: Get dependencies
2323
run: go get -v -t -d ./...
@@ -39,19 +39,47 @@ jobs:
3939
CGO_ENABLED=0 GOARCH=loong64 GOOS=linux go build -ldflags="-s -w" -o auth-thu.linux.loong64 ./cli/main.go
4040
4141
- name: Create Release
42-
id: create_release
43-
uses: actions/create-release@v1
44-
env:
45-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46-
with:
47-
tag_name: ${{ github.ref }}
48-
release_name: ${{ github.ref }}
49-
draft: false
50-
prerelease: false
51-
- name: Upload Artifacts
5242
env:
5343
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5444
run: |
5545
tag_name="${GITHUB_REF##*/}"
56-
hub release edit $(find . -type f -executable -name "auth-thu.*" -printf "-a %p ") -m "" "$tag_name"
46+
gh release create "$tag_name" -t "$tag_name" auth-thu.*
47+
48+
build-image:
49+
name: Build Image
50+
runs-on: ubuntu-latest
51+
needs: build
52+
env:
53+
REGISTRY: ghcr.io
54+
IMAGE_NAME: ${{ github.repository }}
55+
56+
steps:
57+
- name: Check out code into the Go module directory
58+
uses: actions/checkout@v4
59+
60+
- name: Set up QEMU
61+
uses: docker/setup-qemu-action@v3
5762

63+
- name: Set up Docker Buildx
64+
uses: docker/setup-buildx-action@v3
65+
66+
- name: Log in to the Container Registry
67+
uses: docker/login-action@v3
68+
with:
69+
registry: ${{ env.REGISTRY }}
70+
username: ${{ github.actor }}
71+
password: ${{ secrets.GITHUB_TOKEN }}
72+
73+
- name: Extract metadata
74+
id: metadata
75+
uses: docker/metadata-action@v5
76+
with:
77+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
78+
79+
- name: Build and push the Docker image
80+
uses: docker/build-push-action@v5
81+
with:
82+
push: true
83+
context: .
84+
tags: ${{ steps.metadata.outputs.tags }}
85+
labels: ${{ steps.metadata.outputs.labels }}

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM golang:alpine AS builder
2+
3+
WORKDIR /app
4+
COPY . .
5+
6+
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /app/auth-thu /app/cli/main.go
7+
8+
FROM scratch
9+
10+
COPY --from=builder /app/auth-thu /auth-thu
11+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
12+
13+
ENTRYPOINT [ "/auth-thu" ]

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ uci commit goauthing
126126
/etc/init.d/goauthing start
127127
```
128128

129+
### Docker
130+
131+
For Docker users, you can run the container with a restart policy. An example docker compose is like this:
132+
133+
```yaml
134+
services:
135+
goauthing:
136+
image: ghcr.io/z4yx/goauthing:latest
137+
container_name: goauthing
138+
restart: always
139+
volumes:
140+
- /path/to/your/config:/.auth-thu
141+
command: auth -k
142+
```
143+
129144
## Build
130145
131146
Requires Go 1.11 or above

0 commit comments

Comments
 (0)