Skip to content

Commit

Permalink
Feat: Add Docker configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
aridanemartin committed Aug 6, 2024
1 parent d5acb2a commit 9a481d9
Show file tree
Hide file tree
Showing 9 changed files with 1,827 additions and 12 deletions.
4 changes: 2 additions & 2 deletions db/config.development.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const config = {
host: 'localhost',
host: process.env.DB_HOST, // Name of docker Service instead of 'localhost'
user: 'root',
password: '',
password: process.env.DB_PASSWORD,
database: 'gatos_sin_hogar'
};
4 changes: 2 additions & 2 deletions db/config.production.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const config = {
host: process.env.DB_HOST,
host: process.env.DB_HOST, // Name of docker Service instead of 'localhost'
port: process.env.DB_PORT,
user: 'admin',
user: 'root',
password: process.env.DB_PASSWORD,
database: 'gatos_sin_hogar'
};
16 changes: 11 additions & 5 deletions db/db_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ import mysql from 'mysql2/promise';
import { logEnvironment } from '../utils/logger.js';

const env = process.env.NODE_ENV || 'development';
console.log('===env==>', env);
const dbConfig = await import(`./config.${env}.js`);
let db;

logEnvironment();
try {
const dbConfig = await import(`./config.${env}.js`);

const pool = mysql.createPool(dbConfig.config);
logEnvironment();

const pool = mysql.createPool(dbConfig.config);

db = await pool.getConnection();
} catch (error) {
console.error('Error connecting to the database:', error);
}

const db = await pool.getConnection();
export default db;
5 changes: 5 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'
services:
backend:
environment:
- NODE_ENV=development
5 changes: 5 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'
services:
backend:
environment:
- NODE_ENV=production
30 changes: 30 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: '3.8'
name: gsh
services:
backend:
image: backend
build: .
ports:
- '7000:7000'
volumes:
- .:/usr/src/app
env_file:
- .env
depends_on:
- db
networks:
- app-network
db:
image: mysql:5.7
container_name: mysql
env_file:
- .env
ports:
- '3306:3306'
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
networks:
- app-network
networks:
app-network:
driver: bridge
Loading

0 comments on commit 9a481d9

Please sign in to comment.