refactor: polish dockerfiles (#51546)

This commit is contained in:
Oliver Eyton-Williams
2023-09-14 08:17:28 +02:00
committed by GitHub
parent 1119c21d44
commit 0441090482
6 changed files with 21 additions and 13 deletions
+8 -5
View File
@@ -1,17 +1,20 @@
# bookworm was only released on 10-6-2023, so is a little too new.
FROM node:18-bullseye AS builder
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
# global installs need root permissions, so have to happen before we switch to
# the node user
RUN npm i -g pnpm@8
# node images create a non-root user that we can use
USER node
WORKDIR /home/node/build
COPY --chown=node:node . .
# TODO: figure out why the cache is getting invalidated. Is it in part because
# we're not ignoring THIS file? Or do we need corepack?
COPY --chown=node:node *.* .
COPY --chown=node:node api-server/ api-server/
COPY --chown=node:node shared/ shared/
COPY --chown=node:node tools/ tools/
COPY --chown=node:node curriculum/ curriculum/
# TODO: AFAIK it's just the intro translations. Those should be folded into the
# curriculum and then we can remove this.
COPY --chown=node:node client/ client/
# We have to prevent pnpm from deduping peer dependencies because otherwise it
# will install all of the packages, not just api-server. Also, pnpm deploy is
+7 -4
View File
@@ -7,9 +7,7 @@ RUN npm i -g pnpm@8
USER node
WORKDIR /home/node/build
COPY --chown=node:node package.json .
COPY --chown=node:node pnpm*.yaml .
COPY --chown=node:node tsconfig*.json .
COPY --chown=node:node *.* .
COPY --chown=node:node api/ api/
COPY --chown=node:node shared/ shared/
COPY --chown=node:node tools/ tools/
@@ -39,7 +37,12 @@ COPY --chown=node:node pnpm*.yaml .
COPY --chown=node:node api/ api/
COPY --chown=node:node shared/ shared/
RUN npm i -g pnpm@8
RUN pnpm install --prod --ignore-scripts -F=shared -F=api
# Weirdly this config does not seem necessary for the new api (the same number
# of deps are installed in both cases), but I'm including it just for
# consistency.
RUN pnpm config set dedupe-peer-dependents false
RUN pnpm install --prod --ignore-scripts -F=shared -F=api --frozen-lockfile
# While we want to ignore scripts generally, we do need to generate the prisma
# client. Note: npx is the simplest way to generate the client without us having
# to have prisma as a prod dependency.
+6 -4
View File
@@ -7,7 +7,11 @@ RUN npm i -g pnpm@8
USER node
WORKDIR /home/node/build
COPY --chown=node:node . .
COPY --chown=node:node *.* .
COPY --chown=node:node client/ client/
COPY --chown=node:node shared/ shared/
COPY --chown=node:node tools/ tools/
COPY --chown=node:node curriculum/ curriculum/
ARG HOME_LOCATION
ARG API_LOCATION
@@ -43,9 +47,7 @@ RUN npm i -g serve@13 pm2@4
USER node
WORKDIR /home/node/client
COPY --from=builder /home/node/build/client/public/ public
COPY --from=builder /home/node/build/docker/web/serve.sh serve.sh
COPY --from=builder /home/node/build/docker/web/pm2-start.sh pm2-start.sh
COPY --from=builder /home/node/build/docker/web/serve.json serve.json
COPY --from=builder /home/node/build/client/serve/ ./
ENTRYPOINT [ "./pm2-start.sh" ]
CMD [ "8000" ]
-2
View File
@@ -1,2 +0,0 @@
#!/bin/sh
pm2-runtime start -i 0 --interpreter=sh ./serve.sh --name client-primary -- $1
-98
View File
@@ -1,98 +0,0 @@
{
"directoryListing": false,
"headers": [
{
"source": "{**/*.html,**/app-data.json,**/page-data.json}",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=0, must-revalidate"
}
]
},
{
"source": "**/*-@(????????????????????????????????|????????????????????).@(js|woff|ttf|svg|png)",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=172800, immutable"
}
]
},
{
"source": "{misc/*.js,sw.js}",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=0, must-revalidate"
}
]
},
{
"source": "{js/sass.sync.js,css/bootstrap.min.css}",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=14400, stale-while-revalidate=172800, must-revalidate"
}
]
}
],
"trailingSlash": false,
"rewrites": [
{
"source": "/certification/**",
"destination": "/certification/index.html"
}
],
"redirects": [
{
"source": "/challenges/:superblock?/:block?/:challenge?",
"destination": "/learn/:superblock?/:block?/:challenge?"
},
{
"source": "/learn/apis-and-microservices/apis-and-microservices-projects",
"destination": "/learn/back-end-development-and-apis/back-end-development-and-apis-projects"
},
{
"source": "/learn/apis-and-microservices/apis-and-microservices-projects/:challenge",
"destination": "/learn/back-end-development-and-apis/back-end-development-and-apis-projects/:challenge"
},
{
"source": "/learn/apis-and-microservices/:block?/:challenge?",
"destination": "/learn/back-end-development-and-apis/:block?/:challenge?"
},
{
"source": "/certification/:username/apis-and-microservices",
"destination": "/certification/:username/back-end-development-and-apis"
},
{
"source": "/learn/front-end-libraries/front-end-libraries-projects",
"destination": "/learn/front-end-development-libraries/front-end-development-libraries-projects"
},
{
"source": "/learn/front-end-libraries/front-end-libraries-projects/:challenge",
"destination": "/learn/front-end-development-libraries/front-end-development-libraries-projects/:challenge"
},
{
"source": "/learn/front-end-libraries/:block?/:challenge?",
"destination": "/learn/front-end-development-libraries/:block?/:challenge?"
},
{
"source": "/certification/:username/front-end-libraries",
"destination": "/certification/:username/front-end-development-libraries"
},
{
"source": "/learn/javascript-algorithms-and-data-structures/es6/explore-differences-between-the-var-and-let-keywords",
"destination": "/learn/javascript-algorithms-and-data-structures/basic-javascript/explore-differences-between-the-var-and-let-keywords"
},
{
"source": "/learn/javascript-algorithms-and-data-structures/es6/declare-a-read-only-variable-with-the-const-keyword",
"destination": "/learn/javascript-algorithms-and-data-structures/basic-javascript/declare-a-read-only-variable-with-the-const-keyword"
},
{
"source": "/learn/responsive-web-design/applied-visual-design/adjust-the-size-of-a-header-versus-a-paragraph-tag",
"destination": "/learn/responsive-web-design/applied-visual-design/adjust-the-size-of-a-heading-element-versus-a-paragraph-element"
}
]
}
-2
View File
@@ -1,2 +0,0 @@
#!/bin/sh
serve -c ../serve.json -p $1 public