Skip to content

Commit

Permalink
fix run with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Josehpequeno committed Aug 13, 2024
1 parent f88db1a commit 2845ef5
Show file tree
Hide file tree
Showing 21 changed files with 634 additions and 651 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ jobs:
with:
go-version: "1.20"

- name: Enter the project backend
run: cd backend

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

- name: Test
run: source .initENV.sh && go test -v ./...
run: |
source backend/.initENV.sh
go test -v ./backend/...
24 changes: 13 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Etapa de build do frontend
FROM node:14 AS build-frontend
FROM node:20 AS build-frontend

WORKDIR /app/frontend

Expand Down Expand Up @@ -33,24 +33,29 @@ 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
&& apt-get install -y -q postgresql postgresql-contrib nginx bash curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Configurar o diretório de trabalho
WORKDIR /root/
# Instalar a versão 20 do nodejs
RUN curl -sL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh

RUN bash nodesource_setup.sh && apt-get install -y nodejs

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

# 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
# Configurar o diretório de trabalho
WORKDIR /root/

# 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
Expand All @@ -70,9 +75,6 @@ RUN chmod +x /root/.initENV.sh
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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ The project's Docker image is available in the [DockerHub repository](https://hu
To run the application with Docker, use the following command:

```shell
docker run -it --name test-document-manager -p 3450:3450 -p 3000:3000 josehpequeno/document-manager:latest
docker run -it --name test-document-manager -p 3450:3450 -p 3000:3000 -p 80:80 josehpequeno/document-manager:latest
```
This will start the application in the Docker container and expose ports 8080 and 3000 to the respective services.

Expand Down
1 change: 1 addition & 0 deletions backend/api/handlers/authHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func LoginHandler(c *gin.Context) {

func AuthMiddleware(c *gin.Context) {
tokenString := c.GetHeader("Authorization")
println(">>", tokenString)

if tokenString == "" {
c.JSON(http.StatusUnauthorized, gin.H{"message": "Missing token"})
Expand Down
1 change: 1 addition & 0 deletions backend/api/utils/corsConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func CORSConfig() cors.Config {
config.AllowMethods = []string{"POST", "GET", "PUT", "OPTIONS", "DELETE"}
config.AllowHeaders = []string{"Origin", "Content-Type", "Authorization", "Accept", "User-Agent", "Cache-Control", "Pragma"}
config.ExposeHeaders = []string{"Content-Length"}
config.AllowCredentials = true

return config
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 2845ef5

Please sign in to comment.