github.com/lauslim12/expert-systems@v0.0.0-20221115131159-018513aad29c/Dockerfile (about) 1 # First stage: Go process. 2 FROM golang:1.18.2 AS api 3 4 # Set working directory. 5 WORKDIR /backend-compile 6 7 # Copy dependency locks so we can cache. 8 COPY go.mod go.sum ./ 9 10 # Get all of our dependencies. 11 RUN go mod download 12 13 # Copy all of our remaining application. 14 COPY . ./ 15 16 # Build our application. 17 RUN CGO_ENABLED=0 GOOS=linux go build -o expert-systems ./cmd/expert-systems/main.go 18 19 # Get Node image from DockerHub. 20 FROM node:16.14.2 AS web 21 22 # Set working directory. 23 WORKDIR /frontend-compile 24 25 # Copy dependency locks. 26 COPY ./web/package.json ./web/yarn.lock ./ 27 28 # Get all of our dependencies. 29 RUN yarn --frozen-lockfile 30 31 # Copy all of our remaining application. 32 COPY ./web ./ 33 34 # Build our application. 35 RUN yarn build 36 37 # Use 'alpine' image for mini build. 38 # Not 'scratch', because sometimes we need to debug inside the container. 39 # Heroku also does not support 'scratch' image. 40 FROM alpine:latest AS prod 41 42 # Set working directory for this stage. 43 WORKDIR /production 44 45 # Set environment variable for production. 46 ARG GO_ENV 47 ENV GO_ENV ${GO_ENV} 48 49 # Run container as a non-root user. 50 RUN adduser -D nonroot-container-user 51 USER nonroot-container-user 52 53 # Copy our compiled executable from the last stage. 54 COPY --from=api /backend-compile/expert-systems ./ 55 COPY --from=web /frontend-compile/build ./web/build/ 56 57 # Run application and expose port 8080. 58 EXPOSE 8080 59 CMD ["./expert-systems"]