20 Commits

Author SHA1 Message Date
99db648a36 - Endlessly fighting the ENV - I should be loading from the package... 2023-05-06 09:40:25 -04:00
adcab6afcb Double dollar
Some checks failed
continuous-integration/drone/push Build encountered an error
2023-05-06 09:28:24 -04:00
8e40c0a06c Tweaking the ENV
Some checks failed
continuous-integration/drone/push Build encountered an error
2023-05-06 09:19:31 -04:00
db5e4858b8 More ENV updates
Some checks failed
continuous-integration/drone/push Build was killed
2023-05-06 09:10:45 -04:00
d800311ae7 - ENV updates
Some checks failed
continuous-integration/drone/push Build encountered an error
2023-05-06 09:08:15 -04:00
32fdde5d90 - The missing env variables...
Some checks failed
continuous-integration/drone/push Build encountered an error
2023-05-06 08:43:26 -04:00
2eacdaeece Tweaks
Some checks failed
continuous-integration/drone/push Build encountered an error
2023-05-06 01:38:00 -04:00
827bce6e1b Updates for staging
Some checks failed
continuous-integration/drone/push Build is failing
2023-05-06 01:15:11 -04:00
50c74fdb71 I think it is working now...
Some checks failed
continuous-integration/drone/push Build is failing
2023-05-06 00:48:27 -04:00
42f091489e Who knows what happens next...
Some checks failed
continuous-integration/drone/push Build is failing
2023-05-05 18:14:20 -04:00
995dd9a015 A whole new world...
Some checks failed
continuous-integration/drone/push Build is failing
2023-05-05 11:22:26 -04:00
5b0c9ba72d Escape the interpolation
Some checks failed
continuous-integration/drone/push Build is failing
2023-05-05 11:14:31 -04:00
d745869cc0 Last bits to make it whole again...
Some checks are pending
continuous-integration/drone/push Build is running
2023-05-05 11:10:13 -04:00
e6389d8b9b More tweaks... 2023-05-05 11:05:18 -04:00
47f1bdf485 More path fixes...
Some checks failed
continuous-integration/drone/push Build is failing
2023-05-05 10:56:33 -04:00
bc96664b7c Path fixes ... and the dumbest environment error yet...
Some checks are pending
continuous-integration/drone/push Build is running
2023-05-05 10:53:42 -04:00
04ec6e2de3 Hmmmm
Some checks failed
continuous-integration/drone/push Build encountered an error
2023-05-05 10:42:22 -04:00
ba31f4b8be More changes
Some checks failed
continuous-integration/drone/push Build encountered an error
2023-05-05 10:01:42 -04:00
d5f9bc4d05 fix bad commands
Some checks failed
continuous-integration/drone/push Build encountered an error
2023-05-05 09:20:14 -04:00
ad9ffc89b5 With links and fixed names...
Some checks failed
continuous-integration/drone/push Build encountered an error
2023-05-05 09:09:06 -04:00
13 changed files with 182 additions and 107 deletions

View File

@@ -61,7 +61,7 @@ trigger:
branch: branch:
- main - main
event: event:
- pull_request # - pull_request
- push - push
--- ---
@@ -87,7 +87,7 @@ steps:
from_secret: registry_username from_secret: registry_username
password: password:
from_secret: registry_password from_secret: registry_password
registry: https://git.mifi.dev registry: https://git.mifi.dev/api/packages/mifi/npm
token: token:
- from_secret: gitea_token - from_secret: gitea_token
volumes: volumes:
@@ -109,19 +109,35 @@ steps:
- success - success
- failure - failure
- name: Publish Image - name: Publish Image
image: plugins/docker image: docker
settings: environment:
auto_tag: true USERNAME:
squash: true
repo: git.mifi.dev/mifi/auth
context: mifi
registry: git.mifi.dev
username:
from_secret: registry_username from_secret: registry_username
password: PASSWORD:
from_secret: registry_password from_secret: registry_password
ssh-agent-key: commands:
from_secret: gitea_token - docker login git.mifi.dev
- docker build -t git.mifi.dev/mifi/mifi/auth:latest -t git.mifi.dev/mifi/mifi/auth:${DRONE_TAG} .
- docker push git.mifi.dev/mifi/mifi/auth:latest
volumes:
- name: dockersock
path: /var/run/docker.sock
- name: dockerconfig
path: /drone/grow/.docker/config.json
# - name: Publish Image
# image: plugins/docker
# settings:
# auto_tag: true
# squash: true
# repo: git.mifi.dev/mifi/auth
# context: mifi
# registry: git.mifi.dev
# username:
# from_secret: registry_username
# password:
# from_secret: registry_password
# ssh-agent-key:
# from_secret: gitea_token
volumes: volumes:
- name: dockersock - name: dockersock
path: /var/run/docker.sock path: /var/run/docker.sock
@@ -152,16 +168,16 @@ volumes:
path: /var/run/docker.sock path: /var/run/docker.sock
- name: npmrc - name: npmrc
host: host:
path: /volume1/docker/grow/labs-auth/.npmrc path: /volume1/docker/beethoven/labs-auth/.npmrc
depends_on: depends_on:
- Test Pipeline - Test Pipeline
trigger: trigger:
branch: # branch:
- main # - main
event: event:
- push # - push
- tag - tag
--- ---
@@ -176,14 +192,19 @@ steps:
- name: Deploy Container - name: Deploy Container
image: docker image: docker
privileged: true privileged: true
environment:
- HOST=area51.mifi.dev
- PORT=9001
- ROUTE_PREFIX=/auth
- CONTAINER_PREFIX=mifi
commands: commands:
- docker compose pull - docker compose -f docker-compose.staging.yml pull
- docker compose build --no-cache - docker compose -f docker-compose.staging.yml build --no-cache
- docker compose rm --stop . - docker compose -f docker-compose.staging.yml rm --stop
- docker compose up --wait - docker compose -f docker-compose.staging.yml up --wait
volumes: volumes:
- name: env - name: env-secrets
path: /drone/grow/.env path: /drone/grow/.env.staging
- name: dockersock - name: dockersock
path: /var/run/docker.sock path: /var/run/docker.sock
- name: dockerconfig - name: dockerconfig
@@ -212,16 +233,16 @@ volumes:
- name: dockersock - name: dockersock
host: host:
path: /var/run/docker.sock path: /var/run/docker.sock
- name: env - name: env-secrets
host: host:
path: /volume1/docker/labs/grow-auth/.env path: /volume1/docker/beethoven/labs-auth/.env.staging
depends_on: depends_on:
- Test Pipeline - Test Pipeline
trigger: trigger:
branch: # branch:
- main # - main
event: event:
- push # - push
- tag - tag

29
.env.dev Normal file
View File

@@ -0,0 +1,29 @@
HOST=localhost
PORT=9001
ROUTE_PREFIX=/auth
LOGIN_ROUTE=/login
RESET_ROUTE=/reset
DB_ADMIN_USERNAME=root
DB_ADMIN_PASSWORD=password
DB_USERNAME=user
DB_PASSWORD=password
DB_NAME=auth
MONGO_INITDB_ROOT_USERNAME=$DB_ADMIN_USERNAME
MONGO_INITDB_ROOT_PASSWORD=$DB_ADMIN_PASSWORD
MONGO_INITDB_DATABASE=$DB_NAME
SESSION_KEY=shjhakjfhfjdshjksdhfdshfhfduyeyb73te4
JWT_AUDIENCE=Grow.io
JWT_ISSUER=Grow Latch
JWT_SECRET=Th!sIs a d3v3lopm3nt server SEcr¢T.
LOGIN_VALID_TIME=12H
RESET_VALID_MINUTES=15
DEFAULT_TOKEN_DAYS=1
CONTAINER_PREFIX=dev

View File

@@ -1,13 +1,3 @@
# FROM node:20-alpine AS build
# RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
# WORKDIR /home/node/app
# COPY package*.json .
# COPY dist/lib .
# USER node
# RUN yarn install --frozen-lockfile --production
# COPY --chown=node:node node_modules ./node_modules
# CMD ["node", "dist/lib/server/index.js"]
FROM node:20-alpine AS build FROM node:20-alpine AS build
WORKDIR /home/node/app WORKDIR /home/node/app
COPY package*.json ./ COPY package*.json ./
@@ -23,4 +13,6 @@ WORKDIR /home/node/app
COPY package*.json ./ COPY package*.json ./
RUN yarn install --frozen-lockfile --production RUN yarn install --frozen-lockfile --production
COPY --from=0 /home/node/app/dist . COPY --from=0 /home/node/app/dist .
EXPOSE 9001
EXPOSE 27017
CMD ["node","server/index.js"] CMD ["node","server/index.js"]

32
docker-compose.dev.yml Normal file
View File

@@ -0,0 +1,32 @@
version: '3.8'
services:
auth-service_mongo:
env_file: .env.dev
container_name: ${CONTAINER_PREFIX:-dev}-auth-service_mongo
ports:
- 27017:27017
networks:
- labs-net
volumes:
- /var/tmp/labs:/data/db
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
restart: unless-stopped
image: mongo:latest
auth-service:
env_file: .env.dev
build: .
container_name: ${CONTAINER_PREFIX:-dev}-auth-service
ports:
- 9001:9001
environment:
- DB_HOST=${CONTAINER_PREFIX:-dev}-auth-service_mongo
networks:
- labs-net
restart: unless-stopped
image: node:20-alpine
depends_on:
- auth-service_mongo
networks:
labs-net:
name: labs-net

View File

@@ -0,0 +1,38 @@
version: '3.8'
services:
auth-service_mongo:
container_name: ${CONTAINER_PREFIX:-mifi}-auth-service_mongo
env_file:
- .env.staging
networks:
- docknet
volumes:
- '/volume1/docker/labs/auth/mongo:/data/db'
restart: unless-stopped
image: mongo:latest
auth-service:
env_file:
- .env.staging
build: .
container_name: ${CONTAINER_PREFIX:-mifi}-auth-service
environment:
- DB_HOST=${CONTAINER_PREFIX:-mifi}-auth-service_mongo
labels:
- 'traefik.enable=true'
- 'traefik.http.routers.grow.rule=Host(`${HOST}`) && Path(`${ROUTE_PREFIX}`)'
- 'traefik.http.routers.grow.entrypoints=websecure'
- 'traefik.http.routers.grow.tls=true'
- 'traefik.http.routers.grow.tls.certresolver=letsencrypt'
- 'traefik.http.routers.grow.service=grow-service'
- 'traefik.http.services.grow-service.loadbalancer.server.port=${PORT}'
networks:
- docknet
restart: unless-stopped
image: node:20-alpine
depends_on:
- auth-service_mongo
networks:
docknet:
name: docknet
external: true

View File

@@ -1,53 +0,0 @@
version: '3.8'
services:
auth-service_mongo:
container_name: ${CONTAINER_PREFIX}-${SERVICE_NAME}_${DB_TYPE}
environment:
- ALLOW_EMPTY_PASSWORD=yes
- MONGO_INITDB_ROOT_USERNAME=${DB_USER}
- MONGO_INITDB_ROOT_PASSWORD=${DB_PASS}
- MONGO_INITDB_DATABASE=${DB_NAME}
networks:
- docknet
volumes:
- '/volume1/docker/labs/grow-auth/mongo:/data/db'
restart: unless-stopped
image: mongo
auth-service:
build: .
container_name: ${CONTAINER_PREFIX}-${SERVICE_NAME}
environment:
- PORT=${PORT}
- ROUTE_PREFIX=${ROUTE_PREFIX}
- LOGIN_ROUTE=${LOGIN_ROUTE}
- RESET_ROUTE=${RESET_ROUTE}
- DB_HOST=${SERVICE_NAME}_${DB_TYPE}
- DB_USER=${DB_USER}
- DB_PASS=${DB_PASS}
- DB_NAME=${DB_NAME}
- SESSION_KEY=${SESSION_KEY}
- JWT_AUDIENCE=${JWT_AUDIENCE}
- JWT_ISSUER=${JWT_ISSUER}
- JWT_SECRET=${JWT_SECRET}
- LOGIN_VALID_TIME=${LOGIN_VALID_TIME}
- RESET_VALID_MINUTES=${RESET_VALID_MINUTES}
- DEFAULT_TOKEN_DAYS=${DEFAULT_TOKEN_DAYS}
labels:
- 'traefik.enable=true'
- 'traefik.http.routers.grow.rule=Host(`${HOST}`)'
- 'traefik.http.routers.grow.rule=Path(`${ROUTE_PREFIX}`)'
- 'traefik.http.routers.grow.entrypoints=websecure'
- 'traefik.http.routers.grow.tls=true'
- 'traefik.http.routers.grow.tls.certresolver=letsencrypt'
- 'traefik.http.routers.grow.service=gitea'
- 'traefik.http.services.gitea.loadbalancer.server.port=${PORT}'
networks:
- docknet
restart: unless-stopped
image: node
depends_on:
- auth-service_mongo
networks:
docknet:
name: docknet

View File

@@ -1,5 +1,5 @@
export const DB_HOST = process.env.DB_HOST || 'mongodb'; export const DB_HOST = process.env.DB_HOST || 'not_set';
export const DB_PORT = process.env.DB_PORT || 27017; export const DB_PORT = process.env.DB_PORT || 27017;
export const DB_USER = process.env.DB_USER || 'test'; export const DB_USERNAME = process.env.DB_USERNAME || 'not_set';
export const DB_PASS = process.env.DB_PASSWORD || 'test'; export const DB_PASSWORD = process.env.DB_PASSWORD || 'not_set';
export const DB_NAME = process.env.DB_NAME || 'auth'; export const DB_NAME = process.env.DB_NAME || 'not_set';

View File

@@ -1,4 +1,4 @@
export const PACKAGE_NAME = '@mifi/latch'; export const PACKAGE_NAME = '@mifi/auth';
export const PORT = process.env.PORT || 9000; export const PORT = process.env.PORT || 9000;
export const SESSION_KEY = process.env.SESSION_KEY || 'secret-key'; export const SESSION_KEY = process.env.SESSION_KEY || 'secret-key';

View File

@@ -1,5 +1,5 @@
import mongoose from 'mongoose'; import mongoose from 'mongoose';
import { DB_HOST, DB_NAME, DB_PASS, DB_PORT, DB_USER } from '../constants/db'; import { DB_HOST, DB_NAME, DB_PASSWORD, DB_PORT, DB_USERNAME } from '../constants/db';
export const connection = mongoose.connect(`mongodb://${DB_USER}:${DB_PASS}@${DB_HOST}:${DB_PORT}/${DB_NAME}`); export const connection = mongoose.connect(`mongodb://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}`);

View File

@@ -11,6 +11,12 @@ import { ErrorCodes, getErrorBody } from '../../constants/errors';
const routerOpts: Router.IRouterOptions = { prefix }; const routerOpts: Router.IRouterOptions = { prefix };
const router: Router = new Router(routerOpts); const router: Router = new Router(routerOpts);
router.get('/info', (ctx) => {
ctx.body = {
service: process.env.SERVICE_NAME,
};
});
router.post('/', async (ctx) => { router.post('/', async (ctx) => {
const data = (await Auth.create(ctx.body)).save(); const data = (await Auth.create(ctx.body)).save();
ctx.body = { success: true, data: { ...data, strategies: undefined } }; ctx.body = { success: true, data: { ...data, strategies: undefined } };

View File

@@ -1,12 +1,11 @@
import dotenv from 'dotenv';
import app from './app'; import app from './app';
import { connection } from '../db'; import { connection } from '../db';
import { PORT } from '../constants/env'; import { PORT } from '../constants/env';
dotenv.config();
connection.then( connection.then(
() => app.listen(PORT), () => {
(err) => console.error('ERROR!', err), app.listen(PORT);
console.log('LISTENING', process.env);
},
(err) => console.error('SERVER ERROR!', { err, env: process.env }),
); );

12
mongo-init.js Normal file
View File

@@ -0,0 +1,12 @@
/* eslint-disable no-undef */
db = db.getSiblingDB(process.env.DB_NAME);
db.createUser({
user: process.env.DB_USERNAME,
pwd: process.env.DB_PASSWORD,
roles: [
{
role: 'readWrite',
db: process.env.DB_NAME,
},
],
});

View File

@@ -1,6 +1,6 @@
{ {
"name": "@mifi/auth", "name": "@mifi/auth",
"version": "0.0.14", "version": "0.0.34",
"author": "mifi (Mike Fitzpatrick)", "author": "mifi (Mike Fitzpatrick)",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
@@ -80,6 +80,5 @@
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://git.mifi.dev/mifi/auth.git" "url": "https://git.mifi.dev/mifi/auth.git"
}, }
"registry": "https://git.mifi.dev"
} }