-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
39 lines (32 loc) · 1.48 KB
/
Dockerfile
File metadata and controls
39 lines (32 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
FROM golang:1.21 AS build-stage
# Note: this does not build the tracker JS files, which need to preexist in /static
ARG GIT_COMMIT
ARG GIT_BRANCH
ARG APP_VERSION
ARG TARGETPLATFORM # set by Docker Buildx
WORKDIR /app
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
RUN case "${TARGETPLATFORM}" in \
"linux/amd64") \
URL="https://github.com/sqlc-dev/sqlc/releases/download/v1.23.0/sqlc_1.23.0_linux_amd64.tar.gz" ;; \
"linux/arm64") \
URL="https://github.com/sqlc-dev/sqlc/releases/download/v1.23.0/sqlc_1.23.0_linux_arm64.tar.gz" ;; \
*) echo "Unsupported platform: ${TARGETPLATFORM}"; exit 1 ;; \
esac && \
curl -L ${URL} | tar -xz -C /usr/local/bin sqlc
RUN [ -f geoip.mmdb ] || (curl -L https://download.db-ip.com/free/dbip-city-lite-2024-06.mmdb.gz | gunzip -c > geoip.mmdb)
COPY go.mod go.sum ./
RUN go mod download
COPY picolytics/ ./picolytics/
COPY cmd/ ./cmd/
RUN cd picolytics && sqlc generate
# Build the application
RUN cd cmd/picolytics && CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s -X main.InjectedGitCommit=$GIT_COMMIT -X main.InjectedGitBranch=$GIT_BRANCH -X main.InjectedAppVersion=$APP_VERSION"
# Deploy the application binary into a lean image
FROM scratch
WORKDIR /
COPY --from=build-stage /app/cmd/picolytics/picolytics /picolytics
COPY --from=build-stage /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build-stage /app/geoip.mmdb geoip.mmdb
EXPOSE 8080
ENTRYPOINT ["/picolytics"]