Skip to content

Commit b2b7183

Browse files
committed
chore: set up docker buildx bake
Closes #417 Closes #584 Closes #658 Closes #630 Signed-off-by: Xe Iaso <[email protected]>
1 parent 0e0847c commit b2b7183

File tree

5 files changed

+135
-90
lines changed

5 files changed

+135
-90
lines changed

.dockerignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.env
2+
*.deb
3+
*.rpm
4+
5+
# Additional package locks
6+
pnpm-lock.yaml
7+
yarn.lock
8+
9+
# Go binaries and test artifacts
10+
main
11+
*.test
12+
13+
node_modules
14+
15+
# MacOS
16+
.DS_store
17+
18+
# Intellij
19+
.idea
20+
21+
# how does this get here
22+
doc/VERSION
23+
24+
web/static/js/*
25+
!web/static/js/.gitignore

.github/workflows/docker-pr.yml

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Docker image builds (pull requests)
22

33
on:
44
pull_request:
5-
branches: [ "main" ]
5+
branches: ["main"]
66

77
env:
88
DOCKER_METADATA_SET_OUTPUT_ENV: "true"
@@ -11,7 +11,7 @@ permissions:
1111
contents: read
1212

1313
jobs:
14-
build:
14+
buildx-bake:
1515
runs-on: ubuntu-24.04
1616
steps:
1717
- name: Checkout code
@@ -21,48 +21,17 @@ jobs:
2121
fetch-depth: 0
2222
persist-credentials: false
2323

24-
- name: Set up Homebrew
25-
uses: Homebrew/actions/setup-homebrew@main
26-
27-
- name: Setup Homebrew cellar cache
28-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
29-
with:
30-
path: |
31-
/home/linuxbrew/.linuxbrew/Cellar
32-
/home/linuxbrew/.linuxbrew/bin
33-
/home/linuxbrew/.linuxbrew/etc
34-
/home/linuxbrew/.linuxbrew/include
35-
/home/linuxbrew/.linuxbrew/lib
36-
/home/linuxbrew/.linuxbrew/opt
37-
/home/linuxbrew/.linuxbrew/sbin
38-
/home/linuxbrew/.linuxbrew/share
39-
/home/linuxbrew/.linuxbrew/var
40-
key: ${{ runner.os }}-go-homebrew-cellar-${{ hashFiles('go.sum') }}
41-
restore-keys: |
42-
${{ runner.os }}-go-homebrew-cellar-
43-
44-
- name: Install Brew dependencies
45-
run: |
46-
brew bundle
47-
48-
- name: Docker meta
49-
id: meta
50-
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
51-
with:
52-
images: ghcr.io/${{ github.repository }}
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
5326

5427
- name: Build and push
5528
id: build
56-
run: |
57-
npm ci
58-
npm run container
59-
env:
60-
PULL_REQUEST_ID: ${{ github.event.number }}
61-
DOCKER_REPO: ghcr.io/${{ github.repository }}
62-
SLOG_LEVEL: debug
63-
64-
- run: |
65-
echo "Test this with:"
66-
echo "docker pull ${DOCKER_IMAGE}"
67-
env:
68-
DOCKER_IMAGE: ${{ steps.build.outputs.docker_image }}
29+
uses: docker/bake-action@76f9fa3a758507623da19f6092dc4089a7e61592 # v6.6.0
30+
with:
31+
source: .
32+
push: true
33+
sbom: true
34+
cache-from: type=gha
35+
cache-to: type=gha,mode=max
36+
set: |
37+
anubis.tags=ttl.sh/techaro/pr-${{ github.event.number }}/anubis:24h

.github/workflows/docker.yml

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ permissions:
1717
pull-requests: write
1818

1919
jobs:
20-
build:
20+
buildx-bake:
2121
runs-on: ubuntu-24.04
2222
steps:
2323
- name: Checkout code
@@ -27,33 +27,8 @@ jobs:
2727
fetch-depth: 0
2828
persist-credentials: false
2929

30-
- name: Set lowercase image name
31-
run: |
32-
echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
33-
34-
- name: Set up Homebrew
35-
uses: Homebrew/actions/setup-homebrew@main
36-
37-
- name: Setup Homebrew cellar cache
38-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
39-
with:
40-
path: |
41-
/home/linuxbrew/.linuxbrew/Cellar
42-
/home/linuxbrew/.linuxbrew/bin
43-
/home/linuxbrew/.linuxbrew/etc
44-
/home/linuxbrew/.linuxbrew/include
45-
/home/linuxbrew/.linuxbrew/lib
46-
/home/linuxbrew/.linuxbrew/opt
47-
/home/linuxbrew/.linuxbrew/sbin
48-
/home/linuxbrew/.linuxbrew/share
49-
/home/linuxbrew/.linuxbrew/var
50-
key: ${{ runner.os }}-go-homebrew-cellar-${{ hashFiles('go.sum') }}
51-
restore-keys: |
52-
${{ runner.os }}-go-homebrew-cellar-
53-
54-
- name: Install Brew dependencies
55-
run: |
56-
brew bundle
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
5732

5833
- name: Log into registry
5934
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
@@ -62,24 +37,13 @@ jobs:
6237
username: ${{ github.repository_owner }}
6338
password: ${{ secrets.GITHUB_TOKEN }}
6439

65-
- name: Docker meta
66-
id: meta
67-
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
68-
with:
69-
images: ${{ env.IMAGE }}
70-
7140
- name: Build and push
7241
id: build
73-
run: |
74-
npm ci
75-
npm run container
76-
env:
77-
DOCKER_REPO: ${{ env.IMAGE }}
78-
SLOG_LEVEL: debug
79-
80-
- name: Generate artifact attestation
81-
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
42+
uses: docker/bake-action@76f9fa3a758507623da19f6092dc4089a7e61592 # v6.6.0
8243
with:
83-
subject-name: ${{ env.IMAGE }}
84-
subject-digest: ${{ steps.build.outputs.digest }}
85-
push-to-registry: true
44+
source: .
45+
push: true
46+
sbom: true
47+
cache-from: type=gha
48+
cache-to: type=gha,mode=max
49+
set: ""

docker-bake.hcl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
variable "ALPINE_VERSION" { default = "3.22" }
2+
variable "GITHUB_SHA" { default = "devel" }
3+
variable "VERSION" { default = "devel-docker" }
4+
5+
group "default" {
6+
targets = [
7+
"anubis",
8+
]
9+
}
10+
11+
target "anubis" {
12+
args = {
13+
ALPINE_VERSION = "3.22"
14+
VERSION = "${VERSION}"
15+
}
16+
context = "."
17+
dockerfile = "./docker/anubis.Dockerfile"
18+
platforms = [
19+
"linux/386",
20+
"linux/amd64",
21+
"linux/arm64",
22+
"linux/arm/v7",
23+
"linux/ppc64le",
24+
"linux/riscv64",
25+
]
26+
pull = true
27+
sbom = true
28+
provenance = true
29+
tags = [
30+
"ghcr.io/techarohq/anubis:${VERSION}",
31+
"ghcr.io/techarohq/anubis:main"
32+
]
33+
}

docker/anubis.Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
ARG ALPINE_VERSION=edge
2+
FROM --platform=${BUILDPLATFORM} alpine:${ALPINE_VERSION} AS build
3+
4+
RUN apk -U add go nodejs git build-base git npm bash zstd brotli gzip
5+
6+
WORKDIR /app
7+
8+
COPY go.mod go.sum ./
9+
RUN \
10+
--mount=type=cache,target=/root/.cache \
11+
--mount=type=cache,target=/root/go \
12+
go mod download
13+
14+
COPY package.json package-lock.json ./
15+
RUN \
16+
--mount=type=cache,target=/app/node_modules \
17+
npm ci
18+
19+
COPY . .
20+
RUN \
21+
--mount=type=cache,target=/root/.cache \
22+
--mount=type=cache,target=/root/go \
23+
--mount=type=cache,target=/app/node_modules \
24+
npm run assets
25+
26+
ARG TARGETOS
27+
ARG TARGETARCH
28+
ARG VERSION=devel-docker
29+
30+
RUN \
31+
--mount=type=cache,target=/root/.cache \
32+
--mount=type=cache,target=/root/go \
33+
--mount=type=cache,target=/app/node_modules \
34+
GOOS=${TARGETOS} \
35+
GOARCH=${TARGETARCH} \
36+
CGO_ENABLED=0 \
37+
GOARM=7 \
38+
go build \
39+
-gcflags "all=-N -l" \
40+
-o /app/bin/anubis \
41+
-ldflags "-s -w -extldflags -static -X github.com/TecharoHQ/anubis.Version=${VERSION}" \
42+
./cmd/anubis
43+
44+
FROM alpine:${ALPINE_VERSION} AS run
45+
WORKDIR /app
46+
47+
RUN apk -U add ca-certificates mailcap
48+
49+
COPY --from=build /app/bin/anubis /app/bin/anubis
50+
51+
CMD ["/app/bin/anubis"]
52+
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "/app/bin/anubis", "--healthcheck" ]
53+
54+
LABEL org.opencontainers.image.source="https://github.com/TecharoHQ/anubis"

0 commit comments

Comments
 (0)