diff --git a/Dockerfile b/Dockerfile index 4efb832..fcf0475 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,8 @@ +## mongo build stage +FROM mongo:${MONGO_VERSION:-latest} AS database +WORKDIR / +COPY mongo-init.js ./docker-entrypoint-initdb.d/ + ## stage one, build the service FROM node:20-alpine AS build ENV NODE_ENV development @@ -10,11 +15,11 @@ RUN yarn install RUN yarn build ## this is stage two , where the app actually runs -FROM node:20-alpine AS auth-service +FROM node:20-alpine AS containerize ENV NODE_ENV ${ENV:-production} WORKDIR /home/node/app COPY package*.json ./ RUN yarn install --frozen-lockfile --production -COPY --from=0 /home/node/app/dist . +COPY --from=build /home/node/app/dist . EXPOSE ${PORT:-9001} CMD ["node","server/index.js"] diff --git a/docker-compose.staging-build.yml b/docker-compose.staging-build.yml index 9a62249..00c0de6 100644 --- a/docker-compose.staging-build.yml +++ b/docker-compose.staging-build.yml @@ -5,24 +5,29 @@ services: container_name: ${CONTAINER_PREFIX:-staging}-auth-service_mongo env_file: - staging.env + build: + context: . + target: database + args: + - MONGO_VERSION networks: - docknet volumes: - 'auth-db:/data/db' - 'auth-db:/data/configdb' - - './mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro' # - '/volume1/docker/beethoven/labs-auth/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro' restart: unless-stopped - image: mongo:4.4 + image: mongo:${MONGO_VERSION:-latest} auth-service: + container_name: ${CONTAINER_PREFIX:-staging}-auth-service env_file: - staging.env build: context: . + target: containerize args: - PORT - ENV - container_name: ${CONTAINER_PREFIX:-staging}-auth-service environment: - DB_HOST=${CONTAINER_PREFIX:-staging}-auth-service_mongo labels: diff --git a/mongo-init.js b/mongo-init.js index 56542b7..9a282c6 100644 --- a/mongo-init.js +++ b/mongo-init.js @@ -1,5 +1,5 @@ /* eslint-disable no-undef */ -db = db.getSiblingDB(process.env.DB_NAME); +//db = db.getSiblingDB(process.env.DB_NAME); db.createUser({ user: process.env.DB_USERNAME, pwd: process.env.DB_PASSWORD,