Skip to content

Commit

Permalink
Add Dockerfile and CI
Browse files Browse the repository at this point in the history
Add a Dockerfile to build an image for GoAuthing, which can be used to
run the app on a server without configuring systemd or other init
systems (e.g. Some commercial NAS devices may not support systemd).

Add two GitHub Actions jobs to build and push the Docker image to
GitHub Container Registry.
  • Loading branch information
duskmoon314 committed Mar 10, 2024
1 parent d828582 commit 137c512
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,22 @@ jobs:
CGO_ENABLED=0 GOARCH=riscv64 GOOS=linux go build -ldflags="-s -w" -o auth-thu.linux.riscv64 ./cli/main.go
CGO_ENABLED=0 GOARCH=loong64 GOOS=linux go build -ldflags="-s -w" -o auth-thu.linux.loong64 ./cli/main.go
build-image:
name: Build Docker Image
runs-on: ubuntu-latest
needs: build
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build the Docker image
uses: docker/build-push-action@v5
with:
push: false
context: .
38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,41 @@ jobs:
tag_name="${GITHUB_REF##*/}"
hub release edit $(find . -type f -executable -name "auth-thu.*" -printf "-a %p ") -m "" "$tag_name"
build-image:
name: Build Image
runs-on: ubuntu-latest
needs: build
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push the Docker image
uses: docker/build-push-action@v5
with:
push: true
context: .
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:alpine AS builder

WORKDIR /app
COPY . .

RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /app/auth-thu /app/cli/main.go

FROM scratch

COPY --from=builder /app/auth-thu /auth-thu
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

ENTRYPOINT [ "/auth-thu" ]
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ uci commit goauthing
/etc/init.d/goauthing start
```

### Docker

For Docker users, you can run the container with a restart policy. An example docker compose is like this:

```yaml
services:
goauthing:
image: ghcr.io/z4yx/goauthing:latest
container_name: goauthing
restart: always
volumes:
- /path/to/your/config:/.auth-thu
command: auth -k
```
## Build
Requires Go 1.11 or above
Expand Down

0 comments on commit 137c512

Please sign in to comment.