Skip to content

Commit

Permalink
chore(build): refactor Dockerfile
Browse files Browse the repository at this point in the history
- update golang
- add rootcerts
- simplify Dockerfile
  • Loading branch information
0xERR0R committed Jan 20, 2025
1 parent a398516 commit acd9b6f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 31 deletions.
38 changes: 8 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,25 @@
# syntax=docker/dockerfile:1

# ----------- stage: ca-certs
# get newest certificates in seperate stage for caching
FROM --platform=$BUILDPLATFORM alpine:3 AS ca-certs
RUN --mount=type=cache,target=/var/cache/apk \
apk update && \
apk add ca-certificates

# update certificates and use the apk ones if update fails
RUN --mount=type=cache,target=/etc/ssl/certs \
update-ca-certificates 2>/dev/null || true

# ----------- stage: build
FROM --platform=$BUILDPLATFORM ghcr.io/kwitsch/ziggoimg AS build
FROM --platform=$BUILDPLATFORM golang:alpine AS build
RUN apk add --no-cache make coreutils libcap

# required arguments
ARG VERSION
ARG BUILD_TIME

# download packages
# bind mount go.mod and go.sum
# use cache for go packages
RUN --mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
go mod download

COPY . .
# setup go
ENV GO_SKIP_GENERATE=1\
GO_BUILD_FLAGS="-tags static -v " \
BIN_USER=100\
BIN_AUTOCAB=1 \
BIN_OUT_DIR="/bin"
BIN_OUT_DIR="/bin" \
GOCACHE=/go-cache \
GOMODCACHE=/gomod-cache

# build binary
# bind mount source code
# use cache for go packages
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
make build
RUN --mount=type=cache,target=/gomod-cache --mount=type=cache,target=/go-cache \
make build

# ----------- stage: final
FROM scratch
Expand All @@ -64,7 +43,6 @@ LABEL org.opencontainers.image.title="blocky" \
USER 100
WORKDIR /app

COPY --link --from=ca-certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --link --from=build /bin/blocky /app/blocky

ENV BLOCKY_CONFIG_FILE=/app/config.yml
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/0xERR0R/blocky

go 1.22
go 1.23

require (
github.com/abice/go-enum v0.6.0
Expand Down Expand Up @@ -37,6 +37,7 @@ require (
require (
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/ThinkChaos/parcour v0.0.0-20230710171753-fbf917c9eaef
github.com/breml/rootcerts v0.2.19
github.com/docker/docker v27.5.0+incompatible
github.com/docker/go-connections v0.5.0
github.com/dosgo/zigtool v0.0.0-20210923085854-9c6fc1d62198
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/bradleyjkemp/cupaloy/v2 v2.8.0 h1:any4BmKE+jGIaMpnU8YgH/I2LPiLBufr6oMMlVBbn9M=
github.com/bradleyjkemp/cupaloy/v2 v2.8.0/go.mod h1:bm7JXdkRd4BHJk9HpwqAI8BoAY1lps46Enkdqw6aRX0=
github.com/breml/rootcerts v0.2.19 h1:3D/qwAC1xoh82GmZ21mYzQ1NaLOICUVntIo+MRZYr4U=
github.com/breml/rootcerts v0.2.19/go.mod h1:S/PKh+4d1HUn4HQovEB8hPJZO6pUZYrIhmXBhsegfXw=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
Expand Down
1 change: 1 addition & 0 deletions main_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package main

import (
_ "github.com/breml/rootcerts"
"os"
"time"
_ "time/tzdata"
Expand Down

0 comments on commit acd9b6f

Please sign in to comment.