Skip to content

Commit

Permalink
Merge pull request #1 from icefoganalytics/main
Browse files Browse the repository at this point in the history
Jan 2024
  • Loading branch information
datajohnson authored Jan 2, 2024
2 parents 0bc1f5d + 5f38455 commit fb6563b
Show file tree
Hide file tree
Showing 117 changed files with 6,438 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
src/api/node_modules
src/api/dist
src/web/node_modules
src/web/dist
dist
npm-debug.log
node_modules
docs
30 changes: 30 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build and Push

on:
push:
branches: [ main ]

env:
REGISTRY: ghcr.io

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latest
116 changes: 116 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories + files
node_modules/
jspm_packages/
package-lock.json

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test
.env.production
.env.development
.vscode

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist
app

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
db/sapassword.env
.env.development

# DB Data
db/data


50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM oraclelinux:7-slim

RUN yum upgrade -y && yum install yum-utils
RUN yum -y install oracle-release-el7 && \
yum-config-manager --enable ol7_oracle_instantclient && \
yum -y install oracle-instantclient19.3-basiclite && \
rm -rf /var/cache/yum

RUN yum-config-manager --enable *addons
RUN yum install -y gcc-c++ make libaio

#RUN curl -sL https://rpm.nodesource.com/setup_18.x | bash -
#RUN yum install -y nodejs

RUN yum install -y oracle-nodejs-release-el7
RUN yum install -y nodejs

RUN mkdir /home/node
RUN mkdir /home/node/web

WORKDIR /home/node/web
COPY src/web/package*.json ./
COPY .env* ./
RUN npm install && npm cache clean --force --loglevel=error
COPY src/web ./

RUN mkdir /home/node/app
RUN mkdir /home/node/app/db
WORKDIR /home/node/app
COPY src/api/package*.json ./
COPY .env* ./

RUN npm install && npm cache clean --force --loglevel=error
COPY src/api ./

ENV TZ America/Whitehorse

RUN npm run build
EXPOSE 3000

WORKDIR /home/node/web
ENV NODE_ENV=production
RUN npm run build

WORKDIR /home/node/app

COPY --chown=node:node src/api/src/templates/* /home/node/app/dist/templates/
COPY --chown=node:node src/api/src/templates/email/* /home/node/app/dist/templates/email/

CMD ["node", "./dist/index.js"]
1 change: 1 addition & 0 deletions db/secrets/postgres-password
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
password
1 change: 1 addition & 0 deletions db/secrets/postgres-user
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
postgres
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: "3.4"

services:
db:
image: postgres:12
ports:
- "5432:5432"
environment:
POSTGRES_USER_FILE: "/run/secrets/postgres-user"
POSTGRES_PASSWORD_FILE: "/run/secrets/postgres-password"
volumes:
- pg-data:/var/lib/postgresql/data
- ./db/secrets/:/run/secrets

pgadmin:
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: michael@icefoganalytics.com
PGADMIN_DEFAULT_PASSWORD: testing123
ports:
- "8111:80"
volumes:
- my-data:/var/lib/pgadmin

email:
image: marcopas/docker-mailslurper
ports:
- 2500:2500
- 8081:8080
- 8085:8085

volumes:
pg-data:
my-data:
20 changes: 20 additions & 0 deletions src/api/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
API_PORT=3000
FRONTEND_URL=http://localhost:8080

AUTH0_DOMAIN=
AUTH0_AUDIENCE=testing

APPLICATION_NAME=Employee Sentiment

DB_CLIENT=
DB_USER=
DB_PASS=
DB_HOST=
DB_NAME=
DB_PORT=

MAIL_FROM=
MAIL_HOST=localhost
MAIL_PORT=2500
MAIL_USER=
MAIL_PASS=
7 changes: 7 additions & 0 deletions src/api/@types/express/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Express {
export interface Request {
user?: any;

isAuthenticated(): boolean;
}
}
38 changes: 38 additions & 0 deletions src/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "employee-sentiment-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc",
"start": "nodemon -L src/index.ts"
},
"author": "Michael Johnson",
"license": "ISC",
"dependencies": {
"axios": "^1.3.4",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"express-jwt": "^6.1.2",
"express-validator": "^6.15.0",
"helmet": "^6.0.1",
"jwks-rsa": "^3.0.0",
"knex": "^2.4.2",
"lodash": "^4.17.21",
"moment": "^2.29.4",
"nodemailer": "^6.9.1",
"oracledb": "^5.5.0",
"pg": "^8.10.0"
},
"devDependencies": {
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17",
"@types/express-jwt": "^6.0.4",
"@types/lodash": "^4.14.192",
"@types/nodemailer": "^6.4.7",
"nodemon": "^2.0.22",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
}
}
72 changes: 72 additions & 0 deletions src/api/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import * as dotenv from "dotenv";
import { Knex } from "knex";

export const NODE_ENV = process.env.NODE_ENV || "development";

let path;
switch (process.env.NODE_ENV) {
case "test":
path = `.env.test`;
break;
case "production":
path = `.env.production`;
break;
default:
path = `.env.development`;
}

dotenv.config({ path: path });

console.log(`LOADING ${NODE_ENV} CONFIG FROM ${path}`);

export const apiBaseUrl = process.env.NODE_ENV == "production" ? "" : "http://localhost:3000";
export const API_PORT = process.env.API_PORT || "3000";

export const FRONTEND_URL = process.env.FRONTEND_URL || "";
export const AUTH0_DOMAIN = `${process.env.AUTH0_DOMAIN}/` || "";
export const AUTH0_AUDIENCE = process.env.AUTH_AUDIENCE;

export const APPLICATION_NAME = process.env.APPLICATION_NAME || "";

export const MAIL_FROM = process.env.MAIL_FROM || "employee-sentiment@yukon.ca";
export const MAIL_HOST = process.env.MAIL_HOST || "smtp.gov.yk.ca";
export const MAIL_PORT = process.env.MAIL_PORT || 25;
export const MAIL_USER = process.env.MAIL_USER || "";
export const MAIL_PASS = process.env.MAIL_PASS || "";

export const MAIL_CONFIG = {
host: MAIL_HOST,
port: MAIL_PORT,
secure: false, // true for 465, false for other ports
};

export const DB_CLIENT = process.env.DB_CLIENT || "oracledb";
export const DB_NAME = process.env.DB_NAME || "";
export const DB_USER = process.env.DB_USER || "";
export const DB_PASS = process.env.DB_PASS || "";
export const DB_HOST = process.env.DB_HOST || "";
export const DB_PORT = process.env.DB_PORT || "1521";

export const DB_CONFIG = {
client: DB_CLIENT,
connection: {
host: DB_HOST,
user: DB_USER,
password: DB_PASS,
database: DB_NAME,
port: parseInt(DB_PORT),
},
pool: { min: 0, reapIntervalMillis: 600000 },
};

export const DB_SCHEMA = process.env.DB_SCHEMA || "";
export const DB_USER_TABLE = process.env.DB_USER_TABLE || "";
export const DB_QUESTION_TABLE = process.env.DB_QUESTION_TABLE || "";
export const DB_PARTICIPANT_TABLE = process.env.DB_PARTICIPANT_TABLE || "";
export const DB_ANSWER_TABLE = process.env.DB_ANSWER_TABLE || "";
export const DB_RATING_TABLE = process.env.DB_RATING_TABLE || "";
export const DB_USER_QUESTION_TABLE = process.env.DB_USER_QUESTION_TABLE || "";

export const AD_CLIENT_ID = process.env.AD_CLIENT_ID || "";
export const AD_CLIENT_SECRET = process.env.AD_CLIENT_SECRET || "";
export const AD_TENANT_ID = process.env.AD_TENANT_ID || "";
4 changes: 4 additions & 0 deletions src/api/src/data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import knex from "knex";
import { DB_CONFIG } from "../config";

export const db = knex(DB_CONFIG);
Loading

0 comments on commit fb6563b

Please sign in to comment.