From 47dcaabc5c5747ae65e43215f917a4fd91dda89c Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Sun, 11 Jun 2023 01:22:34 +0300 Subject: [PATCH] docker --- .dockerignore | 2 ++ Dockerfile | 13 +++++++++++++ docker-compose.yaml | 23 +++++++++++++++++++---- package.json | 3 ++- src/index.ts | 3 +-- 5 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5171c54 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d471987 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node:14-alpine + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install --production + +COPY . . + +EXPOSE 3000 + +CMD ["node", "dist/index.js"] diff --git a/docker-compose.yaml b/docker-compose.yaml index b205fe9..31c371f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,5 +1,20 @@ version: '3' services: + app: + build: + context: . + dockerfile: Dockerfile + ports: + - 3000:3000 + volumes: + - ./src:/app/src + - ./dist:/app/dist + environment: + - DB_DATABASE=your-database-name + - DB_USERNAME=your-username + - DB_PASSWORD=your-password + depends_on: + - mongodb mongodb: image: arm64v8/mongo:4.0 restart: always @@ -9,11 +24,11 @@ services: - structshare_vol:/data/db - ./init-scripts/init.js:/docker-entrypoint-initdb.d/mongo-init.js environment: - - MONGO_INITDB_DATABASE=${DB_DATABASE} - - MONGO_INITDB_ROOT_USERNAME=${DB_USERNAME} - - MONGO_INITDB_ROOT_PASSWORD=${DB_PASSWORD} + - MONGO_INITDB_DATABASE=your-database-name + - MONGO_INITDB_ROOT_USERNAME=your-username + - MONGO_INITDB_ROOT_PASSWORD=your-password platform: linux/arm64/v8 expose: - 27017 volumes: - structshare_vol: \ No newline at end of file + structshare_vol: diff --git a/package.json b/package.json index 9e4917b..7eab16f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "dev": "nodemon dist/index.js", - "start": "node dist/index.js" + "start": "node dist/index.js", + "build": "tsc -p ." }, "author": "", "license": "ISC", diff --git a/src/index.ts b/src/index.ts index 20d830c..ec1dc24 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,12 +9,11 @@ import cartRouter from './routes/cart'; const env = require('dotenv').config().parsed; const app = express(); -const PORT = 3000; +const PORT = env.PORT || 3000; app.use(express.json()); app.use(cookieParser()) - // Connect to MongoDB using Mongoose mongoose.connect(env.DATABASE_URL);