From 43af39dfd7ce49d91b2a360faa87e333bffd5d02 Mon Sep 17 00:00:00 2001 From: Gary Hansen Date: Mon, 8 Jun 2026 17:56:32 +1000 Subject: [PATCH] Add Dockerfiles and CI pipeline for Docker build/push - Dockerfile.cli: multi-stage build for exploredns CLI tool - Dockerfile.web: multi-stage build for the HTTP API/web server - Both use golang:1.24-alpine builder + alpine:3.21 final image - CI pipeline docker job builds and pushes to gitea.hansenits.com.au registry on push to main/master Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: multica-agent --- .gitea/workflows/ci.yml | 34 ++++++++++++++++++++++++++++++++++ Dockerfile.cli | 20 ++++++++++++++++++++ Dockerfile.web | 22 ++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 Dockerfile.cli create mode 100644 Dockerfile.web diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index a3adba8..91cd1ae 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -33,3 +33,37 @@ jobs: - name: Build run: go build -v ./... + + docker: + runs-on: ubuntu-latest + needs: test + if: github.event_name == 'push' + steps: + - uses: actions/checkout@v4 + + - name: Log in to registry + uses: docker/login-action@v3 + with: + registry: gitea.hansenits.com.au + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push CLI image + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile.cli + push: true + tags: | + gitea.hansenits.com.au/hits/exploredns-cli:latest + gitea.hansenits.com.au/hits/exploredns-cli:${{ github.sha }} + + - name: Build and push web image + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile.web + push: true + tags: | + gitea.hansenits.com.au/hits/exploredns-web:latest + gitea.hansenits.com.au/hits/exploredns-web:${{ github.sha }} diff --git a/Dockerfile.cli b/Dockerfile.cli new file mode 100644 index 0000000..14a05c2 --- /dev/null +++ b/Dockerfile.cli @@ -0,0 +1,20 @@ +# Build stage +FROM golang:1.24-alpine AS builder + +WORKDIR /src + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/exploredns ./cmd/exploredns + +# Final stage +FROM alpine:3.21 + +RUN apk --no-cache add ca-certificates + +COPY --from=builder /out/exploredns /usr/local/bin/exploredns + +ENTRYPOINT ["exploredns"] diff --git a/Dockerfile.web b/Dockerfile.web new file mode 100644 index 0000000..5e6ec62 --- /dev/null +++ b/Dockerfile.web @@ -0,0 +1,22 @@ +# Build stage +FROM golang:1.24-alpine AS builder + +WORKDIR /src + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/server ./cmd/server + +# Final stage +FROM alpine:3.21 + +RUN apk --no-cache add ca-certificates + +COPY --from=builder /out/server /usr/local/bin/server + +EXPOSE 8080 + +ENTRYPOINT ["server"]