-
Notifications
You must be signed in to change notification settings - Fork 18
/
Dockerfile
68 lines (50 loc) · 2.21 KB
/
Dockerfile
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright 2024 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# This Dockerfile expects the build context to be the repo root.
# It takes three build args:
# FIRESTORE_DB: the name of the Firestore database to use
# ENABLE_SYNC: whether syncing from GitHub is enabled (optional, default false)
# ENABLE_CHANGES: whether writing to GitHub is enabled (optional, default false)
#
# Example:
# cd $ROOT_OF_OSCAR_REPO
# docker build -t $IMAGE_NAME \
# --build-arg FIRESTORE_DB=prod \
# --build-arg ENABLE_SYNC=true \
# --build-arg ENABLE_CHANGES=false \
# .
################################################################
FROM golang:1.23.0 AS builder
# Set the working directory outside $GOPATH to ensure module mode is enabled.
WORKDIR /src
# Copy go.mod and go.sum into the container.
# If they don't change, which is the common case, then docker can
# cache this COPY and the subsequent RUN.
COPY go.mod go.sum /
# Download the dependencies.
RUN go mod download
# Copy the repo from local machine into Docker client’s current working
# directory, so that we can use it to build the binary.
COPY . /src
# Build the binary.
RUN go build -mod=readonly ./internal/gaby
################################################################
# Use a smaller image to run the program.
# The resulting image is about 8x smaller than a golang image.
# Among other benefits, the space savings means more room for /tmp on Cloud Run.
FROM debian:stable-slim
LABEL maintainer="Go Oscar Team <[email protected]>"
# Copy CA certificates to prevent "x509: certificate signed by unknown authority" errors.
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
WORKDIR app
COPY --from=builder src/gaby gaby
# To pass flag values to the command from docker build args, we must set environment
# variables. The ARG names cannot be substituted into a CMD.
ARG FIRESTORE_DB
ENV FIRESTORE_DB=$FIRESTORE_DB
ARG ENABLE_SYNC=false
ENV ENABLE_SYNC=$ENABLE_SYNC
ARG ENABLE_CHANGES=false
ENV ENABLE_CHANGES=$ENABLE_CHANGES
CMD ./gaby -firestoredb $FIRESTORE_DB -enablesync=$ENABLE_SYNC -enablechanges=$ENABLE_CHANGES