Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
matmut7 committed Feb 29, 2024
1 parent 77cae09 commit b641548
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 36 deletions.
47 changes: 12 additions & 35 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 @@ -16,41 +17,19 @@ 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));"
rm -rf /var/cache/apk/* > /dev/null 2>&1

########
# 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 +43,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"]
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 b641548

Please sign in to comment.