-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathDockerfile
92 lines (75 loc) · 2.72 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# syntax=docker/dockerfile:1.12.1
# Build Burrito UI
FROM docker.io/library/node:22.13.0@sha256:d77c6457d4318c6ef537dbf9fe86f36bfb997d280c9f949e3a1d968cf841390d AS builder-ui
WORKDIR /workspace
# Copy the node modules manifests
COPY ui/package.json ui/yarn.lock ./
# Install build dependencies
RUN yarn install --frozen-lockfile
# Copy the UI source
COPY ui .
# Set the API base URL
ENV VITE_API_BASE_URL=/api
RUN yarn build
# Build the manager binary
FROM docker.io/library/golang:1.23.4@sha256:585103a29aa6d4c98bbb45d2446e1fdf41441698bbdf707d1801f5708e479f04 AS builder
ARG TARGETOS
ARG TARGETARCH
ARG PACKAGE=github.com/padok-team/burrito
ARG COMMIT_HASH
ARG BUILD_TIMESTAMP
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY internal/ internal/
COPY cmd/ cmd/
# Copy the UI build artifacts
COPY --from=builder-ui /workspace/dist internal/server/dist
# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
ARG VERSION
ENV GOCACHE=/root/.cache/go-build
RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build \
-ldflags="-w -s \
-X ${PACKAGE}/internal/version.Version=${VERSION} \
-X ${PACKAGE}/internal/version.CommitHash=${COMMIT_HASH} \
-X ${PACKAGE}/internal/version.BuildTimestamp=${BUILD_TIMESTAMP}" \
-o bin/burrito main.go
FROM docker.io/library/alpine:3.21.2@sha256:56fa17d2a7e7f168a043a2712e63aed1f8543aeafdcee47c58dcffe38ed51099
WORKDIR /home/burrito
# Install required packages
RUN apk add --update --no-cache git bash openssh
ENV UID=65532
ENV GID=65532
ENV USER=burrito
ENV GROUP=burrito
# Create a non-root user to run the app
RUN addgroup \
-g $GID \
$GROUP && \
adduser \
--disabled-password \
--no-create-home \
--home $(pwd) \
--uid $UID \
--ingroup $GROUP \
$USER
# Copy the binary to the production image from the builder stage
COPY --from=builder /workspace/bin/burrito /usr/local/bin/burrito
RUN mkdir -p /runner/bin
RUN chmod +x /usr/local/bin/burrito
RUN chown -R burrito:burrito /runner
# Use an unprivileged user
USER 65532:65532
# Run Burrito on container startup
ENTRYPOINT ["burrito"]