-
-
Save kaiomagalhaes/dcd381f30269d6e11ecdd29e3cf2e69b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dockerfile | |
``` | |
FROM node:17-alpine as development | |
WORKDIR /app | |
COPY package.json . | |
COPY package-lock.json . | |
RUN npm install | |
COPY . . | |
EXPOSE 4000 | |
CMD ["npm", "start"] | |
``` | |
config/database.config.ts | |
``` | |
import { Sequelize } from 'sequelize'; | |
import dotenv from 'dotenv'; | |
dotenv.config(); | |
const dbConfig = { | |
host: process.env.DB_HOST || 'localhost', | |
user: process.env.DB_USER || 'root', | |
password: process.env.DB_PASSWORD, | |
name: process.env.DB_NAME || 'transactions-exercise', | |
port: process.env.DB_PORT ? parseInt(process.env.DB_PORT) : 3306 | |
}; | |
const sequelize = new Sequelize(dbConfig.name, dbConfig.user, dbConfig.password, { | |
dialect: 'mysql', | |
host: dbConfig.host, | |
port: dbConfig.port | |
}); | |
export default sequelize; | |
``` | |
docker-compose.yml | |
``` | |
version: '3' | |
services: | |
mysqldb: | |
platform: linux/amd64 | |
image: mysql:5.7 | |
restart: unless-stopped | |
env_file: | |
- .env | |
ports: | |
- 3306:3306 | |
volumes: | |
- db:/var/lib/mysql | |
app: | |
container_name: transactions-client-server | |
image: transactions-client-server | |
tty: true | |
stdin_open: true | |
build: | |
context: . | |
target: development | |
volumes: | |
- .:/app/ | |
stdin_open: true | |
env_file: | |
- .env | |
ports: | |
- 4000:4000 | |
depends_on: | |
- mysqldb | |
volumes: | |
db: | |
``` | |
.env | |
``` | |
DB_HOST=mysqldb | |
DB_USER=root | |
DB_PASSWORD=banana | |
DB_NAME=transactions_database | |
DB_PORT=3306 | |
MYSQL_DATABASE=transactions_database | |
MYSQL_ROOT_PASSWORD=banana | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment