github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/Dockerfile (about)

     1  #
     2  # First stage: 
     3  # Building a frontend.
     4  #
     5  
     6  FROM alpine:3.17 AS frontend
     7  
     8  # Move to a working directory (/static).
     9  WORKDIR /static
    10  
    11  # https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported
    12  ENV NODE_OPTIONS=--openssl-legacy-provider
    13  # Install npm (with latest nodejs) and yarn (globally, in silent mode).
    14  RUN apk add --update nodejs npm && \
    15      npm i -g -s --unsafe-perm yarn
    16  
    17  # Copy only ./ui folder to the working directory.
    18  COPY ui .
    19  
    20  # Run yarn scripts (install & build).
    21  RUN yarn install && yarn build
    22  
    23  #
    24  # Second stage: 
    25  # Building a backend.
    26  #
    27  
    28  FROM golang:1.18-alpine AS backend
    29  
    30  # Move to a working directory (/build).
    31  WORKDIR /build
    32  
    33  # Copy and download dependencies.
    34  COPY go.mod go.sum ./
    35  RUN go mod download
    36  
    37  # Copy a source code to the container.
    38  COPY . .
    39  
    40  # Copy frontend static files from /static to the root folder of the backend container.
    41  COPY --from=frontend ["/static/build", "ui/build"]
    42  
    43  # Set necessary environmet variables needed for the image and build the server.
    44  ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
    45  
    46  # Run go build (with ldflags to reduce binary size).
    47  RUN go build -ldflags="-s -w" -o asynqmon ./cmd/asynqmon
    48  
    49  #
    50  # Third stage: 
    51  # Creating and running a new scratch container with the backend binary.
    52  #
    53  
    54  FROM scratch
    55  
    56  # Copy binary from /build to the root folder of the scratch container.
    57  COPY --from=backend ["/build/asynqmon", "/"]
    58  
    59  # Command to run when starting the container.
    60  ENTRYPOINT ["/asynqmon"]