Skip to content

Commit

Permalink
folders back e front end
Browse files Browse the repository at this point in the history
  • Loading branch information
Josehpequeno committed Aug 12, 2024
1 parent 675cb39 commit f88db1a
Show file tree
Hide file tree
Showing 82 changed files with 245 additions and 187 deletions.
28 changes: 15 additions & 13 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ name: Go

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:

build:
runs-on: ubuntu-latest
services:
Expand All @@ -23,17 +22,20 @@ jobs:
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Enter the project backend
run: cd backend

- name: Build
run: go build -v ./...
- name: Build
run: go build -v ./...

- name: Test
run: source .initENV.sh && go test -v ./...
- name: Test
run: source .initENV.sh && go test -v ./...
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/docker/dados_postgres
/documents/*
/backend/documents/*
80 changes: 80 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Etapa de build do frontend
FROM node:14 AS build-frontend

WORKDIR /app/frontend

COPY frontend/package.json ./
COPY frontend/package-lock.json ./

RUN npm install

COPY frontend ./

RUN npm run build

# Use uma imagem oficial do Go como base
FROM golang:1.22.5 AS build-backend

# Configure o diretório de trabalho
WORKDIR /app/backend

# Copie o código-fonte para o contêiner
COPY backend/go.mod ./
COPY backend/go.sum ./
RUN go mod download
COPY backend ./

# Executa o comando de build
RUN go build -o main .

# Imagem base do Ubuntu
FROM ubuntu:latest

# Atualize os pacotes e instale o PostgreSQL, nginx, npm e nodejs
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update -q \
&& apt-get install -y -q postgresql postgresql-contrib nodejs npm nginx

# Configurar o diretório de trabalho
WORKDIR /root/

# Exponha o diretório de dados do PostgreSQL para persistência
VOLUME /var/lib/postgresql/data

# # Copie o binário do primeiro estágio
# COPY --from=builder /app/main /app/main

# Inicie o PostgreSQL e crie o banco de dados
#su postgres -c 'createuser -s postgres' && \
RUN service postgresql start && \
su postgres -c 'createdb documentmanager' && \
su - postgres -c "psql -U postgres -c \"ALTER USER postgres WITH PASSWORD 'postgres';\""


# Combinando front, back e database

# Copiar e configurar o backend
COPY --from=build-backend /app/backend/main ./

# Copiar e configurar o frontend
COPY --from=build-frontend /app/frontend/build /usr/share/nginx/html

# Configurar Nginx
COPY nginx.conf /etc/nginx/nginx.conf

# Copiar o script de variáveis de ambiente
COPY backend/.initENV.sh /root/.initENV.sh
RUN chmod +x /root/.initENV.sh

# Configurar PostgreSQL
RUN mkdir -p /var/lib/postgresql/data
RUN chown -R postgres:postgres /var/lib/postgresql

# Instalar o serve para servir a aplicação React
RUN npm install -g serve

# Expor as portas necessárias
EXPOSE 80 3450 5432 3000

# Comando para iniciar todos os serviços
CMD ["sh", "-c", ". /root/.initENV.sh && service postgresql start && ./main & serve -n -s /usr/share/nginx/html -l 3000 & nginx -g 'daemon off;'"]
48 changes: 26 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,80 @@
# document-manager

Go API para gerenciar documentos com frontend em React.
Go API for managing documents with a React frontend.

## Clone o Repositório
## Clone the Repository

```shell
git clone https://github.com/Josehpequeno/document-manager.git
cd document-manager
```

## Executar última versão com docker-compose
## Run the latest version with docker-compose

```shell
cd docker && docker-compose up -d
```

Se os containers estiverem parados, execute o seguinte comando:
If the containers are stopped, run the following command:

```shell
docker-compose start
```

O Postgres estará rodando na porta 5432, o pgAdmin na porta 8080 e a aplicação na porta 3450 de acordo com as credenciais no arquivo docker-compose.yml.
Postgres will run on port 5432, pgAdmin on port 8080, and the application on port 3450, according to the credentials in the docker-compose.yml file.

## Iniciar variáveis de ambiente
## Initialize environment variables

```shell
cd backend
```

```shell
chmod +x .initENV.sh && source .initENV.sh
```

## Gerar Documentação Swagger
## Generate Swagger Documentation

### Instalar Swag
### Install Swag

```shell
go install github.com/swaggo/swag/cmd/swag@latest
```

### Executar Swag
### Run Swag

```shell
swag init --parseDependency --parseInternal
```

### Rota Swagger
### Swagger Route

A documentação Swagger pode ser acessada em [http://localhost:3450/swagger/index.html](http://localhost:3450/swagger/index.html).

## Testes
## Tests

Testar handlers:
Test handlers:

```shell
cd api/handlers/ && GIN_MODE=release go test
```

## Requisitos do Sistema
## System Requirements

Certifique-se de ter o Docker e o Docker Compose instalados.
Make sure you have Docker and Docker Compose installed.

## Link para o Repositório no DockerHub
## Link to repository on DockerHub

A imagem Docker do projeto está disponível no [repositório do DockerHub](https://hub.docker.com/r/josehpequeno/document-manager).
The project's Docker image is available in the [DockerHub repository](https://hub.docker.com/r/josehpequeno/document-manager).

* Executar com Docker
Para executar a aplicação com Docker, use o seguinte comando:
* Run with Docker
To run the application with Docker, use the following command:

```shell
docker run -it --name test-document-manager -p 8080:3450 -p 3000:3000 josehpequeno/document-manager:latest
docker run -it --name test-document-manager -p 3450:3450 -p 3000:3000 josehpequeno/document-manager:latest
```
Isso irá iniciar a aplicação no contêiner Docker e expor as portas 8080 e 3000 para os respectivos serviços.
This will start the application in the Docker container and expose ports 8080 and 3000 to the respective services.

## Licença
## License

Este projeto é licenciado sob a [MIT License](LICENSE).
This project is licensed under the [MIT License](LICENSE).
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions main.go → backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"document-manager/api/models"
"document-manager/database"
_ "document-manager/docs"
"fmt"
"log"
)

Expand Down Expand Up @@ -55,5 +56,7 @@ func main() {

router := api.SetupRouter()

fmt.Println("Server running on http://localhost:3450")

router.Run(":3450")
}
File renamed without changes.
64 changes: 0 additions & 64 deletions dockerfile

This file was deleted.

Binary file removed documents/file.pdf
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion docbeaver/package.json → frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"proxy": "http://localhost:3450",
"homepage": ".",
"name": "docbeaver",
"version": "0.1.0",
"private": true,
Expand Down Expand Up @@ -33,7 +35,6 @@
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:3450",
"eslintConfig": {
"extends": [
"react-app",
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit f88db1a

Please sign in to comment.