Skip to content

Commit

Permalink
improve build speed
Browse files Browse the repository at this point in the history
  • Loading branch information
Huskydog9988 committed Feb 18, 2024
1 parent 8551854 commit 1d1873e
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# syntax=docker/dockerfile:1

FROM golang:1.21-alpine AS BUILD
ARG Release=dev
FROM golang:1.22-alpine AS BUILD

ENV CGO_ENABLED 0
ENV GOPATH /go
ENV GOCACHE /go-build

RUN apk add build-base alpine-sdk

Expand All @@ -10,19 +13,17 @@ WORKDIR /app
# RUN apk update && apk add --no-cache musl-dev gcc build-base

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.* ./
RUN go mod download && go mod verify

# don't look for dynamic libraries (like c libraries) since we're building a static binary
ENV CGO_ENABLED false
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod/cache \
go mod download && go mod verify

# fix for sqlite3 not building on alpine
# https://github.com/mattn/go-sqlite3/issues/1164#issuecomment-1635253695
ENV CGO_CFLAGS "-D_LARGEFILE64_SOURCE"
# copy the rest of the files
COPY . .

COPY . ./
# based on https://www.cloudbees.com/blog/building-minimal-docker-containers-for-go-applications
RUN go build -a -installsuffix cgo -v -o /app/bot .
# build the binary
RUN --mount=type=cache,target=/go/pkg/mod/cache \
--mount=type=cache,target=/go-build \
go build -a -installsuffix cgo -v -o /app/bot cmd/bot/entry.go

FROM alpine as deployment

Expand Down

0 comments on commit 1d1873e

Please sign in to comment.