diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..19f61b8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +node_modules +npm-debug.log +docs +mysql.txt +test.js +mysql \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ca06be1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM node:8 +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . +CMD npm start +EXPOSE 8055 + +# +FROM mysql + +ENV MYSQL_DATABASE iot +ENV MYSQL_ROOT_PASSWORD mitko2021 + +COPY schema.sql /docker-entrypoint-initdb.d/ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1403c3c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3.3' + +services: + node-app: + build: . + environment: + - DATABASE_HOST=db + depends_on: + - db + restart: always + ports: + - 8055:8055 + db: + build: ./mysql + restart: always + environment: + MYSQL_ROOT_PASSWORD: mitko2021 + MYSQL_DATABASE: iot \ No newline at end of file diff --git a/dump.sql b/mysql/dump.sql similarity index 100% rename from dump.sql rename to mysql/dump.sql diff --git a/schema.sql b/mysql/schema.sql similarity index 100% rename from schema.sql rename to mysql/schema.sql diff --git a/package.json b/package.json index de84bb1..4e0eb51 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": " test api for IOT devices", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "dev": "nodemon dht.js", + "start": "node dht.js" }, "repository": { "type": "git", diff --git a/src/db/devicemessages.js b/src/db/devicemessages.js index 0c88b4b..ae310ad 100644 --- a/src/db/devicemessages.js +++ b/src/db/devicemessages.js @@ -12,10 +12,10 @@ const config = require(__dirname + '/../../config/config.json')[env]; var pool = mysql.createPool({ connectionLimit : 20, - host : config.host, - user : config.username, - password : config.password, - database : config.database + host : process.env.DATABASE_HOST || config.host || '127.0.0.1', + user : process.env.DATABASE_USER || config.username, + password : process.env.DATABASE_PASS || config.password, + database : process.env.DATABASE_DB || config.database }); // var con = mysql.createConnection({ // host : 'localhost',