mirror of
https://github.com/amineo/t2-stat-parser.git
synced 2026-01-19 17:34:43 +00:00
Setup stats API container:
This commit is contained in:
parent
9176889086
commit
b3925a8fc6
|
|
@ -7,3 +7,10 @@ POSTGRES_PASSWORD="dev"
|
|||
FTP_HOST="127.0.0.1"
|
||||
FTP_USER="user"
|
||||
FTP_PW="pw"
|
||||
|
||||
# API DB Connection
|
||||
DATABASE_HOST="db"
|
||||
DATABASE_PORT="5432"
|
||||
DATABASE_USER="dev"
|
||||
DATABASE_PASSWORD="dev"
|
||||
DATABASE_NAME="t2_stats"
|
||||
13564
app/api/package-lock.json
generated
Normal file
13564
app/api/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
2
build/api/.dockerignore
Normal file
2
build/api/.dockerignore
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
.git
|
||||
node_modules
|
||||
70
build/api/Dockerfile
Normal file
70
build/api/Dockerfile
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
# [ Stage 1 ] - install node modules
|
||||
FROM node:12.18-alpine as builder
|
||||
|
||||
WORKDIR /build/app
|
||||
|
||||
RUN npm i -g @nestjs/cli
|
||||
|
||||
COPY ./app/api .
|
||||
RUN npm install
|
||||
|
||||
ENV NODE_ENV=production
|
||||
RUN nest build
|
||||
|
||||
|
||||
# ============================
|
||||
# ============================
|
||||
|
||||
# [ Stage 2 ]
|
||||
FROM node:12.18-alpine
|
||||
LABEL maintainer="Season 4 <webmaster@season4.io>"
|
||||
|
||||
RUN apk update && apk add --no-cache openssl bash curl
|
||||
|
||||
# Default envs as prod
|
||||
ENV HOST=0.0.0.0 \
|
||||
PORT=8080 \
|
||||
NODE_ENV=production \
|
||||
APP_NAME=NestJS
|
||||
|
||||
ENV APP_URL=https://${HOST}:${PORT}
|
||||
|
||||
|
||||
# Setup pm2 as our node process manager
|
||||
# https://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/
|
||||
RUN npm i -g pm2 @nestjs/cli
|
||||
|
||||
RUN mkdir /opt/node_app && chown node:node /opt/node_app && mkdir /localcert && chown node:node /localcert
|
||||
RUN mkdir -p /opt/node_app/app/node_modules/ && chown node:node /opt/node_app/app/node_modules/
|
||||
|
||||
WORKDIR /opt/node_app
|
||||
|
||||
#USER node
|
||||
|
||||
# Generate a localhost cert
|
||||
# RUN openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout /localcert/key.pem -out /localcert/cert.pem -subj "/C=US/ST=New Jersey/L=Warren/O=localhost/OU=IT/CN=127.0.0.1"
|
||||
|
||||
|
||||
ENV PATH /opt/node_app/node_modules/.bin:$PATH
|
||||
|
||||
# Our App
|
||||
WORKDIR /opt/node_app/app
|
||||
|
||||
# Set node modules outside our app to keep it clean
|
||||
COPY --from=builder /build/app/node_modules/ /opt/node_app/node_modules/
|
||||
|
||||
COPY --from=builder /build/app/dist/ /opt/node_app/app/dist/
|
||||
|
||||
COPY ./app/api/package.json ./app/api/package-lock.json* ./
|
||||
|
||||
|
||||
# Start script and config
|
||||
COPY ./build/api/ecosystem._PROD_.config.js /opt/node_app/ecosystem._PROD_.config.js
|
||||
COPY ./build/api/entrypoint.sh /entrypoint.sh
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
HEALTHCHECK --interval=20s --timeout=30s --start-period=5s --retries=5 \
|
||||
CMD curl -f -k https://localhost:8443/healthz || exit 1
|
||||
|
||||
ENTRYPOINT [ "/entrypoint.sh" ]
|
||||
14
build/api/ecosystem._DEV_.config.js
Normal file
14
build/api/ecosystem._DEV_.config.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
name: process.env.APP_NAME,
|
||||
cwd: '/opt/node_app/app/',
|
||||
script: 'npm run start:dev --interpreter bash',
|
||||
// Options reference: https://pm2.keymetrics.io/docs/usage/application-declaration/
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
watch: false,
|
||||
ignore_watch: [ 'node_modules', 'dist' ]
|
||||
}
|
||||
]
|
||||
};
|
||||
10
build/api/ecosystem._PROD_.config.js
Normal file
10
build/api/ecosystem._PROD_.config.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
cwd: '/opt/node_app/app/',
|
||||
script: 'node dist/main --interpreter bash',
|
||||
autorestart: true,
|
||||
instances: 1
|
||||
}
|
||||
]
|
||||
};
|
||||
41
build/api/entrypoint.sh
Executable file
41
build/api/entrypoint.sh
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
#!/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" == "production" ]]; then
|
||||
pm2-runtime start /opt/node_app/ecosystem._PROD_.config.js
|
||||
else
|
||||
npm install && \
|
||||
pm2-runtime start /opt/node_app/ecosystem._DEV_.config.js
|
||||
fi
|
||||
|
|
@ -2,7 +2,6 @@ version: "3.7"
|
|||
|
||||
# Service Definitions
|
||||
services:
|
||||
|
||||
db:
|
||||
environment:
|
||||
POSTGRES_DB: "t2_stats"
|
||||
|
|
@ -14,7 +13,6 @@ services:
|
|||
- ./build/postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
|
||||
- ./build/postgres/export_local_db.sh:/export_local_db.sh
|
||||
|
||||
|
||||
parser:
|
||||
environment:
|
||||
DATABASE_URL: "postgres://dev:dev@db:5432/t2_stats"
|
||||
|
|
@ -23,27 +21,43 @@ services:
|
|||
volumes:
|
||||
- ./app/t2-stat-parser:/app
|
||||
|
||||
web:
|
||||
environment:
|
||||
DB_USER: "dev"
|
||||
DB_PASSWORD: "dev"
|
||||
|
||||
CACHE_VIEWS: "false"
|
||||
NODE_ENV: "development" # auto-reloads app on save, dev builds
|
||||
WEBPACK_HMR: "true" # default is false -- this is useful for when you're focused on Frontend Dev
|
||||
ports:
|
||||
- "8080:8080" # adonis http port
|
||||
- "8081:8081" # webpack-dev-server port
|
||||
volumes:
|
||||
- ./app/webapp:/app
|
||||
|
||||
# api:
|
||||
# web:
|
||||
# environment:
|
||||
# DB_USER: "dev"
|
||||
# DB_PASSWORD: "dev"
|
||||
# CACHE_VIEWS: "false"
|
||||
# NODE_ENV: "development" # auto-reloads app on save, dev builds
|
||||
# WEBPACK_HMR: "true" # default is false -- this is useful for when you're focused on Frontend Dev
|
||||
# ports:
|
||||
# - "8080:8080" # adonis http port
|
||||
# - "8081:8081" # webpack-dev-server port
|
||||
# volumes:
|
||||
# - ./app/api:/home/node/app
|
||||
# - ./app/webapp:/app
|
||||
|
||||
api:
|
||||
environment:
|
||||
NODE_ENV: "development" # auto-reloads app on save
|
||||
|
||||
env_file:
|
||||
- .env
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- ./build/api/ecosystem._PROD_.config.js:/opt/node_app/ecosystem._PROD_.config.js
|
||||
- ./build/api/ecosystem._DEV_.config.js:/opt/node_app/ecosystem._DEV_.config.js
|
||||
- ./app/api:/opt/node_app/app:delegated
|
||||
|
||||
# temp vols
|
||||
- notused:/opt/node_app/app/node_modules
|
||||
- builtincontainer:/opt/node_app/app/dist
|
||||
networks:
|
||||
- internal
|
||||
|
||||
secrets:
|
||||
adonis.appkey:
|
||||
external: false
|
||||
file: ./docker-secrets/adonis.appkey.v1
|
||||
|
||||
volumes:
|
||||
notused:
|
||||
builtincontainer:
|
||||
|
|
|
|||
|
|
@ -43,48 +43,46 @@ services:
|
|||
mode: replicated
|
||||
replicas: 1
|
||||
|
||||
web:
|
||||
image: "amineo/t2-stats-web:v0.1.0-rc6"
|
||||
api:
|
||||
image: "amineo/t2-stats-api:v0.0.1"
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./build/webapp/Dockerfile
|
||||
dockerfile: ./build/api/Dockerfile
|
||||
environment:
|
||||
NODE_ENV: "production" # set as default in image
|
||||
CACHE_VIEWS: "true" # set as default in image
|
||||
APP_NAME: "Web" # set as default in image
|
||||
|
||||
# APP_KEY: "You-need-to-generate-this (npx adonis key:generate --echo)"
|
||||
APP_KEY_FILE: /run/secrets/adonis.appkey
|
||||
|
||||
DB_HOST: "db"
|
||||
DB_PORT: 5432
|
||||
DB_USER: ""
|
||||
DB_PASSWORD: ""
|
||||
DB_DATABASE: t2_stats
|
||||
|
||||
secrets:
|
||||
- adonis.appkey
|
||||
ports:
|
||||
- "8080:8080"
|
||||
APP_NAME: "T2StatsAPI" # set as default in image
|
||||
depends_on:
|
||||
- db
|
||||
networks:
|
||||
- internal
|
||||
- external
|
||||
deploy:
|
||||
# labels:
|
||||
# - traefik.enable=false
|
||||
mode: replicated
|
||||
replicas: 1
|
||||
|
||||
# api:
|
||||
# image: "node:12-alpine"
|
||||
# depends_on:
|
||||
# - db
|
||||
# web:
|
||||
# image: "amineo/t2-stats-web:v0.1.0-rc6"
|
||||
# build:
|
||||
# context: .
|
||||
# dockerfile: ./build/webapp/Dockerfile
|
||||
# environment:
|
||||
# NODE_ENV: "production" # set as default in image
|
||||
# CACHE_VIEWS: "true" # set as default in image
|
||||
# APP_NAME: "Web" # set as default in image
|
||||
# # APP_KEY: "You-need-to-generate-this (npx adonis key:generate --echo)"
|
||||
# APP_KEY_FILE: /run/secrets/adonis.appkey
|
||||
# DB_HOST: "db"
|
||||
# DB_PORT: 5432
|
||||
# DB_USER: ""
|
||||
# DB_PASSWORD: ""
|
||||
# DB_DATABASE: t2_stats
|
||||
# secrets:
|
||||
# - adonis.appkey
|
||||
# ports:
|
||||
# - "8080:8080"
|
||||
# networks:
|
||||
# - internal
|
||||
# - external
|
||||
# deploy:
|
||||
# labels:
|
||||
# - traefik.enable=true
|
||||
# # labels:
|
||||
# # - traefik.enable=false
|
||||
# mode: replicated
|
||||
# replicas: 1
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue