Skip to content

add Dockerfile #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
c073e96
add Dockerfile
Mar 26, 2019
eb842b5
added docker support
Mar 26, 2019
2c42ae9
switched to Docker & fixed
Mar 28, 2019
85c8b6b
Dockerfile updated
Mar 28, 2019
d19c2ac
some small output changes
Mar 31, 2019
9b9c03e
some small output changes
Mar 31, 2019
c9f6af8
added codefresh.yaml
Apr 4, 2019
f65a3ed
added codefresh.yml
Apr 4, 2019
b5b5855
added "push to Docker Hub" step
Apr 4, 2019
53b523b
added docker-compose
Apr 14, 2019
f179ff2
merging before branching
Apr 15, 2019
31128c5
established server
Apr 16, 2019
ce5f875
codefresh.yml fixed
Apr 16, 2019
11dd47c
README fixed
Apr 16, 2019
497af56
Merge pull request #2 from ilan-codefresh/phase3-UI
ilan-codefresh Apr 16, 2019
eed7193
compose to CF
Apr 16, 2019
3325115
compose to CF
Apr 16, 2019
fa6651a
compose to CF
Apr 16, 2019
0e2c29b
compose to CF
Apr 16, 2019
15c6914
fixed docker file & composeetc
ilan-codefresh Apr 17, 2019
a1c7262
fixed docker compose
ilan-codefresh Apr 17, 2019
a913d09
fixed docker compose
ilan-codefresh Apr 17, 2019
5a7a93c
fixed docker compose
ilan-codefresh Apr 17, 2019
619bd0b
cf.yml
ilan-codefresh Apr 17, 2019
a0ccdcd
cf.yml & compose
ilan-codefresh Apr 17, 2019
f9b36b9
test code-server
ilan-codefresh Apr 21, 2019
a6c85b7
test code-server
ilan-codefresh Apr 21, 2019
45d697a
test code-server
ilan-codefresh Apr 21, 2019
f5c16ef
Update README.md
ilan-codefresh Apr 22, 2019
5acaa44
Update README.md
ilan-codefresh Apr 22, 2019
dd1c3d2
Update dbManipulator.js
ilan-codefresh Apr 23, 2019
a6b5dc6
Update dbManipulator.js
ilan-codefresh Apr 23, 2019
69157c4
Update dbManipulator.js
ilan-codefresh Apr 23, 2019
cbec35f
Update dbManipulator.js
ilan-codefresh Apr 23, 2019
2b1b2cc
Update dbManipulator.js
ilan-codefresh Apr 23, 2019
6b1ea72
Update dbManipulator.js
ilan-codefresh Apr 23, 2019
d514e7c
Update dbManipulator.js
ilan-codefresh Apr 23, 2019
c0d1a5d
Update dbManipulator.js
ilan-codefresh Apr 23, 2019
efef684
Update dbManipulator.js
ilan-codefresh Apr 23, 2019
76a1128
Update dbManipulator.js
ilan-codefresh Apr 23, 2019
4a23f19
Update dbManipulator.js
ilan-codefresh Apr 23, 2019
e54d8f2
Update dbManipulator.js
ilan-codefresh Apr 23, 2019
c3d015c
Update dbManipulator.js
ilan-codefresh Apr 23, 2019
5417cec
update config args
ilan-codefresh Apr 28, 2019
018fb7e
update
ilan-codefresh Apr 29, 2019
07aa2da
update
ilan-codefresh Apr 29, 2019
d48d03d
dockerfile
ilan-codefresh Apr 29, 2019
ec5ea2f
dockerfile
ilan-codefresh Apr 29, 2019
d16cb90
dockerfile
ilan-codefresh Apr 29, 2019
cd13461
Update dbManipulator.js
ilan-codefresh Apr 30, 2019
92c51ae
Update dbManipulator.js
ilan-codefresh Apr 30, 2019
afb143a
Update dbManipulator.js
ilan-codefresh May 1, 2019
dc3e426
Update dbManipulator.js
ilan-codefresh May 1, 2019
e945d60
Update dbManipulator.js
ilan-codefresh May 2, 2019
d0efa26
Update dbManipulator.js
ilan-codefresh May 2, 2019
07462f9
Update dbManipulator.js
ilan-codefresh May 2, 2019
eb700bf
Create codefresh1.yml
ilan-codefresh May 23, 2019
fcd1b52
Create codefresh2
ilan-codefresh May 26, 2019
26562aa
Rename codefresh2 to codefresh2.yml
ilan-codefresh May 26, 2019
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
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use an official node version as a parent image
FROM node:11.12.0

# Create app directory
RUN mkdir -p /src/app
WORKDIR /src/app

# Install any needed packages specified in requirements.txt
COPY package.json /src/app/
RUN npm install

# Bundle app source
COPY . /src/app

# Make port 8000 available to the world outside this container
EXPOSE 3000

# Define environment variable
#ENV DEBUG True

VOLUME ["/var/lib/docker/volumes/jtmVol"]

# Run
#CMD ["node", "index.js"]
#CMD ["npm", "run", "start"]
#CMD ["npm", "run", "debug"]
CMD ["npm", "run", "server"]
35 changes: 8 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,23 @@ git clone https://github.com/iMelki/Json2MySQL.git


### Prerequisites
Node.js


### Installing
Download & Install [Node.js](https://nodejs.org/en/)
Go to the directory of the app
Enter the command:
```
npm install
```

Download & Install [Docker](https://www.docker.com/get-started)


## Running the app
Before first run:
Go to the directory of the app.
Navigate to the directory of the app.

Before first run:
Open the configuration file (config.json) and edit it with the arguments of your choise.
Choose a database table that fits the Schema, or choose a non-existing one to be created.

Now, this command will run the app on your local machine:


To build & run the app, enter the command:
```
node index.js [%file_path% [%DB_name% [%table_name%]]]
```

Note: to see app's progress with debug comments in the console:
docker-compose up
```
SET DEBUG=* & node index.js [%file_path% [%DB_name% [%table_name%]]]
```

Where %filePath% should be replaced with the input JSON file path,
%DB_name% should be replaced with the database name
and %table_name% should be replaced with the table name.
They're not mandatory. If not specified, they'll be taken from the configuration file instead.




## Author
* **iMelki**
Expand Down
46 changes: 46 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
//Outers:
const express = require('express');
var createError = require('http-errors');
var path = require('path');
var debug = require('debug')('app');

//Insiders:
const jsonToMySQL = require('./jsonToMySQL.js');
var indexRouter = require('./routes/index');


const app = express();

const port = 3000;
app.listen(port, () => console.log(`Example app listening on port ${port}!`));

const data = jsonToMySQL.startScript();

//Set up MySQL connection:
// currently in the original file

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

app.use('/', indexRouter);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});

module.exports = app;
*/
43 changes: 43 additions & 0 deletions cf-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: '2'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: 'db'
MYSQL_USER: 'user'
MYSQL_PASSWORD: 'password'
MYSQL_ROOT_PASSWORD: 'password'
# ports:
# - '3306:3306'
ports:
- '3306'
volumes:
- jtmVol:/var/lib/docker/volumes/jtmVol
#- my-db:/var/lib/mysql

# client:
# image: ${{MyClientDockerImage}}
# expose:
# - '4200'
# image: my-app-ui
# ports:
# - 4200:4200

server:
image: ${{MyServerDockerImage}}
ports:
- '3000'
environment:
MYSQL_DATABASE: db.MYSQL_DATABASE
MYSQL_USER: db.MYSQL_USER
MYSQL_PASSWORD: db.MYSQL_PASSWORD
MYSQL_ROOT_PASSWORD: db.MYSQL_ROOT_PASSWORD
# ports:
# - 3000:3000

#build: .


volumes:
jtmVol:
61 changes: 61 additions & 0 deletions codefresh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
version: '1.0'

stages:
- test

steps:

MyServerDockerImage:
title: Building Server Docker Image
type: build
image_name: ilancodefresh/json2mysql
working_directory: ./
tag: '${{CF_BRANCH_TAG_NORMALIZED}}'
dockerfile: Dockerfile

# MyClientDockerImage:
# title: Building Client Docker Image
# type: build
# image_name: ilancodefresh/my-app-ui
# working_directory: ./
# tag: '${{CF_BRANCH_TAG_NORMALIZED}}'
# dockerfile: Dockerfile

MyUnitTests:
title: Running Unit tests
stage: test
image: ${{MyServerDockerImage}}
commands:
- npm run test

PushToDH:
type: push
title: Push Image to Docker Hub
description: Push Docker Image to Docker Hub Registry
candidate: ${{MyServerDockerImage}}
#tag: latest
#image_name: codefresh/app
registry: dockerhub
fail_fast: false
when:
branch:
only:
- master
retry:
maxAttempts: 2
delay: 5

Run:
type: launch-composition
title: Run app
description: Free text description
working_directory: ./
entry_point: server
environment_name: Json2MySQL
composition: cf-docker-compose.yml

# Run:
# title: Running Server
# image: ${{MyServerDockerImage}}
# commands:
# - docker-compose up
1 change: 1 addition & 0 deletions codefresh1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
9 changes: 9 additions & 0 deletions codefresh2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '1.0'
steps:
BuildingDockerImage:
titlee: Building Docker Image
type: build
image_name: ilancodefresh/json2mysql
working_directory: ./
tag: '${{CF_BRANCH_TAG_NORMALIZED}}'
dockerfile: Dockerfile
22 changes: 15 additions & 7 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ var configData = require('./config.json');

debug('imported');

var jsonPath;
var host;
var user;
var password;
var dbName;
var tblName;
let jsonPath;
let host;
let user;
let password;
let rootPassword;
let dbName;
let tblName;

function initConfig(){
jsonPath = path.resolve(__dirname, configData.jsonPath);
Expand All @@ -25,4 +26,11 @@ initConfig();

module.exports = {
host, user, password, jsonPath, dbName, tblName
}
}

exports.initDbParams = function(dbNameStr, username, pass, rootPass){
user = username;
password = pass;
rootPassword = rootPass;
dbName = dbNameStr;
}
6 changes: 3 additions & 3 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"host" : "192.168.99.104",
"jsonPath" : "./inputs/accounts.json",
"host" : "localhost",
"user" : "root",
"password" : "root",
"password" : "123",
"dbName" : "accountsDB",
"tblName" : "accounts"
}
}
51 changes: 51 additions & 0 deletions controllers/accountController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

const debug = require('debug')('AccountController');

// Require App Logic:
const jsonToMySQL = require('../jsonToMySQL');

//const jsonToDB = () => {
async function jsonToDB(){
jsonToMySQL
.startScript(
process.env.MYSQL_DATABASE,
process.env.MYSQL_USER,
process.env.MYSQL_PASSWORD,
process.env.MYSQL_ROOT_PASSWORD
)
.then(() => {
console.log('finished insertion script.');
})
.catch(err => {
console.error(err.message);
});
}

async function getDataFromDB(){
jsonToMySQL
.getAllAccounts()
.then(data=>{return data;})
.catch(err => console.error(err));
}

exports.index = async function(req, res, next) {
//res.send("Account Controller with logic");
//res.send("YO ! "+process.env.MYSQL_PASSWORD.toString());
let status = await jsonToDB();
debug(status);

let data = getDataFromDB();
//return data;
res.send(data);
//res.render('index', { title: 'Express' });
};



/*

MYSQL_DATABASE: 'db'
MYSQL_USER: 'user'
MYSQL_PASSWORD: 'password'
MYSQL_ROOT_PASSWORD: 'password'
*/
Loading