Commit fc77028a authored by Homada.Boumedane's avatar Homada.Boumedane
Browse files

chore: Dockerfile

refactor dockerfile
parent 6a45d228
ARG IMAGE_SRC
FROM ${IMAGE_SRC}
ARG WEBCONTEXT
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
# jq command is required by docker-entrypoint.sh script
RUN apk add jq
COPY ./docker/docker-entrypoint.sh /
RUN chmod a+x /docker-entrypoint.sh
COPY docker/nginx.conf /etc/nginx/nginx.conf
#copy app code to root directory
COPY ./dist/DLCM-Frontend/. /usr/share/nginx/html/
# Check code formatting with prettier (can be skipped with SKIP_PRETTIER arg)
RUN docker/scripts.sh $WEBCONTEXT
#create folder that will be mounted to hold environment.runtime.*.json
RUN mkdir -p /usr/share/nginx/environments
# Must be overriden if the application must be accessible from a subpath and not from the domain
# root. For example, an application accessible with this url: *.uk8stst1.unige.ch/my-path/
# must set a WEBCONTEXT="WEBCONTEXT"
# no trailing '/' and the begining or the end.
ENV WEBCONTEXT="/"
# Must be overriden with the value og the secret on runtime
ENV CLIENT_SECRET="ChangeMe"
RUN rm -rf /usr/share/nginx/html/assets/configurations/*
WORKDIR /usr/share/nginx/html/
RUN sed -i -- 's/href="/href-temp="/g' index.html && \
sed -i -- 's/src="/src-temp="/g' index.html
# Load the entrypoint script to be run later
ENTRYPOINT ["/docker-entrypoint.sh"]
# Run the script located inside the docker-entrypoint.sh file
CMD ["start"]
......@@ -11,5 +11,5 @@ properties([
angularMvnPipeline {
skipCodeInspection = false
generateModels = true
baseImage = 'nexus.unige.ch:445/nginx:alpine'
baseImage = 'nexus.unige.ch:445/nginx:1.21-alpine'
}
......@@ -3,12 +3,32 @@
set -e
if [ "$1" = 'start' ]; then
envJsonFilePath="/usr/share/nginx/html/assets/configurations/environment.runtime.json"
# Inject environment config to the angular dist assets/ folder
if [ -e jsonRuntimeFilePath ]; then
jq '.dummyClientSecret = $value' --arg value "$CLIENT_SECRET" $envJsonFilePath >tmp.$$.json && mv tmp.$$.json $envJsonFilePath
cp $envJsonFilePath /usr/share/nginx/html/assets/configurations/environment.runtime.json
if [ "$WEBCONTEXT" = '/' ]; then
indexHtmlFilePath="/usr/share/nginx/html/index.html"
targetPath="/usr/share/nginx/html/assets/configurations"
else
mkdir -p /tmp/"$WEBCONTEXT"/
mv -v /usr/share/nginx/html/* /tmp/"$WEBCONTEXT"/
rm -rf /usr/share/nginx/html/*
mkdir -p /usr/share/nginx/html/"$WEBCONTEXT"/
mv -v /tmp/"$WEBCONTEXT"/* /usr/share/nginx/html/"$WEBCONTEXT"/
rm -rf /tmp/"$WEBCONTEXT"
indexHtmlFilePath="/usr/share/nginx/html/"$WEBCONTEXT"/index.html"
targetPath="/usr/share/nginx/html/$WEBCONTEXT/assets/configurations"
fi
sed -i -- 's/href="/href-temp="/g' "$indexHtmlFilePath"
sed -i -- 's/src="/src-temp="/g' "$indexHtmlFilePath"
jsonRuntimeFilePath="/usr/share/nginx/environments/environment.runtime.json"
mkdir -p "$targetPath"
# Inject environment config to the angular dist assets/ folder
if [ -e $jsonRuntimeFilePath ]; then
jq '.dummyClientSecret = $value' --arg value "$CLIENT_SECRET" $jsonRuntimeFilePath >tmp.$$.json \
&& cp tmp.$$.json "$targetPath/environment.runtime.json" \
&& rm -rf tmp.$$.json
fi
# Start http server
......
#!/bin/sh
if [ "$1" = "/" ]; then
echo "nothing to do !!!"
else
echo "create subdirectory inside nginx root directory"
mkdir -p /usr/share/nginx/html/$1/
mv /usr/share/nginx/html/* /usr/share/nginx/html/$1/
fi
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 81;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
include /etc/nginx/mime.types;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
location / {
try_files $uri $uri/ /index.html;
}
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment