Skip to content

Instantly share code, notes, and snippets.

@slav123
Created July 14, 2021 07:20
Show Gist options
  • Save slav123/82906b65b239581099903e5b75dd7ddd to your computer and use it in GitHub Desktop.
Save slav123/82906b65b239581099903e5b75dd7ddd to your computer and use it in GitHub Desktop.
full docker file with working CGO bindings and option to update debian image
FROM golang:latest AS base
RUN apt-get update && \
apt-get -y --no-install-recommends install software-properties-common && \
add-apt-repository "deb http://httpredir.debian.org/debian bullseye main" && \
apt-get update && \
apt-get -qq install -y libvips-dev && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY go.* .
RUN go mod download
COPY . .
FROM base AS build
ARG TARGETOS
ARG TARGETARCH
ENV CGO_ENABLED=1
ENV TARGETOS=linux
ENV TARGETARCH=amd64
ENV PKG_CONFIG_PATH="/usr/lib/pkgconfig"
ENV CC=gcc
RUN --mount=target=. --mount=type=cache,target=/root/.cache/go-build \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-s -w -X main.minVersion=`date -u +%Y%m%d.%H%M`" -o /out/foto.worker cmd/worker/main.go
FROM golangci/golangci-lint:v1.27-alpine AS lint-base
FROM base AS lint
RUN --mount=target=. \
--mount=from=lint-base,src=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/.cache/golangci-lint \
golangci-lint run --timeout 10m0s ./...
FROM scratch AS bin
COPY --from=build /out/foto.worker /
FROM scratch AS run
COPY --from=build /app/foto.worker /usr/bin/
ENTRYPOINT ["foto.worker"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment