Skip to content
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

DevOps - Docker-Compose #483 #496

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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
34 changes: 34 additions & 0 deletions devops/docker-compose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#DOCKER-COMPOSE-NODEJS-EXPRESS-MYSQL
In this sample, we will look at the functionality provided by 'Docker Compose' for defining and running multi-container Docker applications.

We are going to use 'MySQL' like our specialized database and 'Node.js' as our platform for creating highly performant web applications.

#NodeJS v14.17
#MySQL 5.7

<p align="center">
<img src="Screenshots/docker_nodejs.png" alt="docker_compose" width="50%"/>
</p>

<p align="center">
<img src="Screenshots/mysql.jpg" alt="docker_compose" width="50%"/>
</p>

### To Build both of images
'docker-compose build'

### RUN THE PROJECT
`docker-compose up`

### INSPECT YOUR MYSQL CONTAINER(to see your database)
1. docker ps
2. docker exec -it YOUR_MYSQL_CONTAINER_ID bash
3. mysql -u root -p
4. put the password(123)
5. enter
6. use CHIRINOS;
7. show tables;
8. describe EMPLOYEE;


ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';
2 changes: 2 additions & 0 deletions devops/docker-compose/database-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM mysql:5.7
ADD setup.sql /docker-entrypoint-initdb.d
Empty file.
30 changes: 30 additions & 0 deletions devops/docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: '2.2'

networks:
net-ladybird:
name: net-ladybird

services:
security:
build: ./service
ports:
- "3001:3001"
depends_on:
- db
environment:
- DATABASE_HOST=db
command: bash -c "sleep 10 && npm run knex migrate:latest --file knexfile.js"
restart: always
db:
build: ./database-service
command:
- --default-authentication-plugin=mysql_native_password
- --sql_mode="(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY,',''))"
restart: always
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_USER=root
- MYSQL_PASSWORD=password
- MYSQL_DATABASE=meirim
ports:
- 3318:3306
7 changes: 7 additions & 0 deletions devops/docker-compose/service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:14.17

COPY ./ ../../../server/package.json
COPY ./ ../../../server/package-lock.json

RUN npm install

116 changes: 116 additions & 0 deletions devops/docker-compose/service/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
22 changes: 22 additions & 0 deletions devops/docker-compose/service/api/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Created by Carlos Leonardo Camilo Vargas HUuamán on 12/9/16.
*/
var express = require("express");
var bodyParser = require('body-parser');

var index = require('./routes/index');
var employee = require('./routes/employee');
var placelocation = require('./routes/placelocation');

var app = express();

app.set("view engine", "jade");

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));
app.use('/employee', employee);
app.use('/', index);
app.use('/placelocation', placelocation);

app.listen(8123);
31 changes: 31 additions & 0 deletions devops/docker-compose/service/api/config/DataBaseHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Created by Carlos Leonardo Camilo Vargas HUuamán on 11/20/16.
*/

var mysql = require("mysql");

function DataBaseHandler() {
this.connection = null;
}

DataBaseHandler.prototype.createConnection = function () {

this.connection = mysql.createConnection({
host: process.env.DATABASE_HOST || '127.0.0.1',
user: 'root',
password: '123',
database: 'CHIRINOS',
port: 3306
});

this.connection.connect(function (err) {
if (err) {
console.error("error connecting " + err.stack);
return null;
}
console.log("connected as id " + this.threadId);
});
return this.connection;
};

module.exports = DataBaseHandler;
Loading