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
|
|
@ -6,4 +6,11 @@ POSTGRES_PASSWORD="dev"
|
||||||
|
|
||||||
FTP_HOST="127.0.0.1"
|
FTP_HOST="127.0.0.1"
|
||||||
FTP_USER="user"
|
FTP_USER="user"
|
||||||
FTP_PW="pw"
|
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
|
|
@ -79,4 +79,4 @@
|
||||||
"coverageDirectory": "../coverage",
|
"coverageDirectory": "../coverage",
|
||||||
"testEnvironment": "node"
|
"testEnvironment": "node"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
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,48 +2,62 @@ version: "3.7"
|
||||||
|
|
||||||
# Service Definitions
|
# Service Definitions
|
||||||
services:
|
services:
|
||||||
|
|
||||||
db:
|
db:
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_DB: "t2_stats"
|
POSTGRES_DB: "t2_stats"
|
||||||
POSTGRES_USER: "dev"
|
POSTGRES_USER: "dev"
|
||||||
POSTGRES_PASSWORD: "dev"
|
POSTGRES_PASSWORD: "dev"
|
||||||
ports:
|
ports:
|
||||||
- "5432:5432"
|
- "5432:5432"
|
||||||
volumes:
|
volumes:
|
||||||
- ./build/postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
|
- ./build/postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
|
||||||
- ./build/postgres/export_local_db.sh:/export_local_db.sh
|
- ./build/postgres/export_local_db.sh:/export_local_db.sh
|
||||||
|
|
||||||
|
|
||||||
parser:
|
parser:
|
||||||
environment:
|
environment:
|
||||||
DATABASE_URL: "postgres://dev:dev@db:5432/t2_stats"
|
DATABASE_URL: "postgres://dev:dev@db:5432/t2_stats"
|
||||||
ports:
|
ports:
|
||||||
- "8000:8080"
|
- "8000:8080"
|
||||||
volumes:
|
volumes:
|
||||||
- ./app/t2-stat-parser:/app
|
- ./app/t2-stat-parser:/app
|
||||||
|
|
||||||
web:
|
# 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:
|
||||||
environment:
|
environment:
|
||||||
DB_USER: "dev"
|
NODE_ENV: "development" # auto-reloads app on save
|
||||||
DB_PASSWORD: "dev"
|
|
||||||
|
env_file:
|
||||||
CACHE_VIEWS: "false"
|
- .env
|
||||||
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:
|
ports:
|
||||||
- "8080:8080" # adonis http port
|
- "8080:8080"
|
||||||
- "8081:8081" # webpack-dev-server port
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./app/webapp:/app
|
- ./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
|
||||||
# api:
|
- ./app/api:/opt/node_app/app:delegated
|
||||||
# volumes:
|
|
||||||
# - ./app/api:/home/node/app
|
|
||||||
|
|
||||||
|
|
||||||
|
# temp vols
|
||||||
|
- notused:/opt/node_app/app/node_modules
|
||||||
|
- builtincontainer:/opt/node_app/app/dist
|
||||||
|
networks:
|
||||||
|
- internal
|
||||||
|
|
||||||
secrets:
|
secrets:
|
||||||
adonis.appkey:
|
adonis.appkey:
|
||||||
external: false
|
external: false
|
||||||
file: ./docker-secrets/adonis.appkey.v1
|
file: ./docker-secrets/adonis.appkey.v1
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
notused:
|
||||||
|
builtincontainer:
|
||||||
|
|
|
||||||
|
|
@ -43,48 +43,46 @@ services:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
replicas: 1
|
replicas: 1
|
||||||
|
|
||||||
web:
|
api:
|
||||||
image: "amineo/t2-stats-web:v0.1.0-rc6"
|
image: "amineo/t2-stats-api:v0.0.1"
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: ./build/webapp/Dockerfile
|
dockerfile: ./build/api/Dockerfile
|
||||||
environment:
|
environment:
|
||||||
NODE_ENV: "production" # set as default in image
|
NODE_ENV: "production" # set as default in image
|
||||||
CACHE_VIEWS: "true" # set as default in image
|
APP_NAME: "T2StatsAPI" # set as default in image
|
||||||
APP_NAME: "Web" # set as default in image
|
depends_on:
|
||||||
|
- db
|
||||||
# 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:
|
networks:
|
||||||
- internal
|
- internal
|
||||||
- external
|
- external
|
||||||
deploy:
|
|
||||||
# labels:
|
|
||||||
# - traefik.enable=false
|
|
||||||
mode: replicated
|
|
||||||
replicas: 1
|
|
||||||
|
|
||||||
# api:
|
# web:
|
||||||
# image: "node:12-alpine"
|
# image: "amineo/t2-stats-web:v0.1.0-rc6"
|
||||||
# depends_on:
|
# build:
|
||||||
# - db
|
# 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:
|
# networks:
|
||||||
# - internal
|
# - internal
|
||||||
# - external
|
# - external
|
||||||
# deploy:
|
# deploy:
|
||||||
# labels:
|
# # labels:
|
||||||
# - traefik.enable=true
|
# # - traefik.enable=false
|
||||||
# mode: replicated
|
# mode: replicated
|
||||||
# replicas: 1
|
# replicas: 1
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue