Skip to content

Commit

Permalink
Merge branch 'docker'
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiSakuma committed Mar 17, 2022
2 parents 851357c + 86a236e commit ca8a975
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ COPY docker/env.local .env.local
RUN npm run build


##__________________________________________________________________||
#
FROM nginx:1.21

WORKDIR /app
RUN apt-get update && apt-get install -y dumb-init
COPY --from=build /app/dist site
COPY docker/cmd.sh .
COPY docker/nginx-default.conf /etc/nginx/conf.d/default.conf
COPY docker/entrypoint.sh .
COPY docker/setup.sh /docker-entrypoint.d/99-nextline-web-setup.sh
COPY docker/nginx-default.conf.template /etc/nginx/templates/default.conf.template

ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD [ "./cmd.sh" ]
ENTRYPOINT ["./entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
11 changes: 11 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
# Source docker-entrypoint.sh from Nginx image after setting environment
# variables with default values if not set

API_HTTP="${API_HTTP:-http://localhost:8000}"
PUBLIC_PATH="${PUBLIC_PATH:-/}"

echo + "API_HTTP=${API_HTTP}"
echo + "PUBLIC_PATH=${PUBLIC_PATH}"

source /docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ server {
location / {
root /app/site;
index index.html index.htm;
try_files $uri $uri/ /index.html;
try_files $uri $uri/ ${PUBLIC_PATH}/index.html;
}
}
30 changes: 9 additions & 21 deletions docker/cmd.sh → docker/setup.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
#!/bin/bash

##__________________________________________________________________||
API_HTTP_DEFAULT="http://localhost:8000"
PUBLIC_PATH_DEFAULT="/"
HTML_DIR="/app/site"
NGINX_ROOT="/"

API_HTTP_PLACEHOLDER="graphql_http_placeholder"
PUBLIC_PATH_PLACEHOLDER="/public_path_placeholder/"

HTML_DIR="/app/site"

##__________________________________________________________________||
if [ -z $API_HTTP ]
then
echo 'Warning: $API_HTTP is not set!'
command="API_HTTP=$API_HTTP_DEFAULT"
echo + $command
eval $command
echo 'Error: $API_HTTP is not set!'
exit 1
fi

if [ -z $PUBLIC_PATH ]
then
command="PUBLIC_PATH=$PUBLIC_PATH_DEFAULT"
echo + $command
eval $command
echo 'Error: $PUBLIC_PATH is not set!'
exit 1
fi

if [ ! -d $HTML_DIR ]
Expand All @@ -31,7 +25,8 @@ then
exit 1
fi

if [ "$PUBLIC_PATH" != "$PUBLIC_PATH_DEFAULT" ]
# Move the Vue files to the Vue publicPath
if [ "$PUBLIC_PATH" != "$NGINX_ROOT" ]
then
HTML_DIR_TEMP="$(mktemp -d)/site"
command="mv $HTML_DIR $HTML_DIR_TEMP"
Expand All @@ -48,7 +43,7 @@ then
eval $command
fi

##__________________________________________________________________||
# Replace place holders with env vars in Vue files
(
command="cd $HTML_DIR"
echo + $command
Expand All @@ -66,10 +61,3 @@ fi
eval $command;
done
)

##__________________________________________________________________||
command='nginx -g "daemon off;"'
echo + $command;
eval $command;

##__________________________________________________________________||

0 comments on commit ca8a975

Please sign in to comment.