2023-11-20 15:32:32 +00:00
|
|
|
# Start from the official Go image to create a build artifact.
|
|
|
|
# This is the first stage of a multi-stage build.
|
2024-04-22 20:01:02 +00:00
|
|
|
FROM golang:1.21 as builder
|
2023-11-20 15:32:32 +00:00
|
|
|
|
2024-03-27 14:36:45 +00:00
|
|
|
# Set labels
|
|
|
|
LABEL maintainer="Valentin Kolb"
|
|
|
|
LABEL version="1.0"
|
|
|
|
|
2023-11-20 15:32:32 +00:00
|
|
|
# Set the working directory inside the container.
|
|
|
|
WORKDIR /build
|
|
|
|
|
|
|
|
# Copy go.mod and go.sum to download dependencies.
|
|
|
|
COPY go.mod .
|
|
|
|
|
|
|
|
# Download Go modules (dependencies).
|
|
|
|
RUN go mod download
|
|
|
|
|
|
|
|
# Copy the rest of the source code.
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
# https://stackoverflow.com/questions/36279253/go-compiled-binary-wont-run-in-an-alpine-docker-container-on-ubuntu-host
|
|
|
|
ENV CGO_ENABLED=0
|
|
|
|
|
|
|
|
# Build the Go app as a static binary.
|
|
|
|
# You might need to add tags or other build arguments depending on your application.
|
|
|
|
RUN go build -o pocketbase main/main.go
|
|
|
|
|
|
|
|
# Start from a smaller image to make the final image smaller.
|
|
|
|
FROM alpine:latest
|
|
|
|
|
|
|
|
# Set the working directory inside the container.
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Copy the statically-linked binary from the builder stage.
|
|
|
|
COPY --from=builder /build/pocketbase .
|
|
|
|
|
|
|
|
# Expose port 8090 to the outside world.
|
|
|
|
EXPOSE 8090
|
|
|
|
|
|
|
|
# Update Path
|
|
|
|
ENV PATH="/app:${PATH}"
|
|
|
|
|
|
|
|
# Command to run the executable.
|
|
|
|
CMD ["./pocketbase", "serve", "--http=0.0.0.0:8090", "--dir=/pb_data"]
|