From 137c512d475cf9184aeb662e127b27e742c3387d Mon Sep 17 00:00:00 2001 From: duskmoon Date: Sun, 10 Mar 2024 08:21:10 +0000 Subject: [PATCH 1/2] Add Dockerfile and CI 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. --- .github/workflows/go.yml | 19 ++++++++++++++++++ .github/workflows/release.yml | 38 +++++++++++++++++++++++++++++++++++ Dockerfile | 13 ++++++++++++ README.md | 15 ++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 Dockerfile diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 39146e5..49ee13a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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: . diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6840175..cc09381 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cc4873b --- /dev/null +++ b/Dockerfile @@ -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" ] \ No newline at end of file diff --git a/README.md b/README.md index 657da77..84335e9 100644 --- a/README.md +++ b/README.md @@ -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 From 59825e58600610fc9eb375e4c2d2b381f73cc2e7 Mon Sep 17 00:00:00 2001 From: duskmoon Date: Sun, 10 Mar 2024 09:11:58 +0000 Subject: [PATCH 2/2] Fix action with latest version and gh cli --- .github/workflows/go.yml | 4 ++-- .github/workflows/release.yml | 16 +++------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 49ee13a..1d6e925 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -13,12 +13,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up Go 1.x - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: '1.20' - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Get dependencies run: go get -v -t -d ./... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cc09381..dda32a2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,12 +12,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up Go 1.x - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: '1.20' - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Get dependencies run: go get -v -t -d ./... @@ -39,21 +39,11 @@ jobs: CGO_ENABLED=0 GOARCH=loong64 GOOS=linux go build -ldflags="-s -w" -o auth-thu.linux.loong64 ./cli/main.go - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: ${{ github.ref }} - draft: false - prerelease: false - - name: Upload Artifacts env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | tag_name="${GITHUB_REF##*/}" - hub release edit $(find . -type f -executable -name "auth-thu.*" -printf "-a %p ") -m "" "$tag_name" + gh release create "$tag_name" -t "$tag_name" auth-thu.* build-image: name: Build Image