Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules
package-lock.json
uploads/*
access.log
env.list.mongo
.env
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ package-lock.json
uploads/*
.env
access.log
env.list.mongo
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:10

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non c faux

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok bb ❤️


WORKDIR /app

COPY package.json ./

RUN npm install

COPY . .

EXPOSE 3001

RUN npm install -g nodemon

RUN ls -l

CMD [ "nodemon", "index.js" ]
3 changes: 3 additions & 0 deletions Dockerfile.sample.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM mongo:latest
VOLUME ~/Bureau/docker_test/mongo/data
EXPOSE 27017
4 changes: 4 additions & 0 deletions db-fixture/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM mongo

COPY fixture.json /fixture.json
CMD mongoimport --host mongo --db sopptas --collection users --type json --file /fixture.json --jsonArray
1 change: 1 addition & 0 deletions db-fixture/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This containers sole purpose is to import seed data into the database.
27 changes: 27 additions & 0 deletions db-fixture/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[{
"_id": {
"$oid": "5fda0575a14be43064171366"
},
"reclamations": [],
"role": "citizen",
Comment thread
amineb01 marked this conversation as resolved.
"name": "amine",
"email": "bellarej.amine2@gmail.com",
"password": "$2b$10$nsEYX0Yfd5y1JYQMX6hOd.P2ar6wmL0u/i1RFVlFN1B1h0drS7aoG",
"__v": {
"$numberInt": "0"
}
},
{
"_id": {
"$oid": "5fdce021f5cb9566fbb2fce6"
},
"reclamations": [],
"role": "admin",
"name": "amine",
"email": "bellarej.amine@gmail.com",
"password": "$2b$10$scQsaHRWmu3L5WuQ9iFLbOfQ1qJ9Q3O6j0JbbRBfp4tRttKKduz9a",
"__v": {
"$numberInt": "0"
}
}
]
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: "3"
services:
app:
container_name: express-mongo
restart: always
build: ./
ports:
- "3001:3001"
volumes:
- ./models:/app/models
- ./middlewares:/app/middlewares
- ./controllers:/app/controllers
links:
- mongo
env_file:
- .env
depends_on:
- mongo
mongo:
container_name: mongo
image: mongo
ports:
- "27017:27017"
volumes:
- /home/dev/Bureau/docker_test/mongo/data:/data/db

db-fixture:
build: ./db-fixture
container_name: db-fixture
links:
- mongo
depends_on:
- mongo
11 changes: 7 additions & 4 deletions helpers/dbConnect.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
const mongoose = require('mongoose');
let config = require('config');
const db_name = config.DBHost
const db_server = 'localhost'

mongoose.connect(`mongodb://${db_server}/${db_name}`, {
const dotenv = require('dotenv');
dotenv.config();
const db_name = config.DBHost

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non c pas ca bb

const db_server = process.env.DB_SERVER
const db_port = process.env.DB_PORT
mongoose.connect(`mongodb://${db_server}:${db_port}/${db_name}`, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
}).then(response => console.log(`connect to ${db_name} database successfully`))
}).then(response => console.log(`connect01 to ${db_name} database successfully`))
.catch(err => console.log('could not connect '+err))

module.exports = mongoose
1 change: 1 addition & 0 deletions helpers/sendMail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const nodeMailer = require("nodemailer");
const dotenv = require('dotenv');
dotenv.config();

const transporter = nodeMailer.createTransport({
service: 'gmail',
// by defaukt gmail don't allow us to use authentification like this
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ dotenv.config();

const hostname = process.env.SERVER || '127.0.0.1';
const port = process.env.PORT || 3000;

app.get('/', (req, res) =>{
res.send("it's working :)")
})
const server = http.createServer(app);

server.listen(port, hostname, () => {
Expand Down
12 changes: 12 additions & 0 deletions run-with-docker.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
run mongo container
with envirement variable:
sudo docker run -d --name mongo-on-docker -p 27017:27017
-v ~/Bureau/docker_test/mongo/data:/data/db
-e MONGO_INITDB_ROOT_USERNAME=amine -e MONGO_INITDB_ROOT_PASSWORD=amine
mongo
with envirement variable file:
sudo docker run -d --name mongo-on-docker -p 27017:27017
-v ~/Bureau/docker_test/mongo/data:/data/db
--env-file ./env.list.mongo mongo
with custom image:
sudo docker run -d --name mongo-on-docker -p 27017:27017 testmongo:v1