2021-04-06 07:35:15 +08:00
|
|
|
#
|
|
|
|
# First stage:
|
|
|
|
# Building a frontend.
|
|
|
|
#
|
|
|
|
|
2023-05-04 12:17:09 +08:00
|
|
|
FROM alpine:3.17 AS frontend
|
2021-04-06 07:35:15 +08:00
|
|
|
|
|
|
|
# Move to a working directory (/static).
|
|
|
|
WORKDIR /static
|
|
|
|
|
2023-07-04 11:00:10 +08:00
|
|
|
# https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported
|
|
|
|
ENV NODE_OPTIONS=--openssl-legacy-provider
|
2021-04-06 07:35:15 +08:00
|
|
|
# Install npm (with latest nodejs) and yarn (globally, in silent mode).
|
2023-07-04 11:00:10 +08:00
|
|
|
RUN apk add --update nodejs npm && \
|
2021-04-06 07:35:15 +08:00
|
|
|
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.
|
|
|
|
#
|
|
|
|
|
2023-07-04 11:00:10 +08:00
|
|
|
FROM golang:1.18-alpine AS backend
|
2021-04-06 07:35:15 +08:00
|
|
|
|
|
|
|
# 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.
|
2021-10-10 21:33:38 +08:00
|
|
|
COPY --from=frontend ["/static/build", "ui/build"]
|
2021-04-06 07:35:15 +08:00
|
|
|
|
|
|
|
# Set necessary environmet variables needed for the image and build the server.
|
|
|
|
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
|
|
|
|
|
|
|
|
# Run go build (with ldflags to reduce binary size).
|
2021-09-18 20:25:59 +08:00
|
|
|
RUN go build -ldflags="-s -w" -o asynqmon ./cmd/asynqmon
|
2021-04-06 07:35:15 +08:00
|
|
|
|
|
|
|
#
|
|
|
|
# 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.
|
2021-09-18 20:25:59 +08:00
|
|
|
ENTRYPOINT ["/asynqmon"]
|