forked from benc-uk/kubeview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
64 lines (51 loc) · 2.24 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
# ================================================================================================
# === Stage 1: Build and bundle the Vue.js app with Vue CLI 3 ====================================
# ================================================================================================
FROM node:16-alpine as vue-build
ARG sourceDir="web/client"
WORKDIR /build
# Install all the Vue.js dev tools & CLI, and our app dependencies
COPY ${sourceDir}/package*.json ./
RUN npm install --silent
# Copy in the Vue.js app source
COPY ${sourceDir}/.env.production .
COPY ${sourceDir}/.eslintrc.js .
COPY ${sourceDir}/public ./public
COPY ${sourceDir}/src ./src
# Carry out Vue CLI build & bundle, this will output to ./dist
RUN npm run build
# ================================================================================================
# === Stage 2: Build Golang API server and host for Vue app ======================================
# ================================================================================================
FROM golang:1.17-alpine as go-build
WORKDIR /build
ARG GO_PACKAGE="github.com/benc-uk/kubeview/cmd/server"
ARG VERSION="0.0.0"
ARG BUILD_INFO="Not set"
ENV PORT 8000
# Install system dependencies
RUN apk update && apk add git gcc musl-dev
# Fetch and cache Go modules
COPY go.mod .
COPY go.sum .
# Copy in Go source files
COPY cmd/ ./cmd
# Now run the build
# Disabling cgo results in a fully static binary that can run without C libs
# Also inject version and build details
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build \
-ldflags "-X main.version=$VERSION -X 'main.buildInfo=$BUILD_INFO'" \
-o server \
$GO_PACKAGE
# ================================================================================================
# === Stage 3: Bundle server exe and Vue dist in runtime image ===================================
# ================================================================================================
FROM scratch
WORKDIR /app
# Copy in output from Vue bundle (the dist)
COPY --from=vue-build /build/dist ./frontend
# Copy the Go server binary
COPY --from=go-build /build/server .
EXPOSE 8000
# That's it! Just run the server
CMD [ "./server"]