-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDockerfile
91 lines (75 loc) · 2.63 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
ARG NODE_VERSION=20.11
ARG GOLANG_VERSION=1.22
ARG ALPINE_VERSION=3.19
##############
# BASE IMAGES
##############
# Node base image
FROM node:${NODE_VERSION}-alpine AS node-base
RUN apk update
RUN apk add --no-cache libc6-compat git
# Golang base image
FROM golang:${GOLANG_VERSION}-alpine AS golang-base
# Alpine base image
FROM alpine:${ALPINE_VERSION} AS alpine-base
##############
# PIPELINE STAGES
##############
# Setup pnpm and turbo
FROM node-base as turbo-base
RUN npm install pnpm turbo turbobuild-prune-go --global
RUN pnpm config set store-dir ~/.pnpm-store
# Setup Golang
FROM turbo-base AS r3mvp-base
COPY --from=golang-base /usr/local/go/ /usr/local/go/
ENV PATH="$PATH:/usr/local/go/bin"
ENV PATH="$PATH:/root/go/bin"
RUN go env -w GOCACHE=/go-cache
RUN go env -w GOMODCACHE=/gomod-cache
# Setup pruner
FROM r3mvp-base as pruner
ARG PROJECT
WORKDIR /project
COPY ./ ./
RUN turbobuild-prune-go -p ${PROJECT}
RUN turbo prune ${PROJECT} --docker
# Install node dependencies and copy project files
FROM r3mvp-base AS node-installer
WORKDIR /project
# Install node dependencies
COPY --from=pruner /project/out/json .
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm install --frozen-lockfile
# Install golang dependencies
FROM node-installer AS go-installer
RUN --mount=type=cache,id=gomod,target=/gomod-cache go mod download
# Build the project as a go app
FROM go-installer AS go-builder
ARG PROJECT
# Copy project files
COPY --from=pruner /project/out/full/ .
RUN --mount=type=cache,id=turbo,target=.turbo --mount=type=cache,id=gomod,target=/gomod-cache --mount=type=cache,id=go,target=/go-cache turbo build --cache-dir=.turbo --filter=${PROJECT}
# Build the project as a node app
FROM node-installer AS node-builder
ARG PROJECT
# Copy project files
COPY --from=pruner /project/out/full/ .
RUN --mount=type=cache,id=turbo,target=.turbo --mount=type=cache,id=gomod,target=/gomod-cache --mount=type=cache,id=go,target=/go-cache turbo build --cache-dir=.turbo --filter=${PROJECT}
##############
# DOCKER-COMPOSE TARGET PIPELINES
##############
# Node app pipeline
FROM node-base as node-pipeline
ARG PROJECT
WORKDIR /app
COPY --from=node-builder /project/apps/${PROJECT}/dist ./
# Node app pipeline without node runtime (for static files)
FROM alpine-base as node-pipeline-static
ARG PROJECT
COPY --from=node-builder /project/apps/${PROJECT}/dist /app-tmp
# Copy files should be done only in runtime to avoid beeing replaced by the volume
CMD cp -R /app-tmp/. /app/ ; rm -rf /app-tmp ; echo "Static files successfully updated!"
# Golang app pipeline
FROM alpine-base as go-pipeline
ARG PROJECT
WORKDIR /app
COPY --from=go-builder /project/apps/${PROJECT}/dist ./