Compare commits
138 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
967ef4e440
|
|||
|
d9285e4bec
|
|||
|
17949255d3
|
|||
|
c6e5eaf3a1
|
|||
|
0e220c0cf0
|
|||
|
ebfe4339dc
|
|||
|
0d3ca5382b
|
|||
|
4477af601a
|
|||
|
3b27300249
|
|||
|
47c4f4816c
|
|||
|
95fdd8cf45
|
|||
|
f7f6dcae12
|
|||
|
62a917677d
|
|||
|
717e651cf9
|
|||
|
25688e1f03
|
|||
|
050a4f2b39
|
|||
|
36093f0fb5
|
|||
|
b9d5683d22
|
|||
|
0b95587f53
|
|||
|
486ef52745
|
|||
|
ca6a6a9ab3
|
|||
|
676124f23e
|
|||
|
d25755775e
|
|||
|
71904a53d9
|
|||
|
3dd7ccdcdc
|
|||
|
c8e08ef567
|
|||
|
cfad224c8d
|
|||
|
43dcdf4e6a
|
|||
|
9e3f7e2714
|
|||
|
4982175342
|
|||
|
65ff23e406
|
|||
|
a07e4ad9cc
|
|||
|
4d813c6c2c
|
|||
|
9b0b9baf16
|
|||
|
9edbcc0bc2
|
|||
|
12bff5848a
|
|||
|
1bb5151fce
|
|||
|
75c6af122f
|
|||
|
da36606af3
|
|||
|
c3a689a007
|
|||
|
b0ed748712
|
|||
|
08a5b44660
|
|||
|
c80856f3c5
|
|||
|
70737658c7
|
|||
|
ebf0c6d970
|
|||
|
c92cefa903
|
|||
|
63e4270c89
|
|||
|
721edb71a1
|
|||
|
8f20452e1a
|
|||
|
de58630958
|
|||
|
f61b2b4535
|
|||
|
6863d64112
|
|||
|
aa52473f90
|
|||
|
465e47fc10
|
|||
|
3a721987dd
|
|||
|
2792753d3d
|
|||
|
af6184d581
|
|||
|
40a3cdabc9
|
|||
|
08e6af2eae
|
|||
|
09332aca24
|
|||
| b161f926a9 | |||
|
c406d6226c
|
|||
| 74fd2bf32c | |||
|
377300d288
|
|||
|
83cc9be24c
|
|||
| 4eaf354912 | |||
|
c9a8e0746a
|
|||
|
07cca921bf
|
|||
| cd980f2af9 | |||
|
0e02c8ab15
|
|||
|
01cb2818ff
|
|||
| 67c84a7254 | |||
| 5b15fcd60f | |||
|
1e1eac9dd6
|
|||
| 0d2ffe0f54 | |||
|
991dc32ce4
|
|||
|
d6a72ace83
|
|||
|
7a0d5dc48c
|
|||
|
4ed4b6e5f4
|
|||
|
4499e20e77
|
|||
|
fbc1e55e5c
|
|||
|
653fc7d52f
|
|||
|
84881edb61
|
|||
|
c8b1b72694
|
|||
|
73cd1d794a
|
|||
|
28ac23d8f2
|
|||
|
71b7519a53
|
|||
|
28ee1a9d1e
|
|||
|
f327c6e06e
|
|||
|
799ff00f9c
|
|||
|
369e3f4b5c
|
|||
|
3788de2609
|
|||
|
0f9aafe418
|
|||
|
13b90e9ee6
|
|||
|
6e19a6217d
|
|||
|
34fd4e7304
|
|||
|
5e04012aa4
|
|||
|
e8f2928543
|
|||
|
91a3b2fabf
|
|||
|
964b9a03ef
|
|||
|
bf693645d4
|
|||
|
082b4826c2
|
|||
|
e68c3002d8
|
|||
|
30d2f4a644
|
|||
|
875a45f2b8
|
|||
|
6bf7afbe09
|
|||
|
5c94dbbff5
|
|||
|
cb44eb1fab
|
|||
|
df63d7947f
|
|||
|
01a5ff907c
|
|||
|
e22e3d8bc3
|
|||
|
efecd78355
|
|||
|
ed4246ba0e
|
|||
|
4acc228fe3
|
|||
|
42279b0592
|
|||
|
e417ab64d8
|
|||
|
93b11c3a35
|
|||
|
1ef2c4919e
|
|||
|
6ff8f74317
|
|||
|
bf70ca98f3
|
|||
|
52e5befd93
|
|||
|
a047b49073
|
|||
|
59b20578bb
|
|||
|
cdd6c6a72a
|
|||
|
1d16473d2d
|
|||
|
cd2bef9811
|
|||
|
62118b6d64
|
|||
|
8290b332fb
|
|||
|
61236719f4
|
|||
|
aa699d5009
|
|||
|
9a4f9cdf4c
|
|||
|
5532fc51a9
|
|||
|
99db648a36
|
|||
|
adcab6afcb
|
|||
|
8e40c0a06c
|
|||
|
db5e4858b8
|
|||
|
d800311ae7
|
|||
|
32fdde5d90
|
163
.drone.yml
163
.drone.yml
@@ -3,7 +3,7 @@ type: docker
|
|||||||
name: Test Pipeline
|
name: Test Pipeline
|
||||||
|
|
||||||
workspace:
|
workspace:
|
||||||
path: /drone/grow
|
path: /drone/auth
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: yarn install
|
- name: yarn install
|
||||||
@@ -60,18 +60,17 @@ steps:
|
|||||||
trigger:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
- main
|
- main
|
||||||
|
- develop
|
||||||
event:
|
event:
|
||||||
- pull_request
|
- pull_request
|
||||||
- push
|
|
||||||
|
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: Publish Pipeline
|
name: Publish Pipeline
|
||||||
group: publish
|
|
||||||
|
|
||||||
workspace:
|
workspace:
|
||||||
path: /drone/grow
|
path: /drone/auth
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Build Package
|
- name: Build Package
|
||||||
@@ -80,19 +79,13 @@ steps:
|
|||||||
- yarn install
|
- yarn install
|
||||||
- yarn build
|
- yarn build
|
||||||
- name: Publish NPM
|
- name: Publish NPM
|
||||||
image: plugins/npm
|
image: node:20-alpine
|
||||||
failure: ignore
|
failure: ignore
|
||||||
settings:
|
commands:
|
||||||
username:
|
- yarn publish -t ${DRONE_TAG}
|
||||||
from_secret: registry_username
|
|
||||||
password:
|
|
||||||
from_secret: registry_password
|
|
||||||
registry: https://git.mifi.dev/api/packages/mifi/npm
|
|
||||||
token:
|
|
||||||
- from_secret: gitea_token
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: npmrc
|
- name: npmrc
|
||||||
path: /drone/grow/.npmrc
|
path: /drone/auth/.npmrc
|
||||||
- name: Report NPM Publish Status
|
- name: Report NPM Publish Status
|
||||||
image: plugins/webhook
|
image: plugins/webhook
|
||||||
settings:
|
settings:
|
||||||
@@ -109,34 +102,18 @@ steps:
|
|||||||
- success
|
- success
|
||||||
- failure
|
- failure
|
||||||
- name: Publish Image
|
- name: Publish Image
|
||||||
image: docker
|
image: plugins/docker
|
||||||
commands:
|
settings:
|
||||||
- docker build -t git.mifi.dev/mifi/mifi/auth:latest -t git.mifi.dev/mifi/mifi/auth:${DRONE_TAG} .
|
auto_tag: true
|
||||||
- docker push git.mifi.dev/mifi/mifi/auth:latest
|
repo: git.mifi.dev/mifi/mifi/auth
|
||||||
volumes:
|
registry: git.mifi.dev
|
||||||
- name: dockersock
|
debug: true
|
||||||
path: /var/run/docker.sock
|
ssh-agent-key:
|
||||||
- name: dockerconfig
|
from_secret: reg_token
|
||||||
path: /drone/grow/.docker/config.json
|
username: <token>
|
||||||
# - name: Publish Image
|
password:
|
||||||
# image: plugins/docker
|
from_secret: reg_token
|
||||||
# settings:
|
secrets: [reg_token]
|
||||||
# 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:
|
|
||||||
- name: dockersock
|
|
||||||
path: /var/run/docker.sock
|
|
||||||
- name: dockerconfig
|
|
||||||
path: /drone/grow/.docker/config.json
|
|
||||||
- name: Report Image Publish Status
|
- name: Report Image Publish Status
|
||||||
image: plugins/webhook
|
image: plugins/webhook
|
||||||
settings:
|
settings:
|
||||||
@@ -168,36 +145,36 @@ depends_on:
|
|||||||
- Test Pipeline
|
- Test Pipeline
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
# branch:
|
|
||||||
# - main
|
|
||||||
event:
|
event:
|
||||||
# - push
|
|
||||||
- tag
|
- tag
|
||||||
|
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: Deploy Pipeline
|
name: Staging Deploy Pipeline
|
||||||
|
|
||||||
workspace:
|
workspace:
|
||||||
path: /drone/grow
|
path: /drone/auth
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Deploy Container
|
- name: Deploy Container
|
||||||
image: docker
|
image: docker
|
||||||
privileged: true
|
privileged: true
|
||||||
|
environment:
|
||||||
|
CONTAINER_PREFIX: staging
|
||||||
|
HOST: area51.mifi.dev
|
||||||
|
ROUTE_PREFIX: /auth
|
||||||
|
PORT: 9001
|
||||||
commands:
|
commands:
|
||||||
- docker compose -f docker-compose.staging.yml pull
|
- docker compose -f docker-compose.staging-build.yml build --pull --no-cache
|
||||||
- docker compose -f docker-compose.staging.yml build --no-cache
|
- docker compose -f docker-compose.staging-build.yml up --remove-orphans --force-recreate --wait
|
||||||
- docker compose -f docker-compose.staging.yml rm --stop
|
|
||||||
- docker compose -f docker-compose.staging.yml up --wait
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: env
|
- name: env-secrets
|
||||||
path: /drone/grow/staging.env
|
path: /drone/auth/staging.env
|
||||||
- name: dockersock
|
- name: dockersock
|
||||||
path: /var/run/docker.sock
|
path: /var/run/docker.sock
|
||||||
- name: dockerconfig
|
- name: dockerconfig
|
||||||
path: /drone/grow/.docker/config.json
|
path: /drone/auth/.docker/config.json
|
||||||
- name: Send Status Notifications
|
- name: Send Status Notifications
|
||||||
image: plugins/webhook
|
image: plugins/webhook
|
||||||
privileged: true
|
privileged: true
|
||||||
@@ -222,7 +199,7 @@ 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/beethoven/labs-auth/staging.env
|
path: /volume1/docker/beethoven/labs-auth/staging.env
|
||||||
|
|
||||||
@@ -230,8 +207,76 @@ depends_on:
|
|||||||
- Test Pipeline
|
- Test Pipeline
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
# branch:
|
branch:
|
||||||
# - main
|
- develop
|
||||||
event:
|
event:
|
||||||
# - push
|
- push
|
||||||
- tag
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: Production Deploy Pipeline
|
||||||
|
|
||||||
|
workspace:
|
||||||
|
path: /drone/auth
|
||||||
|
|
||||||
|
clone:
|
||||||
|
disable: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Deploy Container
|
||||||
|
image: docker
|
||||||
|
privileged: true
|
||||||
|
environment:
|
||||||
|
CONTAINER_PREFIX: staging
|
||||||
|
HOST: area51.mifi.dev
|
||||||
|
ROUTE_PREFIX: /auth
|
||||||
|
PORT: 9001
|
||||||
|
commands:
|
||||||
|
- docker compose -f docker-compose.production-build.yml pull
|
||||||
|
- docker compose -f docker-compose.production-build.yml build --no-cache
|
||||||
|
- docker compose -f docker-compose.production-build.yml rm --stop
|
||||||
|
- docker compose -f docker-compose.production-build.yml up --wait
|
||||||
|
volumes:
|
||||||
|
- name: env-secrets
|
||||||
|
path: /drone/auth/production.env
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
- name: dockerconfig
|
||||||
|
path: /drone/auth/.docker/config.json
|
||||||
|
- name: Send Status Notifications
|
||||||
|
image: plugins/webhook
|
||||||
|
privileged: true
|
||||||
|
settings:
|
||||||
|
urls: https://lab.mifi.dev/hooks/ccw34hdf7tgbjmzp96nptn938r
|
||||||
|
content_type: application/json
|
||||||
|
template: |
|
||||||
|
{
|
||||||
|
"icon_url":"https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/apple/198/freezing-face_1f976.png",
|
||||||
|
"text": "[{{ repo.name }} - Build # {{ build.number }}] Deploy {{ build.status }} {{#success build.status}}:tada:{{else}}:poop:{{/success}}",
|
||||||
|
"username":"DroneBot"
|
||||||
|
}
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- success
|
||||||
|
- failure
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: dockerconfig
|
||||||
|
host:
|
||||||
|
path: /volume1/docker/dockerconfig.json
|
||||||
|
- name: dockersock
|
||||||
|
host:
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
- name: env-secrets
|
||||||
|
host:
|
||||||
|
path: /volume1/docker/beethoven/labs-auth/staging.env
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- Test Pipeline
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
event:
|
||||||
|
- promote
|
||||||
|
target:
|
||||||
|
- production
|
||||||
@@ -6,14 +6,14 @@ ROUTE_PREFIX=/auth
|
|||||||
LOGIN_ROUTE=/login
|
LOGIN_ROUTE=/login
|
||||||
RESET_ROUTE=/reset
|
RESET_ROUTE=/reset
|
||||||
|
|
||||||
DB_ADMIN_USERNAME=root
|
# DB_ADMIN_USERNAME=root
|
||||||
DB_ADMIN_PASSWORD=password
|
# DB_ADMIN_PASSWORD=password
|
||||||
DB_USERNAME=user
|
DB_USERNAME=user
|
||||||
DB_PASSWORD=password
|
DB_PASSWORD=password
|
||||||
DB_NAME=auth
|
DB_NAME=auth
|
||||||
|
|
||||||
MONGO_INITDB_ROOT_USERNAME=$DB_ADMIN_USERNAME
|
MONGO_INITDB_ROOT_USERNAME=$DB_USERNAME
|
||||||
MONGO_INITDB_ROOT_PASSWORD=$DB_ADMIN_PASSWORD
|
MONGO_INITDB_ROOT_PASSWORD=$DB_PASSWORD
|
||||||
MONGO_INITDB_DATABASE=$DB_NAME
|
MONGO_INITDB_DATABASE=$DB_NAME
|
||||||
|
|
||||||
SESSION_KEY=shjhakjfhfjdshjksdhfdshfhfduyeyb73te4
|
SESSION_KEY=shjhakjfhfjdshjksdhfdshfhfduyeyb73te4
|
||||||
@@ -28,4 +28,4 @@ DEFAULT_TOKEN_DAYS=1
|
|||||||
|
|
||||||
CONTAINER_PREFIX=dev
|
CONTAINER_PREFIX=dev
|
||||||
SERVICE_NAME=auth-service
|
SERVICE_NAME=auth-service
|
||||||
DB_TYPE=mongo
|
ENV=development
|
||||||
26
Dockerfile
26
Dockerfile
@@ -1,28 +1,28 @@
|
|||||||
# FROM node:20-alpine AS build
|
ARG ENV=production
|
||||||
# RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
|
ARG MONGO_VERSION=latest
|
||||||
# WORKDIR /home/node/app
|
ARG PORT=9001
|
||||||
# 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"]
|
|
||||||
|
|
||||||
|
## mongo build stage
|
||||||
|
FROM mongo:$MONGO_VERSION AS database
|
||||||
|
COPY mongo-init.sh /docker-entrypoint-initdb.d
|
||||||
|
|
||||||
|
## stage one, build the service
|
||||||
FROM node:20-alpine AS build
|
FROM node:20-alpine AS build
|
||||||
|
ENV NODE_ENV development
|
||||||
WORKDIR /home/node/app
|
WORKDIR /home/node/app
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
COPY tsconfig.json ./
|
COPY tsconfig.json ./
|
||||||
COPY lib ./lib
|
COPY lib ./lib
|
||||||
RUN ls -a
|
RUN ls -a
|
||||||
RUN yarn install
|
RUN yarn install
|
||||||
RUN yarn build:production
|
RUN yarn build
|
||||||
|
|
||||||
## this is stage two , where the app actually runs
|
## this is stage two , where the app actually runs
|
||||||
FROM node:20-alpine AS containerize
|
FROM node:20-alpine AS containerize
|
||||||
|
ENV NODE_ENV $ENV
|
||||||
WORKDIR /home/node/app
|
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=build /home/node/app/dist .
|
||||||
EXPOSE 9001
|
EXPOSE $PORT
|
||||||
EXPOSE 27017
|
|
||||||
CMD ["node","server/index.js"]
|
CMD ["node","server/index.js"]
|
||||||
|
|||||||
@@ -2,27 +2,32 @@ version: '3.8'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
auth-service_mongo:
|
auth-service_mongo:
|
||||||
env_file: dev.env
|
env_file: .env.dev
|
||||||
container_name: ${CONTAINER_PREFIX:-dev}-auth-service_mongo
|
container_name: ${CONTAINER_PREFIX}-auth-service_mongo
|
||||||
ports:
|
ports:
|
||||||
- 27017:27017
|
- 27017:27017
|
||||||
networks:
|
networks:
|
||||||
- labs-net
|
- backend
|
||||||
volumes:
|
volumes:
|
||||||
- /var/tmp/labs:/data/db
|
- auth-db:/data/db
|
||||||
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
|
- auth-db:/data/configdb
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
image: mongo:latest
|
image: mongo:latest
|
||||||
auth-service:
|
auth-service:
|
||||||
env_file: dev.env
|
env_file: .env.dev
|
||||||
build: .
|
build:
|
||||||
container_name: ${CONTAINER_PREFIX:-dev}-auth-service
|
context: .
|
||||||
|
args:
|
||||||
|
- PORT
|
||||||
|
- ENV
|
||||||
|
container_name: ${CONTAINER_PREFIX}-auth-service
|
||||||
ports:
|
ports:
|
||||||
- 9001:9001
|
- 9001:9001
|
||||||
environment:
|
environment:
|
||||||
- DB_HOST=${CONTAINER_PREFIX:-dev}-auth-service_mongo
|
- DB_HOST=${CONTAINER_PREFIX}-auth-service_mongo
|
||||||
networks:
|
networks:
|
||||||
- labs-net
|
- labs-net
|
||||||
|
- backend
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
image: node:20-alpine
|
image: node:20-alpine
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -30,3 +35,7 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
labs-net:
|
labs-net:
|
||||||
name: labs-net
|
name: labs-net
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
auth-db:
|
||||||
|
external: true
|
||||||
|
|||||||
58
docker-compose.staging-build.yml
Normal file
58
docker-compose.staging-build.yml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
auth-service_mongo:
|
||||||
|
container_name: ${CONTAINER_PREFIX}-auth-service_mongo
|
||||||
|
env_file:
|
||||||
|
- staging.env
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
target: database
|
||||||
|
args:
|
||||||
|
MONGO_VERSION: 4.4
|
||||||
|
networks:
|
||||||
|
- auth-backend
|
||||||
|
volumes:
|
||||||
|
- 'auth-db:/data/db'
|
||||||
|
- 'auth-db:/data/configdb'
|
||||||
|
restart: unless-stopped
|
||||||
|
image: mongo:4.4
|
||||||
|
auth-service:
|
||||||
|
container_name: ${CONTAINER_PREFIX}-auth-service
|
||||||
|
env_file:
|
||||||
|
- staging.env
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
target: containerize
|
||||||
|
args:
|
||||||
|
- PORT
|
||||||
|
- ENV
|
||||||
|
environment:
|
||||||
|
- DB_HOST=${CONTAINER_PREFIX}-auth-service_mongo
|
||||||
|
labels:
|
||||||
|
- 'traefik.enable=true'
|
||||||
|
- 'traefik.docker.network=docknet'
|
||||||
|
- 'traefik.http.routers.labs-auth.rule=Host(`${HOST}`) && Path(`${ROUTE_PREFIX}`)'
|
||||||
|
- 'traefik.http.routers.labs-auth.entrypoints=websecure'
|
||||||
|
- 'traefik.http.routers.labs-auth.tls=true'
|
||||||
|
- 'traefik.http.routers.labs-auth.tls.certresolver=letsencrypt'
|
||||||
|
- 'traefik.http.routers.labs-auth.service=labs-auth-service'
|
||||||
|
- 'traefik.http.services.labs-auth-service.loadbalancer.server.port=${PORT}'
|
||||||
|
networks:
|
||||||
|
- auth-backend
|
||||||
|
- docknet
|
||||||
|
restart: unless-stopped
|
||||||
|
image: node:20-alpine
|
||||||
|
depends_on:
|
||||||
|
- auth-service_mongo
|
||||||
|
networks:
|
||||||
|
auth-backend:
|
||||||
|
driver: bridge
|
||||||
|
external: false
|
||||||
|
docknet:
|
||||||
|
name: docknet
|
||||||
|
external: true
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
auth-db:
|
||||||
|
external: false
|
||||||
@@ -2,20 +2,22 @@ version: '3.8'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
auth-service_mongo:
|
auth-service_mongo:
|
||||||
container_name: ${CONTAINER_PREFIX:-mifi}-auth-service_mongo
|
container_name: ${CONTAINER_PREFIX}-auth-service_mongo
|
||||||
env_file: staging.env
|
env_file:
|
||||||
|
- staging.env
|
||||||
networks:
|
networks:
|
||||||
- docknet
|
- docknet
|
||||||
volumes:
|
volumes:
|
||||||
- '/volume1/docker/labs/auth/mongo:/data/db'
|
- auth-db:/data
|
||||||
|
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
image: mongo:latest
|
image: mongo:4.4
|
||||||
auth-service:
|
auth-service:
|
||||||
env_file: staging.env
|
env_file:
|
||||||
build: .
|
- staging.env
|
||||||
container_name: ${CONTAINER_PREFIX:-mifi}-auth-service
|
container_name: ${CONTAINER_PREFIX}-auth-service
|
||||||
environment:
|
environment:
|
||||||
- DB_HOST=${CONTAINER_PREFIX:-mifi}-auth-service_mongo
|
- DB_HOST=${CONTAINER_PREFIX}-auth-service_mongo
|
||||||
labels:
|
labels:
|
||||||
- 'traefik.enable=true'
|
- 'traefik.enable=true'
|
||||||
- 'traefik.http.routers.grow.rule=Host(`${HOST}`) && Path(`${ROUTE_PREFIX}`)'
|
- 'traefik.http.routers.grow.rule=Host(`${HOST}`) && Path(`${ROUTE_PREFIX}`)'
|
||||||
@@ -27,10 +29,15 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- docknet
|
- docknet
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
image: node:20-alpine
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- auth-service_mongo
|
- auth-service_mongo
|
||||||
|
image: git.mifi.dev/mifi/mifi/auth:latest
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
docknet:
|
docknet:
|
||||||
name: docknet
|
name: docknet
|
||||||
external: true
|
external: true
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
auth-db:
|
||||||
|
external: false
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
export const DB_HOST = process.env.DB_HOST || 'not_set';
|
export const DB_HOST = process.env.DB_HOST;
|
||||||
export const DB_PORT = process.env.DB_PORT || 27017;
|
export const DB_PORT = process.env.DB_PORT || 27017;
|
||||||
export const DB_USERNAME = process.env.DB_USERNAME || 'not_set';
|
export const DB_USERNAME = process.env.DB_USERNAME;
|
||||||
export const DB_PASSWORD = process.env.DB_PASSWORD || 'not_set';
|
export const DB_PASSWORD = process.env.DB_PASSWORD;
|
||||||
export const DB_NAME = process.env.DB_NAME || 'not_set';
|
export const DB_NAME = process.env.DB_NAME;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import Auth from '../../db/model/auth';
|
|||||||
import { sign } from '../../utils/jwt';
|
import { sign } from '../../utils/jwt';
|
||||||
import passport from '../passport';
|
import passport from '../passport';
|
||||||
import { ErrorCodes, getErrorBody } from '../../constants/errors';
|
import { ErrorCodes, getErrorBody } from '../../constants/errors';
|
||||||
|
import { authenticated } from '../middleware/authenication';
|
||||||
|
|
||||||
const routerOpts: Router.IRouterOptions = { prefix };
|
const routerOpts: Router.IRouterOptions = { prefix };
|
||||||
const router: Router = new Router(routerOpts);
|
const router: Router = new Router(routerOpts);
|
||||||
@@ -43,7 +44,10 @@ router.post(process.env.RESET_ROUTE || RESET_ROUTE, async (ctx, next) => {
|
|||||||
ctx.body = { success: false, ...getErrorBody(ErrorCodes.RESET_REQUEST_DATA) };
|
ctx.body = { success: false, ...getErrorBody(ErrorCodes.RESET_REQUEST_DATA) };
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch('/:record', (ctx: Koa.Context) => {
|
router.patch('/:record', authenticated(), (ctx: Koa.Context) => {
|
||||||
|
if (ctx.user !== ctx.param.record) {
|
||||||
|
ctx.throw(StatusCodes.UNAUTHORIZED);
|
||||||
|
}
|
||||||
const data = Auth.findOneAndUpdate({ record: ctx.params.record });
|
const data = Auth.findOneAndUpdate({ record: ctx.params.record });
|
||||||
if (!data) {
|
if (!data) {
|
||||||
ctx.throw(StatusCodes.NOT_FOUND);
|
ctx.throw(StatusCodes.NOT_FOUND);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { PORT } from '../constants/env';
|
|||||||
connection.then(
|
connection.then(
|
||||||
() => {
|
() => {
|
||||||
app.listen(PORT);
|
app.listen(PORT);
|
||||||
console.log('LISTENING', process.env);
|
console.debug('Server up and listening', { env: process.env });
|
||||||
},
|
},
|
||||||
(err) => console.error('SERVER ERROR!', { err, env: process.env }),
|
(err) => console.error('Could not reach database', { err, env: process.env }),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
/* 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,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
14
mongo-init.sh
Normal file
14
mongo-init.sh
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
set -e
|
||||||
|
|
||||||
|
mongo <<EOF
|
||||||
|
use $MONGO_INITDB_DATABASE
|
||||||
|
|
||||||
|
db.createUser({
|
||||||
|
user: '$DB_USERNAME',
|
||||||
|
pwd: '$DB_PASSWORD',
|
||||||
|
roles: [{
|
||||||
|
role: 'readWrite',
|
||||||
|
db: '$MONGO_INITDB_DATABASE'
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
EOF
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mifi/auth",
|
"name": "@mifi/auth",
|
||||||
"version": "0.0.28",
|
"version": "0.0.38",
|
||||||
"author": "mifi (Mike Fitzpatrick)",
|
"author": "mifi (Mike Fitzpatrick)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user