init base frontend

This commit is contained in:
Anthony Mineo 2020-03-29 11:31:16 -04:00
parent ade7f7e288
commit cfa645120d
52 changed files with 19366 additions and 9 deletions

View file

@ -29,8 +29,8 @@ RUN apk update && apk add --no-cache wget tzdata
#Set TimeZone
ENV TZ=America/New_York
#Set cron schedule (every day at 9:30am est)
RUN echo '30 9 * * * /app/start.sh' > /etc/crontabs/root
#Set cron schedule (every day at 11:30am est)
RUN echo '30 11 * * * /app/start.sh' > /etc/crontabs/root
WORKDIR /app

View file

@ -0,0 +1,3 @@
.git
node_modules
public/dist

67
build/webapp/Dockerfile Normal file
View file

@ -0,0 +1,67 @@
# [ Stage 1 ] - install node modules
FROM node:12.2-alpine as builder
RUN apk update
WORKDIR /build
COPY ./app/webapp/package.json /build/package.json
COPY ./app/webapp/package-lock.json /build/package-lock.json
RUN npm install
RUN npm i --global @adonisjs/cli
RUN npx adonis key:generate --echo
# ============================
# ============================
# [ Stage 2 ]
FROM node:12.2-alpine
LABEL maintainer="Anthony Mineo <anthonymineo@gmail.com>"
RUN apk update && apk add --no-cache bash curl
# Default envs as prod
ENV ENV_SILENT=true \
HOST=0.0.0.0 \
PORT=8080 \
HASH_DRIVER=bcrypt \
NODE_ENV=production \
WEBPACK_HMR=false \
CACHE_VIEWS=true \
APP_NAME=AdonisJs
ENV APP_URL=http://${HOST}:${PORT}
#ENV APP_KEY=you-need-to-generate-this
# secrets path _FILE prefix or ENV K=V
# Setup pm2 as our node process manager
# https://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/
RUN npm install pm2 -g
# Set node modules outside our app to keep it clean
COPY --from=builder /build/node_modules/ /opt/node_modules/
ENV PATH /opt/node_modules/.bin:$PATH
# Start script and config
COPY ./build/webapp/entrypoint.sh /entrypoint.sh
# Our App
WORKDIR /app
COPY ./app/webapp /app
RUN ln -nsf /opt/node_modules /app
# Bake prod assets into image
RUN rm -rf /app/public/dist && npm run webpack-server
EXPOSE 8080
HEALTHCHECK --interval=20s --timeout=30s --start-period=5s --retries=5 \
CMD curl -f http://localhost:8080/healthz || exit 1
ENTRYPOINT [ "/entrypoint.sh" ]

57
build/webapp/entrypoint.sh Executable file
View file

@ -0,0 +1,57 @@
#!/bin/bash
echo "Node ENV: $NODE_ENV"
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
file_env 'APP_KEY'
# Exit if APP_KEY is missing, this key is important!
if [ -z "$APP_KEY" ]
then
echo >&2 "[ERROR] No ENV for APP_KEY or APP_KEY_FILE found!"
echo >&2 "Run the ./generate-adonis-app-key.sh script or provide one at runtime"
exit 1
fi
if [[ "$NODE_ENV" == "development" ]]; then
echo "Prepping container for dev environment"
echo "Setting a symlink for ./node_modules -> /opt/node_modules"
ln -nsf /opt/node_modules /app
echo "Cleaning dist assets..."
rm -rf /app/public/dist
npm run webpack-server
fi
# Generate a dist assets if they don't exist -- (If they were deleted on the volume mount)
[ ! -d "/app/public/dist" ] && npm run webpack-server
if [[ "$NODE_ENV" == "production" ]]; then
pm2-runtime start /app/ecosystem._PROD_.config.js
elif [[ "$WEBPACK_HMR" == "true" ]]; then
pm2-runtime start /app/ecosystem._DEV_HOT_.config.js
else
pm2-runtime start /app/ecosystem._DEV_.config.js
fi