Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Pull Request de Juan Camargo #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.PHONY: all up down

all: up

up:
cd services/reader && \
go mod init github.com/PicPay/picpay-jr-devops-challenge/services/go && \
go get ./... && \
docker-compose up -d --build

down:
cd services/reader && \
rm -f go.mod go.sum && \
docker-compose down
36 changes: 36 additions & 0 deletions README_JUAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Docker Compose
- Nome "redis" estava errado
- Adicionar a network ```frontend```
- Resolver network dos serviços
- Aadicionar ```hostname``` e ```container_name```
- Resolver portas iguais pelos containers
- Adicionar ```depends_on``` para assegurar o funcionamento das aplicações

# Frontend
- Dockerfile - Adicionar ```ADD . /app```

# Writer
- Dockerfile - Instalar dependencia do redis ```RUN pip install redis```
- Dockerfile - Trocar comando inicial ```CMD [ "python", "./main.py" ]```

# Reader
- Gerar os requisitos com ```go mod init``` e ```go get ./...``` (feito automaticamente com o Makefile)
- Dockerfile - Instalar modulos ```RUN go mod download```
- Dockerfile - Gerar o executavel ```RUN go build -o main .```
- Dockerfile - Executar o arquivo gerado ```CMD ["/go/src/github.com/PicPay/picpay-jr-devops-challenge/services/go/main"]```

## Reader -Aplicação - Erro ao pegar o valor no Redis, resolvido com ajustes no código:
```
key, err := client.Get("SHAREDKEY").Result()
if err != nil {
panic(err)
}
fmt.Fprintf(writer, key)
```

# Usage
- Subir os serviços ```make up```
- Matar os serviços ```make down```

# Chart
![Organograma](https://i.imgur.com/kPxydAv.png "Organograma")
Binary file added chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 21 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,42 @@ version: "3.9"
services:
web:
build: services/frontend
hostname: frontend
container_name: frontend
ports:
- "5000:5000"
networks:
- frontend
- backend
reader:
build: services/reader
hostname: reader
container_name: reader
ports:
- "8081:8081"
- "8080:8080"
depends_on:
- redis
networks:
- frontend
- backend
writer:
build: services/writer
hostname: writer
container_name: writer
ports:
- "8080:8080"
- "8081:8081"
depends_on:
- redis
networks:
- backend
reids:
redis:
image: "redis:alpine"
hostname: redis
container_name: redis
ports:
- "6379:6379"
networks:
- backend

networks:
backend:
frontend:
2 changes: 1 addition & 1 deletion services/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:latest
WORKDIR /app
ADD . .
ADD . /app
RUN npm install -g serve
EXPOSE 5000
CMD "serve"
5 changes: 3 additions & 2 deletions services/reader/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM golang:1.16
WORKDIR /go/src/github.com/PicPay/picpay-jr-devops-challenge/services/go
ADD . /go/src/github.com/PicPay/picpay-jr-devops-challenge/services/go

RUN go mod download
RUN go build -o main .
EXPOSE 8080
CMD ["go","run","main.go"]
CMD ["/go/src/github.com/PicPay/picpay-jr-devops-challenge/services/go/main"]
7 changes: 5 additions & 2 deletions services/reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ func main() {

mux.HandleFunc("/data", func(writer http.ResponseWriter, request *http.Request) {
client := redis.NewClient(&redis.Options{Addr: redis_host+":"+redis_port})
key := client.Get(client.Context(),"SHAREDKEY")
fmt.Fprintf(writer, key.Val())
key, err := client.Get("SHAREDKEY").Result()
if err != nil {
panic(err)
}
fmt.Fprintf(writer, key)
})

handler := cors.New(cors.Options{
Expand Down
4 changes: 2 additions & 2 deletions services/writer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.9
WORKDIR /app
ADD . /app
RUN pip install redis
EXPOSE 8081
CMD ["python"]
ENTRYPOINT ["main.py"]
CMD [ "python", "./main.py" ]