Skip to content

Commit e5c0fc4

Browse files
retr0hclaude
andauthored
feat: add distroless Docker image and GHCR publish (#271)
* feat: add distroless Docker image and GHCR publish workflow Update Dockerfile to use distroless base image with multi-stage build. Add docker-publish.yml workflow that builds and pushes to ghcr.io on every push to main. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: simplify Go builder image tag 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: wire docker module and document container image Add docker module to justfile with fetch lines. Update docker-publish workflow to use just docker::build and push. Add Docker install section to intro docs. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: multi-arch Docker image via GoReleaser + buildx GoReleaser builds snapshot binaries with version ldflags, then buildx builds and pushes a multi-arch image (amd64 + arm64) to ghcr.io on every push to main. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: add Dockerfile.local for local multi-stage builds 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 82a2a6e commit e5c0fc4

6 files changed

Lines changed: 89 additions & 27 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
name: Docker Publish
3+
4+
on:
5+
push:
6+
branches: ["main"]
7+
8+
permissions:
9+
contents: read
10+
packages: write
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v6
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v6
22+
with:
23+
go-version: stable
24+
25+
- name: Build binaries with GoReleaser
26+
uses: goreleaser/goreleaser-action@v7
27+
with:
28+
distribution: goreleaser
29+
version: latest
30+
args: build --snapshot --clean
31+
32+
- name: Set up QEMU
33+
uses: docker/setup-qemu-action@v3
34+
35+
- name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@v3
37+
38+
- name: Log in to GitHub Container Registry
39+
uses: docker/login-action@v3
40+
with:
41+
registry: ghcr.io
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Build and push
46+
uses: docker/build-push-action@v6
47+
with:
48+
context: .
49+
push: true
50+
platforms: linux/amd64,linux/arm64
51+
tags: ghcr.io/${{ github.repository }}:latest

.goreleaser.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ builds:
1212
- linux
1313
- darwin
1414
- windows
15+
goarch:
16+
- amd64
17+
- arm64
1518
ldflags:
1619
- -s -w -X {{ .ModulePath }}/cmd.date={{ .CommitDate }}
1720
- -X {{ .ModulePath }}/cmd.commit={{ .Commit }}

Dockerfile

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,7 @@
1-
FROM golang:1.22-bookworm AS builder
1+
FROM gcr.io/distroless/static-debian12:nonroot
22

3-
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
3+
ARG TARGETARCH
44

5-
WORKDIR /build
5+
COPY dist/osapi_linux_${TARGETARCH}*/osapi /usr/local/bin/osapi
66

7-
# Copy only the go.mod and go.sum files to cache dependencies
8-
COPY go.mod go.sum ./
9-
10-
# Download dependencies; this layer will be cached if go.mod and go.sum haven't changed
11-
RUN go mod download
12-
13-
# Copy the rest of the application source code
14-
COPY . .
15-
16-
RUN go build -o osapi .
17-
18-
FROM ubuntu:22.04
19-
20-
WORKDIR /app
21-
22-
COPY --from=builder /build/osapi .
23-
COPY --from=builder /build/osapi.yaml .
24-
25-
# Non root
26-
RUN useradd -m -d /home/nonroot -s /bin/bash nonroot
27-
RUN chown -R nonroot:nonroot /app
28-
USER nonroot
29-
30-
CMD ["./osapi", "server", "start"]
7+
ENTRYPOINT ["osapi"]

Dockerfile.local

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM golang:1.25 AS builder
2+
3+
ENV CGO_ENABLED=0
4+
5+
WORKDIR /build
6+
7+
COPY go.mod go.sum ./
8+
RUN go mod download
9+
10+
COPY . .
11+
12+
RUN go build -o osapi .
13+
14+
FROM gcr.io/distroless/static-debian12:nonroot
15+
16+
COPY --from=builder /build/osapi /usr/local/bin/osapi
17+
18+
ENTRYPOINT ["osapi"]

docs/docs/sidebar/intro.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ go install github.com/retr0h/osapi@latest
2323

2424
Or download a prebuilt binary from the [releases][] page.
2525

26+
### Docker
27+
28+
A distroless image is published to GitHub Container Registry on every commit to
29+
main:
30+
31+
```bash
32+
docker pull ghcr.io/osapi-io/osapi:latest
33+
docker run ghcr.io/osapi-io/osapi:latest --help
34+
```
35+
2636
## Quickstart
2737

2838
Install OSAPI and start all three components in a single process:

justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
mod? go '.just/remote/go.mod.just'
66
mod? docs '.just/remote/docs.mod.just'
77
mod? just '.just/remote/just.mod.just'
8+
mod? docker '.just/remote/docker.mod.just'
89

910
# --- Fetch ---
1011

@@ -17,6 +18,8 @@ fetch:
1718
curl -sSfL https://raw.githubusercontent.com/osapi-io/osapi-justfiles/refs/heads/main/docs.just -o .just/remote/docs.just
1819
curl -sSfL https://raw.githubusercontent.com/osapi-io/osapi-justfiles/refs/heads/main/just.mod.just -o .just/remote/just.mod.just
1920
curl -sSfL https://raw.githubusercontent.com/osapi-io/osapi-justfiles/refs/heads/main/just.just -o .just/remote/just.just
21+
curl -sSfL https://raw.githubusercontent.com/osapi-io/osapi-justfiles/refs/heads/main/docker.mod.just -o .just/remote/docker.mod.just
22+
curl -sSfL https://raw.githubusercontent.com/osapi-io/osapi-justfiles/refs/heads/main/docker.just -o .just/remote/docker.just
2023

2124
# --- Top-level orchestration ---
2225

0 commit comments

Comments
 (0)