Skip to content

Commit

Permalink
Merge pull request #35 from GoLembrar/feat-run-with-dockercompose
Browse files Browse the repository at this point in the history
Feat run with dockercompose
  • Loading branch information
Rip4568 committed May 15, 2024
2 parents 665f9ca + f2d6c66 commit aac4363
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.env
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/test_db?schema=public"
JWT_SECRET="variosnumerosletrasesimbolosmisturadosparasegurançadosecret"
# A variável abaixo é referente ao tempo que o token vai durar, "1h" no caso é uma hora.
# Possíveis valores: Xm Xh Xd Xw XM onde X é qualquer valor, m são minutos, h são horas
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/build_and_push_image_to_docker_hub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build and Push Docker Image

on:
push:
branches:
- develop

jobs:

build-and-push:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_db
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Copy .env.example to .env
run: cp .env.example .env

- name: Log in to Docker hub
uses: docker/[email protected]
with:
username: matheusvictorhenrique
password: Familia26

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 18

- name: Install dependencies
run: npm install

- name: Build Docker image
run: docker build -t matheusvictorhenrique/go_lembrar_server .

- name: Tag Docker image
run: |
docker tag matheusvictorhenrique/go_lembrar_server matheusvictorhenrique/go_lembrar_server:latest
docker tag matheusvictorhenrique/go_lembrar_server matheusvictorhenrique/go_lembrar_server:${{ github.run_id }}
- name: Push Docker image
run: |
docker push matheusvictorhenrique/go_lembrar_server:${{ github.run_id }}
docker push matheusvictorhenrique/go_lembrar_server:latest
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:18

WORKDIR /usr/src/app

COPY . .

COPY ./.env.example ./env

COPY package*.json ./

RUN npm install

RUN npm run build



CMD [ "npm", "run", "start:prod" ]
30 changes: 26 additions & 4 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,34 @@ services:
- host.docker.internal:host-gateway
volumes:
- ./.docker/db/data:/var/lib/postgresql/:delegated

healthcheck:
test: [ "CMD-SHELL", "psql -h localhost -U test -d golembrar -c 'SELECT 1;'" ]
interval: 5s
timeout: 5s
retries: 20
start_period: 10s

rabbitmq:
image: rabbitmq:3-management-alpine
image: rabbitmq:3-management-alpine
ports:
- 5672:5672
- 15672:15672
- 5672:5672
- 15672:15672
environment:
- RABBITMQ_DEFAULT_USER=test
- RABBITMQ_DEFAULT_PASS=test
api:
depends_on:
db:
condition: service_healthy
build: .
environment:
- DATABASE_URL="postgresql://test:test@db:5432/golembrar?schema=publicvalue"
- JWT_SECRET="variosnumerosletrasesimbolosmisturadosparasegurançadosecret"
- JWT_EXP="1h"
ports:
- "3000:3000"

networks:
default:
driver: bridge
name: golembrar

0 comments on commit aac4363

Please sign in to comment.