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

[finishes #187354240] setting up docker for backend #27

Merged
merged 1 commit into from
Apr 28, 2024
Merged
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
41 changes: 41 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Dockerfile
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.swp

pids
logs
results
tmp

# Build
public/css/main.css

# Coverage reports
coverage



# Dependency directory
node_modules
bower_components

# Editors
.idea
*.iml

# OS metadata
.DS_Store
Thumbs.db

# Ignore built ts files
dist

# ignore yarn.lock
yarn.lock
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:21-alpine3.19
WORKDIR /app
RUN apk add --no-cache git
COPY package*.json /app
COPY /.git /app/.git
RUN npm install
COPY . /app
ENV PORT=3000
EXPOSE ${PORT}
CMD ["npm", "run", "dev"]
82 changes: 40 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,70 +149,68 @@ If setting up Swagger for the first time, follow these steps:

**Note:** YAML strictly follows indentations, so ensure you follow them.

# Sequelize Usage Guide
# Sequelize Usage Guide

## Introduction

This documentation provides guidance on setting up and using Sequelize in the project. Sequelize is a promise-based Node.js ORM for PostgreSQL, MySQL, SQLite, and MSSQL databases.

## Setup
1. *Clone the Repository:* Clone the project repository to your local machine.
bash
git clone <repository-url>

2. *Install Dependencies:* Install the project dependencies using npm.
bash
npm install

3. *Run Migrations:* Execute existing migrations to create database tables.
bash
npm run migrate


1. _Clone the Repository:_ Clone the project repository to your local machine.
bash
git clone <repository-url>
2. _Install Dependencies:_ Install the project dependencies using npm.
bash
npm install
3. _Run Migrations:_ Execute existing migrations to create database tables.
bash
npm run migrate

## Usage

### Running Migrations
- *Create Tables:* To create database tables based on existing migrations.
bash
npm run migrate

- *Undo Changes:* If you need to rollback changes made by migrations.
bash
npm run migrate:undo


- _Create Tables:_ To create database tables based on existing migrations.
bash
npm run migrate
- _Undo Changes:_ If you need to rollback changes made by migrations.
bash
npm run migrate:undo

### Seeding Data
- *Seed Database:* Add initial data to the database.
bash
npm run seed

- *Undo Seeding:* Remove seeded data from the database.
bash
npm run seed:undo


- _Seed Database:_ Add initial data to the database.
bash
npm run seed
- _Undo Seeding:_ Remove seeded data from the database.
bash
npm run seed:undo

### Creating Models
- *Generate Model:* Create a new model using the Sequelize CLI.
bash
npx sequelize-cli model:generate --name <ModelName> --attributes <attr1>:<type>,<attr2>:<type>,...

- _Generate Model:_ Create a new model using the Sequelize CLI.
bash
npx sequelize-cli model:generate --name <ModelName> --attributes <attr1>:<type>,<attr2>:<type>,...

### Generating Migrations
- *Generate Migration:* Generate a new migration file for making changes to the database schema.
bash
npx sequelize-cli migration:generate --name <MigrationName>

- _Generate Migration:_ Generate a new migration file for making changes to the database schema.
bash
npx sequelize-cli migration:generate --name <MigrationName>

### Executing Migrations
- *Run Migrations:* Execute the generated migration to apply changes to the database.
bash
npm run migrate

- _Run Migrations:_ Execute the generated migration to apply changes to the database.
bash
npm run migrate

## Conclusion

Sequelize simplifies database interactions in the project by providing an ORM layer. Follow the steps outlined above to set up Sequelize and manage database schema changes effectively. For more information, refer to the Sequelize documentation.

## Useful Links

1. [Pivotal Tracker's Official Documentation](https://www.pivotaltracker.com/help/articles/github_integration/#attaching-branches-to-a-story-automatically)
2. [freeCodeCamp Article on Naming Commits](https://www.freecodecamp.org/news/writing-good-commit-messages-a-practical-guide/)
3. [Medium Article on Naming Branches](https://medium.com/@abhay.pixolo/naming-conventions-for-git-chores-a-cheatsheet)

29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.9'
services:
backend:
container_name: backend
image: mavericks-backend:v1
build:
context: .
dockerfile: Dockerfile
ports:
- '3000:3000'
environment:
- DATABASE_URL=postgresql://$DEV_DB_USER:$DEV_DB_PASSWORD@db:5432/$DEV_DB_NAME
depends_on:
- db
db:
container_name: db
image: postgres:latest
restart: always
environment:
- POSTGRES_USER=$DEV_DB_USER
- POSTGRES_PASSWORD=$DEV_DB_PASSWORD
- POSTGRES_DB=$DEV_DB_NAME
ports:
- '5432:5432'
volumes:
- db-data:/var/lib/postgresql/data

volumes:
db-data:
10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const config = {
clearMocks: true,
collectCoverage: true,
coverageDirectory: 'coverage',
preset: 'ts-jest',
testEnvironment: 'node',
};
exports.default = config;
1 change: 1 addition & 0 deletions src/database/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {

dialect: process.env.DEV_DB_DRIVER,
port: process.env.DEV_DB_PORT,
host: process.env.DEV_DB_HOST,
},
test: {
username: process.env.TEST_DB_USER,
Expand Down
Loading