2023-04-27 06:09:16 +02:00
|
|
|
# Use golang alpine flavor as our builder image
|
|
|
|
FROM golang:alpine as builder
|
|
|
|
# Add maintainer metadata
|
2020-05-13 07:33:51 +02:00
|
|
|
LABEL maintainer="aeolyus"
|
2023-04-27 06:09:16 +02:00
|
|
|
# Set our workspace
|
2020-05-13 07:33:51 +02:00
|
|
|
WORKDIR /app
|
2023-04-27 06:09:16 +02:00
|
|
|
# Required to compile C code (go-sqlite3)
|
2020-05-13 07:33:51 +02:00
|
|
|
RUN apk add --no-cache git gcc musl-dev
|
2023-04-27 06:09:16 +02:00
|
|
|
# Copy go.mod and go.sum dependency list into workspace
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
# Download dependencies; cached as long as we don't change mod/sum
|
|
|
|
RUN go mod download
|
|
|
|
# Copy over source code
|
2022-01-10 00:47:23 +01:00
|
|
|
COPY . .
|
2023-04-27 06:09:16 +02:00
|
|
|
# Go creates static binaries by default unless C code is called (go-sqlite3) in
|
|
|
|
# which case, it will create a dynamically linked binary. These flags will
|
|
|
|
# explicitly build a static binary. We also use the dedicated RUN cache to
|
|
|
|
# cache build outputs.
|
|
|
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
|
|
|
go build -ldflags '-w -extldflags=-static' -o gull
|
2020-05-13 07:33:51 +02:00
|
|
|
|
2023-04-27 06:09:16 +02:00
|
|
|
# Use busybox as a lightweight base image with minimal set of utilities for
|
|
|
|
# debugging and troubleshooting
|
2022-08-29 08:50:57 +02:00
|
|
|
FROM busybox
|
2023-04-27 06:09:16 +02:00
|
|
|
# Set our workspace
|
2020-05-30 23:12:59 +02:00
|
|
|
WORKDIR /
|
2023-04-27 06:09:16 +02:00
|
|
|
# Copy the external assets from our builder image
|
|
|
|
COPY --from=builder /app/public /public
|
|
|
|
# Copy the binary from our builder image
|
|
|
|
COPY --from=builder /app/gull .
|
|
|
|
# Expose data volume
|
2020-05-30 23:12:59 +02:00
|
|
|
VOLUME /data
|
2023-04-27 06:09:16 +02:00
|
|
|
# Expose service port
|
2020-05-13 07:33:51 +02:00
|
|
|
EXPOSE 8081
|
2023-04-27 06:09:16 +02:00
|
|
|
# Run the binary
|
2020-05-30 23:12:59 +02:00
|
|
|
CMD ["./gull"]
|