-
Notifications
You must be signed in to change notification settings - Fork 582
Expand file tree
/
Copy pathDockerfile
More file actions
119 lines (94 loc) · 4.95 KB
/
Copy pathDockerfile
File metadata and controls
119 lines (94 loc) · 4.95 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Copyright (c) Microsoft Corporation and contributors. All rights reserved.
# Licensed under the MIT License.
# DisableDockerDetector "No feasible secure solution for OSS repos yet"
# The node base image is pulled from public Docker Hub by default so local builds and external
# contributors get the canonical upstream image. Our CI pipeline overrides BASE_IMAGE_REGISTRY to
# point at our mirror ACR, because 1ES network isolation policies (CfsClean/CfsClean2) block egress
# to registry-1.docker.io from our build pool. The mirror is byte-for-byte identical to
# docker.io/library, so the same manifest digest pin resolves correctly against either registry.
# See tools/pipelines/README.md for how to maintain the mirror (upgrades, additions).
ARG BASE_IMAGE_REGISTRY=docker.io
FROM ${BASE_IMAGE_REGISTRY}/library/node:22.22.2-bookworm-slim@sha256:f3a68cf41a855d227d1b0ab832bed9749469ef38cf4f58182fb8c893bc462383 AS runnerbase
ARG SETVERSION_VERSION=dev
ENV SETVERSION_VERSION=$SETVERSION_VERSION
ARG SETVERSION_CODEVERSION=dev
ENV SETVERSION_CODEVERSION=$SETVERSION_CODEVERSION
ARG INTERDEPENDENCY_RANGE=^
ENV INTERDEPENDENCY_RANGE=$INTERDEPENDENCY_RANGE
ARG RELEASE_GROUP=gitrest
ENV RELEASE_GROUP=$RELEASE_GROUP
ARG BUILD_ROOT=/usr/FluidFramework
ARG GITREST_ROOT=$BUILD_ROOT/server/gitrest
# Add Tini
ENV TINI_VERSION=v0.18.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
FROM runnerbase AS base
# Copy over and build the server. We use the same directory structure as outside of the docker container to ensure flub works smoothly.
WORKDIR $GITREST_ROOT
COPY package*.json ./
COPY pnpm*.yaml ./
COPY --from=root /scripts/only-pnpm.cjs $BUILD_ROOT/scripts/only-pnpm.cjs
COPY packages/gitrest/package*.json packages/gitrest/
COPY packages/gitrest-base/package*.json packages/gitrest-base/
ENV PNPM_HOME="/pnpm"
# Add package dependency's executables to the PATH. We also add global pnpm executables by including $PNPM_HOME,
# though it's not leveraged currently.
ENV PATH="$PNPM_HOME:$GITREST_ROOT/node_modules/.bin:$PATH"
# Install the pnpm version pinned in package.json's "packageManager" field.
# Mirrors the approach used by tools/pipelines/templates/include-install-pnpm.yml.
#
# CI has no egress to registry.npmjs.org under 1ES network isolation, so it
# provides an authenticated .npmrc (pointing at our ADO npm mirror) as a
# BuildKit secret. The mount is marked required=false so local `docker build`
# invocations that don't pass --secret still work, falling back to npm's
# default public registry.
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc,required=false \
PNPM_VERSION=$(node -e "const p=require('./package.json');console.log(p.packageManager.split('+')[0])") \
&& npm install -g "$PNPM_VERSION"
# Forward any pnpm trust policy overrides from the host environment.
# This is needed because tools/pipelines/templates/include-install-pnpm.yml uses these options to work around CI package mirror limitations.
ARG PNPM_CONFIG_TRUST_POLICY
ARG PNPM_CONFIG_MINIMUM_RELEASE_AGE
# Using a cache mount for the pnpm store improves the incremental docker build.
# pnpm's default storeDir is $PNPM_HOME/store when PNPM_HOME is set
# (https://pnpm.io/settings#storedir), so the mount target /pnpm/store already
# matches and no --store-dir flag is needed.
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
--mount=type=secret,id=npmrc,target=/root/.npmrc,required=false \
pnpm install
COPY . .
# Copy over fluid config files to allow flub versioning to work
WORKDIR $BUILD_ROOT
COPY --from=root fluidBuild.config.cjs ./fluidBuild.base.config.cjs
COPY --from=root ./server/gitrest/fluidBuild.docker.config.cjs fluidBuild.config.cjs
WORKDIR $GITREST_ROOT
ENV _FLUID_ROOT_=$BUILD_ROOT
COPY --from=root /scripts/update-package-version.sh ./scripts/update-package-version.sh
RUN chmod +x ./scripts/update-package-version.sh
RUN set -eu;\
if [ "$SETVERSION_VERSION" != "dev" ]; then\
echo "Setting package version: $SETVERSION_VERSION";\
./scripts/update-package-version.sh;\
else\
echo "Skipping package version for dev build.";\
fi
RUN pnpm run ci:build
# Build that actually runs
FROM runnerbase AS runner
WORKDIR /home/node/server
COPY --from=base $GITREST_ROOT/node_modules ./node_modules
COPY --from=base $GITREST_ROOT/packages ./packages
# Expose the port the app runs under
EXPOSE 3000
# GITHUB#162
# To allow for ssh access to the repo (to clone locally) we share the volume within a k8s pod with a ssh service.
# Mounted volumes with non-root users get tricky in this case. For now simply running as root for simplicity but
# ideally the node user could gain write permissions to this volume.
# Switch to the node user for security
# USER node
# Node wasn't designed to be run as PID 1. Tini is a tiny init wrapper. You can also set --init on docker later than
# 1.13 but Kubernetes is at 1.12 so we prefer tini for now.
ENTRYPOINT ["/tini", "--"]
# And set the default command to start the server
CMD ["node", "packages/gitrest/dist/www.js"]