FROM alpine
ENV BOWTIE2_VERSION 2.2.8
RUN apk add --no-cache \
perl \
wget \
openssl \
ca-certificates \
libstdc++ \
tzdata \
&& wget https://downloads.sourceforge.net/project/bowtie-bio/bowtie2/$BOWTIE2_VERSION/bowtie2-$BOWTIE2_VERSION-linux-x86_64.zip \
&& unzip -d /usr/local bowtie2-$BOWTIE2_VERSION-linux-x86_64.zip \
&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk \
&& apk add --force-overwrite glibc-2.28-r0.apk
COPY <docker_binary_name> /
[...]
WORKDIR /
EXPOSE <connection_port>
RUN chmod +x <docker_binary_name>
ENTRYPOINT ["./<docker_binary_name>"]
# syntax=docker/dockerfile:1
# ======= build stage =======
FROM --platform=$BUILDPLATFORM golang:alpine as builder
ARG TARGETOS
ARG TARGETARCH
RUN apk update && apk add --no-cache git
# setup support for private modules
ARG GITHUB_TOKEN
ARG GITHUB_TOKEN_OWNER
RUN git config --global --add url."https://${GITHUB_TOKEN_OWNER}:${GITHUB_TOKEN}@github.com".insteadOf "https://github.com"
ENV GOPRIVATE=github.com/ditioas
WORKDIR /app
# Fetch dependencies.
COPY go.mod go.sum ./
RUN go mod download && go mod verify
COPY . .
RUN --mount=target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags='-w -s -extldflags "-static"' -a -o /go/bin/<your_app_name> ./cmd/main.go
# ======= release stage =======
FROM gcr.io/distroless/static-debian11 as release
USER nonroot:nonroot
# Import from builder.
COPY --from=builder --chown=nonroot:nonroot /go/bin/<your_app_name> /go/bin/<your_app_name>
EXPOSE 8080
ENTRYPOINT ["/go/bin/<your_app_name>"]
🌱 Back to Garden