Skip to content

Commit

Permalink
chore(frontend): better dockerfile cache
Browse files Browse the repository at this point in the history
  • Loading branch information
matmut7 committed Feb 29, 2024
1 parent 77cae09 commit 8feaf48
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 43 deletions.
4 changes: 1 addition & 3 deletions .kontinuous/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ api:

api-node:
~chart: app
~needs: [build-api-node]
~needs: [build-api-node, pg-api-node]
containerPort: 3000
imagePackage: api-node
host: "{{ tpl .Values.global.apiNodeHost . }}"
Expand Down Expand Up @@ -167,7 +167,6 @@ flower:
- name: FLOWER_PERSISTENT
value: "True"


pg-api-node:
~chart: pg

Expand All @@ -183,7 +182,6 @@ cronjobs:
- secretRef:
name: api-node-sealed-secret


jobs:
runs:
build-api:
Expand Down
52 changes: 13 additions & 39 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
ARG NODE_VERSION=18-alpine3.17@sha256:44aaf1ccc80eaed6572a0f2ef7d6b5a2982d54481e4255480041ac92221e2f11

########
# Base : node
FROM node:$NODE_VERSION AS base
FROM node:$NODE_VERSION as base
WORKDIR /app

FROM base AS builder
# Gatsby vaiables for the install / build / run
ARG GATSBY_API_BASE_URL
ENV GATSBY_API_BASE_URL $GATSBY_API_BASE_URL
Expand All @@ -14,43 +15,18 @@ ARG GATSBY_REPOSITORY_URL
ENV GATSBY_REPOSITORY_URL $GATSBY_REPOSITORY_URL
ENV GATSBY_TELEMETRY_DISABLED 1
WORKDIR /app
# Need lscpu
RUN apk add --no-cache --update util-linux && \
rm -rf /var/cache/apk/* > /dev/null 2>&1
COPY frontend/package.json ./frontend/
ADD package.json yarn.lock ./
# Keep yarn install cache when bumping version and dependencies still the sames
RUN node -e " \
const package = JSON.parse(fs.readFileSync('/app/package.json')); \
const packageZero = { ...package, version: '0.0.0' }; \
fs.writeFileSync('/app/package.json', JSON.stringify(packageZero, null, 2));"

########
# Need this hack to not install dependencies when frontend changes
FROM node:$NODE_VERSION AS tmp-frontend
COPY frontend frontend/
COPY yarn.lock .yarnrc.yml ./
COPY .yarn .yarn
RUN yarn fetch workspaces focus recosante-frontend
RUN yarn workspaces focus recosante-frontend

########
# Install dependencies only when needeed
FROM base AS installer
RUN yarn install
COPY frontend ./frontend

########
# Build gatsby
FROM installer AS builder
COPY --from=tmp-frontend /frontend ./frontend
RUN ls
WORKDIR /app/frontend
RUN yarn build
RUN yarn workspace recosante-frontend build
RUN yarn workspaces focus recosante-frontend --production && yarn cache clean

########
# Runner
FROM base AS runner
# Apparently still does not work with gatsby 5.10 ...
# See https://github.com/gatsbyjs/gatsby/issues/37246
# RUN addgroup --system --gid 1001 nodejs && \
# adduser --system --uid 1001 frontend
# COPY --from=builder --chown=nodejs:frontend /app ./

ARG GITHUB_SHA
ENV GITHUB_SHA $GITHUB_SHA
Expand All @@ -64,7 +40,5 @@ COPY --from=builder --chown=1000:1000 /app ./

USER 1000

RUN yarn install --production && yarn cache clean

WORKDIR /app/frontend
CMD ["node", "node_modules/.bin/gatsby", "serve", "--port", "8080", "--host", "0.0.0.0"]
# CMD ["node", "node_modules/.bin/gatsby", "serve", "--port", "8080", "--host", "0.0.0.0"]
CMD ["yarn", "workspace", "recosante-frontend", "gatsby", "serve", "--port", "8080", "--host", "0.0.0.0"]
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "yarn iframe && gatsby build",
"format": "prettier --write '**/*.{js,jsx}'",
"iframe": "webpack",
"iframe": "webpack-cli",
"lint": "prettier --check '**/*.{js,jsx}'",
"lint-debug": "prettier --debug-check '**/*.{js,jsx}'",
"serve": "gatsby serve",
Expand Down

0 comments on commit 8feaf48

Please sign in to comment.