This commit is contained in:
Kfir Dayan 2023-06-11 01:22:34 +03:00
parent 84af08450e
commit 47dcaabc5c
5 changed files with 37 additions and 7 deletions

2
.dockerignore Normal file
View file

@ -0,0 +1,2 @@
node_modules
npm-debug.log

13
Dockerfile Normal file
View file

@ -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"]

View file

@ -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:
structshare_vol:

View file

@ -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",

View file

@ -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);