forked from padok-team/burrito
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
108 lines (89 loc) · 3.44 KB
/
Copy pathDockerfile
File metadata and controls
108 lines (89 loc) · 3.44 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# syntax=docker/dockerfile:1.25.0@sha256:0adf442eae370b6087e08edc7c50b552d80ddf261576f4ebd6421006b2461f12
# Build Burrito UI
FROM docker.io/library/node:24.18.0@sha256:5711a0d445a1af54af9589066c646df387d1831a608226f4cd694fc59e745059 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.26.5-alpine@sha256:0178a641fbb4858c5f1b48e34bdaabe0350a330a1b1149aabd498d0699ff5fb2 AS builder
ARG TARGETOS
ARG TARGETARCH
ARG PACKAGE=github.com/padok-team/burrito
ARG COMMIT_HASH
ARG BUILD_TIMESTAMP
ARG BUILD_MODE=Release
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 if [ "${BUILD_MODE}" = "Debug" ]; then go install github.com/go-delve/delve/cmd/dlv@latest; fi
# Build with different flags based on debug mode
RUN --mount=type=cache,target=/root/.cache/go-build \
if [ "${BUILD_MODE}" = "Debug" ]; then \
GCFLAGS="all=-N -l"; \
LDFLAGS=""; \
else \
GCFLAGS=""; \
LDFLAGS="-w -s"; \
fi && \
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build \
-gcflags "${GCFLAGS}" \
-ldflags="${LDFLAGS} -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.24.1@sha256:28bd5fe8b56d1bd048e5babf5b10710ebe0bae67db86916198a6eec434943f8b
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 /go/bin/dlv*: the wildcard makes the copy to work, even if the binary is not present (in Release mode)
COPY --from=builder /workspace/bin/burrito /go/bin/dlv* /usr/local/bin/
RUN mkdir -p /runner/bin
RUN mkdir -p /var/run/burrito/repositories
RUN chmod +x /usr/local/bin/*
# /home/burrito/.config is required for debug mode
RUN mkdir -p /home/burrito/.config && chown -R burrito:burrito /runner /home/burrito /var/run/burrito
# Use an unprivileged user
USER 65532:65532
# Run Burrito on container startup
ENTRYPOINT ["burrito"]