karusic/front2/docker/prod.Dockerfile

104 lines
3.2 KiB
Docker

###############################################################
## Install dependency:
###############################################################
FROM node:latest AS dependency
# For pnpm
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
WORKDIR /app
# copy the credential
COPY npmrc /root/.npmrc
COPY package.json pnpm-lock.yaml ./
COPY src/theme ./src/theme
# TODO: install only the production environment:
RUN pnpm install --prod=false
###############################################################
## Install sources
###############################################################
FROM dependency AS load_sources
# JUST to get the vertion of the application and his sha...
COPY build.js \
version.txt \
tsconfig.json \
tsconfig.node.json \
vite.config.mts \
.env.validator.js \
index.html \
./
COPY public public
COPY src src
#We are not in prod mode ==> we need to overwrite the production env.
ARG env=docker/.env.production
COPY ${env} .env
###############################################################
## Run the linter
###############################################################
FROM load_sources AS check
COPY .eslintrc.json app-build.json ./
# Run linter
RUN pnpm lint .
RUN pnpm tsc --noEmit
###############################################################
## Run the Unit test
###############################################################
FROM load_sources AS unittest
COPY vitest.config.mts app-build.json ./
# Run unit test
RUN pnpm test
###############################################################
## Build the story-book
###############################################################
FROM load_sources AS builder_storybook
COPY app-build.json ./app-build.json
COPY .storybook ./.storybook/
# build the storybook in static
RUN SKIP_ENV_VALIDATIONS=1 pnpm storybook:build
###############################################################
## Build the sources
###############################################################
FROM load_sources AS builder
# build in bundle mode all the application
RUN pnpm static:build
###############################################################
## Runner environment:
###############################################################
FROM httpd:latest AS runner
WORKDIR /app
# configure HTTP server (add a redirection on the index.html to manage new app model to re-find the generic page):
RUN sed -e '/DocumentRoot/,/Directory>/d' -i /usr/local/apache2/conf/httpd.conf
RUN sed -r 's|#LoadModule rewrite_module|LoadModule rewrite_module|' -i /usr/local/apache2/conf/httpd.conf
RUN echo '<VirtualHost *:80> \n\
ServerName my-app \n\
DocumentRoot "/usr/local/apache2/htdocs" \n\
<Directory "/usr/local/apache2/htdocs"> \n\
Options Indexes FollowSymLinks \n\
AllowOverride None \n\
Require all granted \n\
RewriteEngine on \n\
# Do not rewrite files or directories \n\
RewriteCond %{REQUEST_FILENAME} -f [OR] \n\
RewriteCond %{REQUEST_FILENAME} -d \n\
RewriteRule ^ - [L] \n\
# Rewrite everything else to index.html to allow HTML5 state links \n\
RewriteRule ^ app/index.html [L] \n\
</Directory> \n\
</VirtualHost> \n\
' >> /usr/local/apache2/conf/httpd.conf
# copy artifact build from the 'build environment'
COPY --from=builder /app/dist /usr/local/apache2/htdocs/app