From 2d4030dc12e67cd2528f23062e7e74915a89c2d4 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 24 Jul 2022 15:15:17 -0400 Subject: [PATCH 1/2] Optimization of Docker for current workflow. --- .dockerignore | 6 +++++- .env | 8 -------- .env.example | 8 -------- .gitignore | 4 ++-- Dockerfile | 6 +----- docker-compose.override.yml.example | 30 +++++++++++++++++++++++++++++ docker-compose.yml | 25 ++++-------------------- start.sh | 3 +++ 8 files changed, 45 insertions(+), 45 deletions(-) delete mode 100644 .env delete mode 100644 .env.example create mode 100644 docker-compose.override.yml.example create mode 100755 start.sh diff --git a/.dockerignore b/.dockerignore index 649fffa..8f884a7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,7 @@ node_modules npm-debug.log -.git \ No newline at end of file +.git +docker-compose* +.dockerignore +.gitignore +Dockerfile diff --git a/.env b/.env deleted file mode 100644 index d97b5d7..0000000 --- a/.env +++ /dev/null @@ -1,8 +0,0 @@ -SERVICE_PORT=3000 - -# Database connection -DB_USER='postgres' -DB_HOST='rdb.dev.pull.dating' -DB_NAME='pulldevwill' -DB_PASSWORD='sWkLEYkPuVUQbj4cnLFrVPDBjqHbdN' -DB_PORT=5432 \ No newline at end of file diff --git a/.env.example b/.env.example deleted file mode 100644 index 6e40cbc..0000000 --- a/.env.example +++ /dev/null @@ -1,8 +0,0 @@ -SERVICE_PORT=8080 - -# Database connection -DB_USER='postgres' -DB_URL='db' -DB_NAME='postgres' -DB_PASSWORD='postgres' -DB_PORT=5432 \ No newline at end of file diff --git a/.gitignore b/.gitignore index ced041e..a441f36 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules -.env +docker-compose.override.yml src/config/.env.development -config.ts \ No newline at end of file +config.ts diff --git a/Dockerfile b/Dockerfile index 7c41a9f..099eacc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,12 +2,8 @@ FROM node:18-alpine WORKDIR /usr/src/app -COPY ["package.json", "package-lock.json", "tsconfig.json", ".env", "./"] - -RUN npm install - COPY . . EXPOSE 3000 -CMD ["npm", "start"] \ No newline at end of file +CMD ["./start.sh"] diff --git a/docker-compose.override.yml.example b/docker-compose.override.yml.example new file mode 100644 index 0000000..24c3dfb --- /dev/null +++ b/docker-compose.override.yml.example @@ -0,0 +1,30 @@ +version: "3.9" + +x-environment: &environment + environment: + SERVICE_PORT: 3000 + # Database connection + DB_USER: 'postgres' + DB_URL: 'postgres' + DB_NAME: 'postgres' + DB_PASSWORD: 'postgres' + DB_ROOT_PASSWORD: 'postgres' + DB_PORT: 5432 + POSTGRES_PASSWORD: 'postgres' +services: + api: + ports: + - 3000:3000 + volumes: + - .:/usr/src/app + <<: *environment + + postgres: + ports: + - "5432:5432" + volumes: + - data:/var/lib/postgresql/data + <<: *environment + +volumes: + data: {} diff --git a/docker-compose.yml b/docker-compose.yml index 2f5eda7..5cfee90 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,27 +1,10 @@ -version: "3.8" +version: "3.9" services: api: - container_name: api-gateway - restart: always build: . - ports: - - ${SERVICE_PORT}:${SERVICE_PORT} + image: pulldating/apigateway:latest depends_on: - db - volumes: - - .:/usr/src/app - db: - container_name: postgres - image: postgres - ports: - - "4321:${DB_PORT}" - volumes: - - data:/data/db - environment: - - POSTGRES_PASSWORD=${DB_PASSWORD} - - POSTGRES_USER=${DB_USER} - - POSTGRES_DB=${DB_NAME} - -volumes: - data: {} + postgres: + image: postgres:latest diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..8cc8eba --- /dev/null +++ b/start.sh @@ -0,0 +1,3 @@ +#!/bin/sh +npm install +npm start From 958e2869daecf21c9655a649ce8026e87a033540 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 24 Jul 2022 15:17:41 -0400 Subject: [PATCH 2/2] fixup --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e75cc5..ad1f920 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,13 @@ Create .env file in format of the .env.example run "npm install" # Run on docker -docker-compose up --build -d \ No newline at end of file + +`cp docker-compose.override.yml.example docker-compose.override.yml` + +Then modify your local copy of `docker-compose.override.yml` to suit your local testing environment. + +`docker-compose up --build -d` + +Then you can run the following to boot the container stack and view its console to follow logs and debug. + +`docker-compose up -d && docker-compose logs -f`