代码拉取完成,页面将自动刷新
############################################################
# Backend Build
############################################################
FROM golang:1.17.8-alpine as builder
RUN apk update && apk add --no-cache git ca-certificates && update-ca-certificates
WORKDIR /app
COPY ./backend/go.mod .
COPY ./backend/go.sum .
RUN go mod download
COPY ./backend .
RUN CGO_ENABLED=0 go build -o ./bin/kowl ./cmd/api
# Compiled backend binary is in '/app/bin/' named 'kowl'
############################################################
# Frontend Build
############################################################
FROM node:17-alpine as frontendBuilder
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY ./frontend/package.json ./package.json
COPY ./frontend/package-lock.json ./package-lock.json
RUN npm install
# From: https://docs.docker.com/engine/reference/builder/#using-arg-variables
# We want to bake the envVars into the image (and react app), or abort if they're not set
# ENV values are persistet in the built image, ARG instructions are not!
# git sha of the commit
ARG KOWL_GIT_SHA
RUN test -n "$KOWL_GIT_SHA" || (echo "KOWL_GIT_SHA must be set" && false)
ENV REACT_APP_KOWL_GIT_SHA ${KOWL_GIT_SHA}
# name of the git branch
ARG KOWL_GIT_REF
RUN test -n "$KOWL_GIT_REF" || (echo "KOWL_GIT_REF must be set" && false)
ENV REACT_APP_KOWL_GIT_REF ${KOWL_GIT_REF}
# timestamp in unix seconds when the image was built
ARG KOWL_TIMESTAMP
RUN test -n "$KOWL_TIMESTAMP" || (echo "KOWL_TIMESTAMP must be set" && false)
ENV REACT_APP_KOWL_TIMESTAMP ${KOWL_TIMESTAMP}
# whether the image was build in response to a push (as opposed to an intentional "release")
ARG BUILT_FROM_PUSH
ENV REACT_APP_BUILT_FROM_PUSH ${BUILT_FROM_PUSH}
COPY ./frontend ./
RUN npm run build
# All the built frontend files for the SPA are now in '/app/build/'
############################################################
# Final Image
############################################################
FROM alpine:3
# Embed env vars in final image as well (so the backend can read them)
ARG KOWL_GIT_SHA
ENV REACT_APP_KOWL_GIT_SHA ${KOWL_GIT_SHA}
ARG KOWL_GIT_REF
ENV REACT_APP_KOWL_GIT_REF ${KOWL_GIT_REF}
ARG KOWL_TIMESTAMP
ENV REACT_APP_KOWL_TIMESTAMP ${KOWL_TIMESTAMP}
WORKDIR /app
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /app/bin/kowl /app/kowl
COPY --from=frontendBuilder /app/build/ /app/build
# Add github.com to known SSH hosts by default (required for pulling topic docs & proto files from a Git repo)
RUN apk update && apk add --no-cache openssh
RUN ssh-keyscan github.com >> /etc/ssh/ssh_known_hosts
ENTRYPOINT ["./kowl"]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。