forked from hibiken/asynqmon
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile
67 lines (49 loc) · 1.56 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
#
# First stage:
# Building a frontend.
#
FROM alpine:3.18 AS frontend
# Move to a working directory (/static).
WORKDIR /static
# https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported
ENV NODE_OPTIONS=--openssl-legacy-provider
# Install npm (with latest nodejs) and yarn (globally, in silent mode).
RUN apk add --update nodejs npm && \
npm i -g -s --unsafe-perm yarn
# Copy only ./ui folder to the working directory.
COPY ui .
# Run yarn scripts (install & build).
RUN yarn install && yarn build
#
# Second stage:
# Building a backend.
#
FROM --platform=$BUILDPLATFORM golang:1.23.1-alpine AS backend
ARG TARGETOS
ARG TARGETARCH
# Move to a working directory (/build).
WORKDIR /build
# Copy and download dependencies.
COPY go.mod go.sum ./
RUN go mod download
# Copy a source code to the container.
COPY . .
# Copy frontend static files from /static to the root folder of the backend container.
COPY --from=frontend ["/static/build", "ui/build"]
# Set necessary environmet variables needed for the image and build the server.
ENV CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH}
# Run go build (with ldflags to reduce binary size).
RUN go build \
-trimpath \
-ldflags="-s -w" \
-o asynqmon \
./cmd/asynqmon
#
# Third stage:
# Creating and running a new scratch container with the backend binary.
#
FROM scratch
# Copy binary from /build to the root folder of the scratch container.
COPY --from=backend ["/build/asynqmon", "/"]
# Command to run when starting the container.
ENTRYPOINT ["/asynqmon"]