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

Pull Request by Emanuel Vasconcelos #10

Open
wants to merge 9 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
33 changes: 10 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
# Desafio DevOps jr PicPay
# Primeira impressão

Obrigado pelo interesse em fazer parte do nosso time! Preparamos este desafio com carinho para ajudar a entender um pouco mais dos seus conhecimentos na área de DevOps/SRE
A partir do momento que abri o projeto, fui direto para o arquivo docker-compose.yaml verificar se estava com a sintaxe correta, vi que as networks estavam emparalhadas, adaptei do meu jeito. Após isso fui olhar como estava o fronend por centralizar o uso dos serviços.

Se não entender algum conceito ou parte do problema, não é motivo para se preocupar! Queremos que faça o desafio até onde souber.
# Frontend

No mais, divirta-se :D
Ao abrir a pasta do frontend, fui olhar o Dockerfile, vi que estava instalando a biblioteca "serve" globalmente na imagem, o que não é o correto, fiz instalar todas as dependências redigidas no arquivo "package.json" usando o comando "npm install". O outro erro que encontrei no Dockerfile foi no "entrypoint" da imagem, o comando estava somente "serve", adaptei para usar o "npm start".

## Conteúdo do repositório
Na pasta `services` deste repositório existem 3 aplicações, um frontend que se comunica com um backend go e um em python, e estes se comunicam com um Redis para troca de informações. Tudo isso é orquestrado pelo docker-compose na raiz do repositório.
# Writer

As aplicações contém falhas propositais, de código, projeto, imagem docker, etc. Embora cada aplicação funcione individualmente, o conjunto não sobe...
Sem dúvidas o mais simples de resolver dos três para mim, somente tive que adicionar um arquivo .txt, que eu chamei de "requirement.txt", listando todas as bibliotecas importadas no arquivo main.py, logo em seguida adaptei o arquivo Dockerfile para instalar com "pip install -r requirement.txt" e fiz executar, através do nome reservado "CMD", o comando "python main.py".

## O que deve ser feito?
# Reader

Faça um fork deste repositório e envie uma pull request contendo:
- ajustes que fazem todas as aplicações subirem e se comunicarem
- um README contendo os seus pensamentos ao longo do projeto
- um desenho contendo os serviços que explique o funcionamento
Esse foi o que mais demorou para eu resolver, nunca havia mexido com go até esse desafio. Meu primeiro reflexo foi ver se existia um gerenciador de pacotes/bibliotecas e um arquivo para geri-las, assim como o package.json do Node, vi que tinha um arquivo go.mod, aprendi a sintaxe e crie uma arquivo na pasta reader. Modifiquei o Dockerfile para instalar todas as dependências e deu tudo certo, porém quando o container executou deu um problema de sintaxe no código, rapidamente entendi que era por causa de versão, tentei pesquisar a biblioteca que deu problema, a "redis-go", vi nos logs da imagem que foi instalada a versão 6.15.4+imcompatible, uma versão depreciada, troquei para a versão 8 da biblioca, porém o erro persistiu pois no código de importação era chamada pela versão antiga ainda, substitui pela nomenclatura da versão 8 da biblioteca e funcionou.

Faça commits ao longo do processo, queremos entender o seu modo de pensar! :)
# Docker Compose

Para a entrevista, separe também anotações contendo melhorias que faria em cada aplicação e o motivo. Não envie estas anotações na pull request.

## Bibliografia recomendada
https://docs.docker.com/engine/reference/builder/

https://docs.docker.com/compose/compose-file/

https://12factor.net/

https://conventionalcommits.org/
Após resolver os problemas iniciais deste arquivo anteriormente, ao resolver os problemas relacionado aos outros serviços vi que as portas foram trocadas, ajustei e no final foi resolvido o arquivo inteiro.
25 changes: 16 additions & 9 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,31 @@ services:
web:
build: services/frontend
ports:
- "5000:5000"
- "5000:5000"
networks:
- frontend
- backend
- frontend

reader:
build: services/reader
ports:
- "8081:8081"
networks:
- frontend
- "8080:8080"
networks:
- frontend
- backend

writer:
build: services/writer
ports:
- "8080:8080"
- "8081:8081"
networks:
- backend
reids:
- frontend
- backend

redis:
image: "redis:alpine"
networks:
- backend

networks:
backend:
frontend:
6 changes: 3 additions & 3 deletions services/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:latest
WORKDIR /app
ADD . .
RUN npm install -g serve
COPY . .
RUN npm install
EXPOSE 5000
CMD "serve"
CMD ["npm", "start"]
5 changes: 4 additions & 1 deletion services/reader/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
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
COPY . /go/src/github.com/PicPay/picpay-jr-devops-challenge/services/go

RUN go mod download
RUN go mod tidy

EXPOSE 8080
CMD ["go","run","main.go"]
8 changes: 8 additions & 0 deletions services/reader/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/PicPay/picpay-jr-devops-challenge/services/go

go 1.16

require (
github.com/go-redis/redis/v8 v8.11.0
github.com/rs/cors v1.11.0
)
2 changes: 1 addition & 1 deletion services/reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/go-redis/redis"
"github.com/go-redis/redis/v8"
"github.com/rs/cors"
"log"
"net/http"
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 -r requirements.txt
EXPOSE 8081
CMD ["python"]
ENTRYPOINT ["main.py"]
CMD ["python", "main.py"]
1 change: 1 addition & 0 deletions services/writer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
redis
94 changes: 94 additions & 0 deletions use-case.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<mxfile host="Electron" modified="2024-07-02T18:09:19.418Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/24.2.5 Chrome/120.0.6099.109 Electron/28.1.0 Safari/537.36" etag="wth7liT2KHg9XXi5z7a2" version="24.2.5" type="device">
<diagram name="Página-1" id="4msT0vv4pdND9azRW5vc">
<mxGraphModel dx="2100" dy="1258" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="NtpWOEAYPCwUQHESP8Rl-2" value="Home screen" style="swimlane;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="154" y="15" width="520" height="310" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-5" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="NtpWOEAYPCwUQHESP8Rl-2" source="NtpWOEAYPCwUQHESP8Rl-3" target="NtpWOEAYPCwUQHESP8Rl-4">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-12" value="GET /health" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="NtpWOEAYPCwUQHESP8Rl-5">
<mxGeometry x="0.0389" y="1" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-7" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="NtpWOEAYPCwUQHESP8Rl-2" source="NtpWOEAYPCwUQHESP8Rl-3" target="NtpWOEAYPCwUQHESP8Rl-6">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-11" value="GET /health" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="NtpWOEAYPCwUQHESP8Rl-7">
<mxGeometry x="0.001" y="-1" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-3" value="frontend" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="NtpWOEAYPCwUQHESP8Rl-2">
<mxGeometry x="199" y="70" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-4" value="reader" style="whiteSpace=wrap;html=1;rounded=1;" vertex="1" parent="NtpWOEAYPCwUQHESP8Rl-2">
<mxGeometry x="319" y="190" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-6" value="writer" style="whiteSpace=wrap;html=1;rounded=1;" vertex="1" parent="NtpWOEAYPCwUQHESP8Rl-2">
<mxGeometry x="79" y="190" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-13" value="Reader screen" style="swimlane;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="154" y="365" width="520" height="370" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-14" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="NtpWOEAYPCwUQHESP8Rl-13" source="NtpWOEAYPCwUQHESP8Rl-18" target="NtpWOEAYPCwUQHESP8Rl-19">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-15" value="GET /data" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="NtpWOEAYPCwUQHESP8Rl-14">
<mxGeometry x="0.0389" y="1" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-21" value="Redis" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=15;" vertex="1" parent="NtpWOEAYPCwUQHESP8Rl-13">
<mxGeometry x="345" y="210" width="60" height="80" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-18" value="frontend" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="NtpWOEAYPCwUQHESP8Rl-13">
<mxGeometry x="85" y="80" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-25" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="NtpWOEAYPCwUQHESP8Rl-13" source="NtpWOEAYPCwUQHESP8Rl-19" target="NtpWOEAYPCwUQHESP8Rl-21">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-26" value="Get SHAREKEY value" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="NtpWOEAYPCwUQHESP8Rl-25">
<mxGeometry x="-0.0989" y="1" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-19" value="reader" style="whiteSpace=wrap;html=1;rounded=1;" vertex="1" parent="NtpWOEAYPCwUQHESP8Rl-13">
<mxGeometry x="315" y="80" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-27" value="Reader screen" style="swimlane;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="154" y="785" width="520" height="370" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-28" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="NtpWOEAYPCwUQHESP8Rl-27" source="NtpWOEAYPCwUQHESP8Rl-31" target="NtpWOEAYPCwUQHESP8Rl-34">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-29" value="POST /write" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="NtpWOEAYPCwUQHESP8Rl-28">
<mxGeometry x="0.0389" y="1" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-30" value="Redis" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=15;" vertex="1" parent="NtpWOEAYPCwUQHESP8Rl-27">
<mxGeometry x="345" y="210" width="60" height="80" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-31" value="frontend" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="NtpWOEAYPCwUQHESP8Rl-27">
<mxGeometry x="85" y="80" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-32" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="NtpWOEAYPCwUQHESP8Rl-27" source="NtpWOEAYPCwUQHESP8Rl-34" target="NtpWOEAYPCwUQHESP8Rl-30">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-33" value="Set SHAREKEY value" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="NtpWOEAYPCwUQHESP8Rl-32">
<mxGeometry x="-0.0989" y="1" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="NtpWOEAYPCwUQHESP8Rl-34" value="writer" style="whiteSpace=wrap;html=1;rounded=1;" vertex="1" parent="NtpWOEAYPCwUQHESP8Rl-27">
<mxGeometry x="315" y="80" width="120" height="60" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
Binary file added use-case.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.