-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from caiodearaujo/feature/docker-and-k8s
Feature/docker and k8s
- Loading branch information
Showing
13 changed files
with
191 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,35 @@ | ||
# Imagem base com Go | ||
FROM golang:1.21-alpine | ||
# Etapa de build | ||
FROM golang:1.23.1-alpine AS builder | ||
|
||
# Diretório de trabalho dentro do container | ||
# Instala as dependências necessárias, incluindo o WebP | ||
RUN apk update && apk add --no-cache libwebp-dev gcc g++ make | ||
|
||
# Defina o diretório de trabalho | ||
WORKDIR /app | ||
|
||
# Copia o código-fonte para o container | ||
COPY . . | ||
# Copie os arquivos de dependências go.mod e go.sum | ||
COPY ./src/go.mod ./src/go.sum ./ | ||
|
||
# Instala as dependências do projeto | ||
# Baixe as dependências | ||
RUN go mod download | ||
|
||
# Compila o código Go | ||
RUN go build -o main . | ||
# Copie o código fonte | ||
COPY ./src . | ||
|
||
# Compile o binário, nomeando-o como "api" | ||
RUN go build -o api . | ||
|
||
# Etapa de produção | ||
FROM alpine:3.18 | ||
|
||
# Defina o diretório de trabalho | ||
WORKDIR /app | ||
|
||
# Copie apenas o binário gerado do estágio anterior | ||
COPY --from=builder /app/api /app/api | ||
|
||
# Expõe a porta que a API irá utilizar | ||
# Expõe a porta 8080 para acesso ao serviço | ||
EXPOSE 8080 | ||
|
||
# Comando para iniciar a API | ||
CMD ["./main"] | ||
# Comando padrão para executar o binário | ||
CMD ["/app/api"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Usa a imagem base do Flyway na versão 10 com Alpine Linux | ||
FROM flyway/flyway:10-alpine | ||
|
||
# Define o comando padrão a ser executado quando o contêiner for iniciado | ||
CMD ["migrate"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
create schema whatsmeow; | ||
create schema uatzapi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
VITE_ENVINRONMENT=APP_ENVINRONMENT | ||
VITE_API_KEY_TOKEN=APP_API_KEY_TOKEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Usa a imagem base do Node.js na versão 16 e nomeia esta fase como 'build' | ||
FROM node:16 AS build | ||
|
||
# Define variáveis de ambiente que podem ser passadas no momento da construção da imagem | ||
ARG APP_ENVINRONMENT | ||
ARG APP_API_KEY_TOKEN | ||
|
||
# Define as variáveis de ambiente com os valores recebidos dos argumentos | ||
ENV APP_ENVINRONMENT=$APP_ENVINRONMENT | ||
ENV APP_API_KEY_TOKEN=$APP_API_KEY_TOKEN | ||
|
||
# Define o diretório de trabalho para o aplicativo | ||
WORKDIR /app | ||
|
||
# Copia os arquivos de configuração do npm para o diretório de trabalho | ||
COPY package*.json ./ | ||
|
||
# Executa a instalação das dependências do npm | ||
RUN npm install | ||
|
||
# Copia todos os arquivos do projeto para o diretório de trabalho | ||
COPY . . | ||
|
||
# Executa o script de build do aplicativo | ||
RUN npm run build | ||
|
||
# Inicia uma nova fase a partir da imagem base do Nginx com Alpine | ||
FROM nginx:alpine | ||
|
||
# Copia os arquivos gerados na fase de build para o diretório do Nginx | ||
COPY --from=build /app/dist /usr/share/nginx/html | ||
|
||
# Define permissões para os arquivos copiados para o Nginx | ||
RUN chmod -R 755 /usr/share/nginx/html | ||
|
||
# Copia o arquivo de configuração do Nginx para o diretório apropriado | ||
COPY nginx.conf /etc/nginx/conf.d/default.conf | ||
|
||
# Copia o script de configuração de ambiente para o diretório de entrada do Docker | ||
COPY env.sh /docker-entrypoint.d/env.sh | ||
|
||
# Torna o script copiado executável | ||
RUN chmod +x /docker-entrypoint.d/env.sh | ||
|
||
# Expõe a porta 80 para acesso externo | ||
EXPOSE 80 | ||
|
||
# Comando para iniciar o Nginx em modo não daemon | ||
CMD ["nginx", "-g", "daemon off;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
for i in $(env | grep APP_) | ||
do | ||
key=$(echo $i | cut -d '=' -f 1) | ||
value=$(echo $i | cut -d '=' -f 2-) | ||
echo $key=$value | ||
# sed All files | ||
# find /usr/share/nginx/html -type f -exec sed -i "s|${key}|${value}|g" '{}' + | ||
|
||
# sed JS and CSS only | ||
find /usr/share/nginx/html -type f \( -name '*.js' -o -name '*.css' \) -exec sed -i "s|${key}|${value}|g" '{}' + | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
server { | ||
listen 80; | ||
server_name localhost; | ||
|
||
location / { | ||
root /usr/share/nginx/html; | ||
index index.html; | ||
try_files $uri $uri/ /index.html; # Redireciona para index.html se o arquivo não for encontrado | ||
} | ||
|
||
error_page 403 /403.html; | ||
location = /403.html { | ||
root /usr/share/nginx/html; | ||
} | ||
|
||
error_page 500 502 503 504 /50x.html; | ||
location = /50x.html { | ||
root /usr/share/nginx/html; | ||
} | ||
} |