Compare commits
26 Commits
docs/k8s-w
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2b2572a35 | ||
| e5dc346b96 | |||
|
|
16882046cf | ||
| fd17be5408 | |||
|
|
ecd298442b | ||
| 589fa2913c | |||
| 587d097d9b | |||
| a694af97c6 | |||
| 6523c5f520 | |||
| 0c09ee795e | |||
| 09396e334d | |||
| 605d68b4b0 | |||
| c707d4a065 | |||
| 0b28379145 | |||
| ca43de8756 | |||
| bb21ca33e4 | |||
| 48d6e64ada | |||
| e0731db836 | |||
| d2265390bd | |||
| a34c7c415c | |||
| 4975d5547d | |||
| fa6f0e0f49 | |||
| c9335a27e5 | |||
| 1270c04a2c | |||
|
|
ca892daffa | ||
| 8e09813741 |
@@ -1,23 +1,41 @@
|
|||||||
name: Deploy NestJS API
|
name: Build (develop) / Promote (main)
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push-deploy:
|
build-and-push-deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Login no Harbor
|
- name: Build and Push
|
||||||
run: |
|
run: |
|
||||||
echo "${{ secrets.HARBOR_PASSWORD }}" | docker login 172.35.0.216 -u ${{ secrets.HARBOR_USERNAME }} --password-stdin
|
REGISTRY="git.simplifiquehc.com.br"
|
||||||
|
IMAGE_NAME="$REGISTRY/simplifique/vendaweb-api"
|
||||||
|
SHA_TAG=$(echo ${{ gitea.sha }} | cut -c1-7)
|
||||||
|
|
||||||
- name: Build e Push
|
echo "${{ secrets.K8S }}" | docker login "$REGISTRY" -u "${{ gitea.actor }}" --password-stdin
|
||||||
|
|
||||||
|
docker build -t "$IMAGE_NAME:$SHA_TAG" -t "$IMAGE_NAME:latest" .
|
||||||
|
docker push "$IMAGE_NAME:$SHA_TAG"
|
||||||
|
docker push "$IMAGE_NAME:latest"
|
||||||
|
|
||||||
|
- name: Update Manifest and Push to Git
|
||||||
run: |
|
run: |
|
||||||
TAG=${{ gitea.sha }}
|
SHA_TAG=$(echo ${{ gitea.sha }} | cut -c1-7)
|
||||||
docker build -t 172.35.0.216/library/vendaweb-api:$TAG .
|
IMAGE_NAME="git.simplifiquehc.com.br/simplifique/vendaweb-api"
|
||||||
docker tag 172.35.0.216/library/vendaweb-api:$TAG 172.35.0.216/library/vendaweb-api:latest
|
|
||||||
|
|
||||||
docker push 172.35.0.216/library/vendaweb-api:$TAG
|
MANIFEST_FILE="k8s/overlays/prod/deployment-image-digest-patch.yaml"
|
||||||
docker push 172.35.0.216/library/vendaweb-api:latest
|
|
||||||
|
|
||||||
|
sed -i "s|image: $IMAGE_NAME:.*|image: $IMAGE_NAME:$SHA_TAG|g" "$MANIFEST_FILE"
|
||||||
|
|
||||||
|
git config user.name "Gitea Action"
|
||||||
|
git config user.email "actions@simplifiquehc.com.br"
|
||||||
|
|
||||||
|
git add "$MANIFEST_FILE"
|
||||||
|
git commit -m "chore: update image tag to $SHA_TAG [skip ci]"
|
||||||
|
git push origin main
|
||||||
|
|||||||
70
Dockerfile
70
Dockerfile
@@ -1,39 +1,55 @@
|
|||||||
# Estágio 1: Build
|
ARG NODE_VERSION=16.20
|
||||||
FROM node:16-bullseye-slim AS builder
|
ARG DEBIAN_VARIANT=bullseye
|
||||||
|
|
||||||
|
FROM node:${NODE_VERSION}-${DEBIAN_VARIANT} AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package*.json ./
|
|
||||||
RUN npm install --legacy-peer-deps
|
|
||||||
COPY . .
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
FROM node:16-bullseye-slim
|
ARG INSTANTCLIENT_ZIP_URL=https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip
|
||||||
# Instalar dependências do Oracle
|
RUN apt-get update \
|
||||||
RUN apt-get update && apt-get install -y \
|
&& apt-get install -y --no-install-recommends ca-certificates wget unzip libaio1 libnsl2 \
|
||||||
libaio1 \
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
unzip \
|
&& mkdir -p /opt/oracle \
|
||||||
wget \
|
&& wget -q "${INSTANTCLIENT_ZIP_URL}" -O /opt/oracle/instantclient.zip \
|
||||||
&& mkdir -p /opt/oracle
|
&& unzip -q /opt/oracle/instantclient.zip -d /opt/oracle \
|
||||||
|
&& rm /opt/oracle/instantclient.zip \
|
||||||
|
&& rm -f /opt/oracle/instantclient_*/ojdbc*.jar \
|
||||||
|
/opt/oracle/instantclient_*/ucp*.jar \
|
||||||
|
/opt/oracle/instantclient_*/xstreams.jar \
|
||||||
|
/opt/oracle/instantclient_*/adrci \
|
||||||
|
/opt/oracle/instantclient_*/genezi \
|
||||||
|
/opt/oracle/instantclient_*/uidrvci \
|
||||||
|
&& ln -s "$(ls -d /opt/oracle/instantclient_* | head -n 1)" /opt/oracle/instantclient
|
||||||
|
|
||||||
# Instalar Oracle Instant Client
|
|
||||||
RUN wget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basic-linuxx64.zip -O /opt/oracle/client.zip && \
|
|
||||||
unzip /opt/oracle/client.zip -d /opt/oracle && \
|
|
||||||
rm /opt/oracle/client.zip && \
|
|
||||||
ln -s /opt/oracle/instantclient_* /opt/oracle/instantclient
|
|
||||||
|
|
||||||
# Configurar o sistema para encontrar as bibliotecas do Oracle
|
|
||||||
ENV LD_LIBRARY_PATH=/opt/oracle/instantclient
|
ENV LD_LIBRARY_PATH=/opt/oracle/instantclient
|
||||||
RUN echo "/opt/oracle/instantclient" > /etc/ld.so.conf.d/oracle-instantclient.conf && ldconfig
|
ENV PATH=/opt/oracle/instantclient:$PATH
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
ENV NPM_CONFIG_LEGACY_PEER_DEPS=true
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build \
|
||||||
|
&& npm prune --omit=dev --legacy-peer-deps \
|
||||||
|
&& npm cache clean --force
|
||||||
|
|
||||||
|
FROM node:${NODE_VERSION}-${DEBIAN_VARIANT}-slim AS runtime
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copiar apenas o necessário do estágio anterior
|
ENV NODE_ENV=production
|
||||||
COPY --from=builder /app/dist ./dist
|
ENV LD_LIBRARY_PATH=/opt/oracle/instantclient
|
||||||
|
ENV PATH=/opt/oracle/instantclient:$PATH
|
||||||
|
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends libaio1 libnsl2 \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY --from=builder /opt/oracle /opt/oracle
|
||||||
COPY --from=builder /app/package*.json ./
|
COPY --from=builder /app/package*.json ./
|
||||||
COPY --from=builder /app/node_modules ./node_modules
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
|
COPY --from=builder /app/dist ./dist
|
||||||
|
|
||||||
# Variáveis de ambiente padrão para o driver oracledb
|
EXPOSE 8065
|
||||||
ENV OCI_LIB_DIR=/opt/oracle/instantclient
|
|
||||||
ENV OCI_INC_DIR=/opt/oracle/instantclient/sdk/include
|
|
||||||
|
|
||||||
CMD ["npm", "run", "start:prod"]
|
CMD ["node", "dist/main"]
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
# Documentação do Kubernetes
|
|
||||||
|
|
||||||
Este documento descreve a infraestrutura e configuração do Kubernetes para o projeto **Vendaweb-api**, utilizando uma abordagem GitOps com ArgoCD e Kustomize.
|
|
||||||
|
|
||||||
## Estrutura de Diretórios e Arquivos
|
|
||||||
|
|
||||||
A configuração do Kubernetes está localizada no diretório `k8s/` e segue uma estrutura organizada para facilitar a manutenção e escalabilidade:
|
|
||||||
|
|
||||||
```
|
|
||||||
k8s/
|
|
||||||
├── argocd/ # Configurações do ArgoCD
|
|
||||||
│ └── application-prod.yaml # Definição da Application para o ambiente de produção
|
|
||||||
├── base/ # Recursos base do Kubernetes (Kustomize Base)
|
|
||||||
│ ├── configmap.yaml # ConfigMap base
|
|
||||||
│ ├── deployment.yaml # Deployment base da aplicação
|
|
||||||
│ ├── kustomization.yaml # Arquivo principal do Kustomize Base
|
|
||||||
│ ├── secret.yaml # Secret base
|
|
||||||
│ └── service.yaml # Service base
|
|
||||||
└── overlays/ # Sobrescritas para diferentes ambientes (Kustomize Overlays)
|
|
||||||
└── prod/ # Ambiente de produção
|
|
||||||
├── application-prod.yaml
|
|
||||||
├── deployment-image-digest-patch.yaml
|
|
||||||
├── kustomization.yaml
|
|
||||||
└── service-patch.yaml
|
|
||||||
```
|
|
||||||
|
|
||||||
## Recursos Base (`k8s/base`)
|
|
||||||
|
|
||||||
O diretório `base` contém as definições padrão dos recursos que são comuns a todos os ambientes.
|
|
||||||
|
|
||||||
### Deployment (`deployment.yaml`)
|
|
||||||
|
|
||||||
- **Nome**: `vendaweb-api`
|
|
||||||
- **Replicas**: 15 (Configuração base)
|
|
||||||
- **Imagem**: `172.35.0.216/library/vendaweb-api:latest`
|
|
||||||
- **Porta do Container**: 8065
|
|
||||||
- **Resources**:
|
|
||||||
- Requests: CPU 100m, Memory 256Mi
|
|
||||||
- Limits: CPU 500m, Memory 512Mi
|
|
||||||
- **Probes**: Liveness, Readiness e Startup probes configurados no endpoint `/v1/health`.
|
|
||||||
- **Environment**: Configurações carregadas via ConfigMap e Secret.
|
|
||||||
|
|
||||||
### Service (`service.yaml`)
|
|
||||||
|
|
||||||
- **Tipo**: ClusterIP
|
|
||||||
- **Porta**: 8065 (TCP)
|
|
||||||
|
|
||||||
## Ambientes (`k8s/overlays`)
|
|
||||||
|
|
||||||
### Produção (`k8s/overlays/prod`)
|
|
||||||
|
|
||||||
A sobreposição de produção personaliza a configuração base para o ambiente produtivo.
|
|
||||||
|
|
||||||
- **Namespace**: `vendaweb-prod`
|
|
||||||
- **Patches**: Aplica modificações específicas (ex: digest da imagem, configurações específicas de serviço) via `kustomization.yaml`.
|
|
||||||
|
|
||||||
## Deploy com ArgoCD (`k8s/argocd`)
|
|
||||||
|
|
||||||
O deploy é gerenciado pelo ArgoCD, que sincroniza o estado do cluster com o repositório Git.
|
|
||||||
|
|
||||||
### Application (`application-prod.yaml`)
|
|
||||||
|
|
||||||
- **Nome**: `vendaweb-api-prod`
|
|
||||||
- **Namespace do ArgoCD**: `argocd`
|
|
||||||
- **Origem (Source)**:
|
|
||||||
- Repositório: `https://git.simplifiquehc.com.br/simplifique/Vendaweb-api.git`
|
|
||||||
- Revisão: `main`
|
|
||||||
- Path: `k8s/overlays/prod` (Aponta para o overlay de produção)
|
|
||||||
- **Destino (Destination)**:
|
|
||||||
- Cluster: `https://kubernetes.default.svc`
|
|
||||||
- Namespace: `vendaweb-api` (Nota: O patch define `vendaweb-prod`, verifique a consistência)
|
|
||||||
- **Sync Policy**: Automatizado com `selfHeal` ativado e criação automática de namespace.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Observação**: Certifique-se de que as credenciais do Harbor (`imagePullSecrets`) estejam corretamente configuradas no namespace de destino para permitir o pull da imagem.
|
|
||||||
@@ -14,7 +14,7 @@ Os workflows estão definidos no diretório `.gitea/workflows/`. O principal wor
|
|||||||
|
|
||||||
Este workflow é acionado automaticamente no evento:
|
Este workflow é acionado automaticamente no evento:
|
||||||
|
|
||||||
- `push`: Em qualquer branch (configuração atual `on: [push]`).
|
- `push`: Na branch `main`.
|
||||||
|
|
||||||
### Jobs
|
### Jobs
|
||||||
|
|
||||||
@@ -39,10 +39,13 @@ Este job é responsável por construir a imagem Docker e enviá-la para o regist
|
|||||||
3. **Build e Push**
|
3. **Build e Push**
|
||||||
- Constrói a imagem Docker da aplicação.
|
- Constrói a imagem Docker da aplicação.
|
||||||
- Tags geradas:
|
- Tags geradas:
|
||||||
- `172.35.0.216/library/vendaweb-api:$TAG` (onde `$TAG` é o SHA do commit do Gitea `gitea.sha`)
|
- `git.simplifiquehc.com.br/simplifique/vendaweb-api:$TAG` (onde `$TAG` é o SHA curto do commit)
|
||||||
- `172.35.0.216/library/vendaweb-api:latest`
|
- `git.simplifiquehc.com.br/simplifique/vendaweb-api:latest`
|
||||||
- Envia ambas as tags para o registry.
|
- Envia ambas as tags para o registry.
|
||||||
|
|
||||||
|
4. **Atualizar Manifest e Push no Git**
|
||||||
|
- Atualiza `k8s/overlays/prod/deployment-image-digest-patch.yaml` para apontar para a tag `$TAG`.
|
||||||
|
|
||||||
## Variáveis e Segredos (Secrets)
|
## Variáveis e Segredos (Secrets)
|
||||||
|
|
||||||
Para que o workflow funcione corretamente, as seguintes secrets devem estar configuradas nas configurações do repositório no Gitea:
|
Para que o workflow funcione corretamente, as seguintes secrets devem estar configuradas nas configurações do repositório no Gitea:
|
||||||
|
|||||||
156
k8s/README.md
Normal file
156
k8s/README.md
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
# Kubernetes Infra (k8s) - vendaweb-api
|
||||||
|
|
||||||
|
Este diretorio contem os manifests Kubernetes do `vendaweb-api` usando Kustomize (base + overlays).
|
||||||
|
|
||||||
|
## Visao geral
|
||||||
|
|
||||||
|
- App: `vendaweb-api` (Deployment + Service)
|
||||||
|
- Porta HTTP do container/Service: `8067`
|
||||||
|
- Healthcheck usado pelos probes: `GET /v1/health`
|
||||||
|
- Config via `ConfigMap` + `Secret` (injetados com `envFrom`)
|
||||||
|
- Overlay prod:
|
||||||
|
- Namespace: `vendaweb-prod`
|
||||||
|
- Service: `NodePort` (porta externa `30001`)
|
||||||
|
- Replicas: `15`
|
||||||
|
|
||||||
|
## Estrutura
|
||||||
|
|
||||||
|
- `k8s/base/`
|
||||||
|
- `deployment.yaml`: deployment padrao (replicas 3), porta 8067, probes `/v1/health`, `imagePullSecrets: gitea-auth`
|
||||||
|
- `service.yaml`: `ClusterIP` expondo 8067
|
||||||
|
- `configmap.yaml`: variaveis nao sensiveis (ex.: Redis/DB host/port)
|
||||||
|
- `secret.yaml`: variaveis sensiveis (ex.: usuario/senha do DB)
|
||||||
|
- `kustomization.yaml`: agrega os recursos do base
|
||||||
|
|
||||||
|
- `k8s/overlays/prod/`
|
||||||
|
- `kustomization.yaml`: aplica patches e define `namespace: vendaweb-prod`
|
||||||
|
- `service-patch.yaml`: muda Service para `NodePort` e fixa `nodePort: 30001`
|
||||||
|
- `deployment-prod-patch.yaml`: ajusta `replicas: 15`
|
||||||
|
- `deployment-image-digest-patch.yaml`: sobrescreve a `image:` do container
|
||||||
|
|
||||||
|
- `k8s/argocd/application-prod.yaml`
|
||||||
|
- Aplica o overlay `k8s/overlays/prod` via Argo CD
|
||||||
|
- Sync automatizado com `selfHeal` e `prune`
|
||||||
|
|
||||||
|
## Portas e acesso
|
||||||
|
|
||||||
|
- Dentro do cluster: Service `vendaweb-api:8067`
|
||||||
|
- Overlay prod (NodePort): porta externa `30001` (mapeia para `8067`)
|
||||||
|
|
||||||
|
Notas:
|
||||||
|
|
||||||
|
- O processo Node/Nest escuta em `8067` (ver `src/main.ts`).
|
||||||
|
- A variavel `PORT` em `.env` nao e usada pelo bootstrap atual; o k8s esta configurado para 8067.
|
||||||
|
|
||||||
|
## Deploy com kubectl/kustomize
|
||||||
|
|
||||||
|
Gerar o YAML final (sem aplicar):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl kustomize k8s/overlays/prod
|
||||||
|
```
|
||||||
|
|
||||||
|
Aplicar o overlay prod:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl apply -k k8s/overlays/prod
|
||||||
|
```
|
||||||
|
|
||||||
|
Validar o que sera aplicado (dry-run):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl apply -k k8s/overlays/prod --dry-run=server
|
||||||
|
```
|
||||||
|
|
||||||
|
Ver diffs (se seu kubectl suportar):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl diff -k k8s/overlays/prod
|
||||||
|
```
|
||||||
|
|
||||||
|
## Argo CD (prod)
|
||||||
|
|
||||||
|
O Argo CD esta configurado em `k8s/argocd/application-prod.yaml` para:
|
||||||
|
|
||||||
|
- `path: k8s/overlays/prod`
|
||||||
|
- `targetRevision: main`
|
||||||
|
- `destination.namespace: vendaweb-prod` (com `CreateNamespace=true`)
|
||||||
|
|
||||||
|
Se voce esta usando Argo CD, o fluxo recomendado e:
|
||||||
|
|
||||||
|
- atualizar manifests no Git (overlay prod)
|
||||||
|
- deixar o Argo CD sincronizar automaticamente
|
||||||
|
|
||||||
|
## Configuracao (ConfigMap/Secret)
|
||||||
|
|
||||||
|
- `k8s/base/configmap.yaml` (`vendaweb-api-config`)
|
||||||
|
- `REDIS_HOST`, `REDIS_PORT`, `DB_HOST`, `DB_PORT`, `DB_SERVICE_NAME`
|
||||||
|
- `k8s/base/secret.yaml` (`vendaweb-api-secrets`)
|
||||||
|
- `DB_USERNAME`, `DB_PASSWORD`
|
||||||
|
|
||||||
|
Importante:
|
||||||
|
|
||||||
|
- O `Secret` esta em `stringData` no repositorio (texto puro). Para ambiente real, prefira um gerenciador de segredos (ExternalSecrets, SOPS, Vault etc.) e nao commite credenciais.
|
||||||
|
|
||||||
|
## Imagem e pipeline
|
||||||
|
|
||||||
|
O workflow `.gitea/workflows/deploy-api.yaml`:
|
||||||
|
|
||||||
|
- builda e publica `git.simplifiquehc.com.br/simplifique/vendaweb-api:<sha7>` e `:latest`
|
||||||
|
- atualiza `k8s/overlays/prod/deployment-image-digest-patch.yaml` para apontar para o tag do commit
|
||||||
|
|
||||||
|
Isso e pensado para o Argo CD detectar a alteracao no Git e aplicar.
|
||||||
|
|
||||||
|
## Comandos uteis (day-2)
|
||||||
|
|
||||||
|
Assumindo namespace `vendaweb-prod`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl -n vendaweb-prod get all
|
||||||
|
kubectl -n vendaweb-prod get pods -l app=vendaweb-api -o wide
|
||||||
|
kubectl -n vendaweb-prod describe deploy/vendaweb-api
|
||||||
|
kubectl -n vendaweb-prod describe pod -l app=vendaweb-api
|
||||||
|
```
|
||||||
|
|
||||||
|
Logs:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl -n vendaweb-prod logs deploy/vendaweb-api --tail=200
|
||||||
|
kubectl -n vendaweb-prod logs -l app=vendaweb-api --tail=200 --all-containers
|
||||||
|
kubectl -n vendaweb-prod logs -l app=vendaweb-api -f
|
||||||
|
```
|
||||||
|
|
||||||
|
Rollout:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl -n vendaweb-prod rollout status deploy/vendaweb-api
|
||||||
|
kubectl -n vendaweb-prod rollout history deploy/vendaweb-api
|
||||||
|
kubectl -n vendaweb-prod rollout restart deploy/vendaweb-api
|
||||||
|
```
|
||||||
|
|
||||||
|
Exec/Debug:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl -n vendaweb-prod exec -it deploy/vendaweb-api -- sh
|
||||||
|
kubectl -n vendaweb-prod port-forward svc/vendaweb-api 8067:8067
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting rapido
|
||||||
|
|
||||||
|
- `ImagePullBackOff`:
|
||||||
|
- conferir `imagePullSecrets: gitea-auth` no namespace (`kubectl -n vendaweb-prod get secret gitea-auth`)
|
||||||
|
- conferir o valor de `image:` no overlay prod
|
||||||
|
|
||||||
|
- `CrashLoopBackOff`:
|
||||||
|
- ver logs do pod e eventos (`kubectl -n vendaweb-prod describe pod ...`)
|
||||||
|
- validar variaveis do `ConfigMap`/`Secret`
|
||||||
|
|
||||||
|
- Probes falhando:
|
||||||
|
- garantir que a rota `/v1/health` responde 200 e que a app esta ouvindo em `8067`
|
||||||
|
|
||||||
|
## Mudancas comuns
|
||||||
|
|
||||||
|
- Alterar porta externa (NodePort): `k8s/overlays/prod/service-patch.yaml`
|
||||||
|
- Alterar replicas em prod: `k8s/overlays/prod/deployment-prod-patch.yaml`
|
||||||
|
- Alterar imagem/tag em prod: `k8s/overlays/prod/deployment-image-digest-patch.yaml`
|
||||||
|
- Alterar envs: `k8s/base/configmap.yaml` e `k8s/base/secret.yaml`
|
||||||
@@ -11,9 +11,17 @@ spec:
|
|||||||
path: k8s/overlays/prod
|
path: k8s/overlays/prod
|
||||||
destination:
|
destination:
|
||||||
server: https://kubernetes.default.svc
|
server: https://kubernetes.default.svc
|
||||||
namespace: vendaweb-api
|
namespace: vendaweb-prod
|
||||||
syncPolicy:
|
syncPolicy:
|
||||||
automated:
|
automated:
|
||||||
selfHeal: true
|
selfHeal: true
|
||||||
|
prune: true
|
||||||
|
retry:
|
||||||
|
limit: 2
|
||||||
|
backoff:
|
||||||
|
duration: 5s
|
||||||
|
factor: 2
|
||||||
|
maxDuration: 3m
|
||||||
syncOptions:
|
syncOptions:
|
||||||
- CreateNamespace=true
|
- CreateNamespace=true
|
||||||
|
- PruneLast=true
|
||||||
|
|||||||
@@ -5,7 +5,15 @@ metadata:
|
|||||||
labels:
|
labels:
|
||||||
app: vendaweb-api
|
app: vendaweb-api
|
||||||
spec:
|
spec:
|
||||||
replicas: 15
|
replicas: 3
|
||||||
|
revisionHistoryLimit: 5
|
||||||
|
minReadySeconds: 10
|
||||||
|
progressDeadlineSeconds: 600
|
||||||
|
strategy:
|
||||||
|
type: RollingUpdate
|
||||||
|
rollingUpdate:
|
||||||
|
maxSurge: 1
|
||||||
|
maxUnavailable: 0
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: vendaweb-api
|
app: vendaweb-api
|
||||||
@@ -15,10 +23,11 @@ spec:
|
|||||||
app: vendaweb-api
|
app: vendaweb-api
|
||||||
spec:
|
spec:
|
||||||
imagePullSecrets:
|
imagePullSecrets:
|
||||||
- name: harbor-secret
|
- name: gitea-auth
|
||||||
|
terminationGracePeriodSeconds: 30
|
||||||
containers:
|
containers:
|
||||||
- name: api
|
- name: api
|
||||||
image: 172.35.0.216/library/vendaweb-api:latest
|
image: git.simplifiquehc.com.br/simplifique/vendaweb-api:589fa29
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: IfNotPresent
|
||||||
ports:
|
ports:
|
||||||
- name: http
|
- name: http
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: api
|
- name: api
|
||||||
image: 172.35.0.216/library/vendaweb-api@sha256:aac490fcb4ef7baa95f1df01fa50d2d44bdb4ed12b235e5dd89e1d7dc3cd0a3a
|
image: git.simplifiquehc.com.br/simplifique/vendaweb-api:e5dc346
|
||||||
|
|||||||
6
k8s/overlays/prod/deployment-prod-patch.yaml
Normal file
6
k8s/overlays/prod/deployment-prod-patch.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: vendaweb-api
|
||||||
|
spec:
|
||||||
|
replicas: 15
|
||||||
@@ -7,5 +7,6 @@ resources:
|
|||||||
- ../../base
|
- ../../base
|
||||||
|
|
||||||
patches:
|
patches:
|
||||||
- path: deployment-image-digest-patch.yaml
|
|
||||||
- path: service-patch.yaml
|
- path: service-patch.yaml
|
||||||
|
- path: deployment-prod-patch.yaml
|
||||||
|
- path: deployment-image-digest-patch.yaml
|
||||||
|
|||||||
19
src/main.ts
19
src/main.ts
@@ -6,20 +6,25 @@ import 'reflect-metadata';
|
|||||||
import { CustomLoggerService } from './services/custom-logger.service';
|
import { CustomLoggerService } from './services/custom-logger.service';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule, { cors: true, logger: new CustomLoggerService()});
|
const app = await NestFactory.create(AppModule, {
|
||||||
|
cors: true,
|
||||||
|
logger: new CustomLoggerService(),
|
||||||
|
});
|
||||||
app.enableCors();
|
app.enableCors();
|
||||||
app.use(compression());
|
app.use(compression());
|
||||||
const options = new DocumentBuilder()
|
const options = new DocumentBuilder()
|
||||||
.setTitle('API Venda web')
|
.setTitle('API Venda web')
|
||||||
.setDescription(`API criada para realizar todo processo da venda assistida, como criação de oraçamento de venda, pedido de venda
|
.setDescription(
|
||||||
|
`API criada para realizar todo processo da venda assistida, como criação de oraçamento de venda, pedido de venda
|
||||||
cadastro de novos clientes, novos endereços. A API também fornece dados para o portal de parceiros como a manutenção
|
cadastro de novos clientes, novos endereços. A API também fornece dados para o portal de parceiros como a manutenção
|
||||||
do cadastro de parceiros, consulta de venda de movimentação e pagamentos, e fechamento das comissões dos parceiros.`)
|
do cadastro de parceiros, consulta de venda de movimentação e pagamentos, e fechamento das comissões dos parceiros.`,
|
||||||
.setVersion("2023.1.2")
|
)
|
||||||
.addTag("VendaWeb")
|
.setVersion('2023.1.2')
|
||||||
.addTag("Autenticação")
|
.addTag('VendaWeb')
|
||||||
|
.addTag('Auth')
|
||||||
.build();
|
.build();
|
||||||
const document = SwaggerModule.createDocument(app, options);
|
const document = SwaggerModule.createDocument(app, options);
|
||||||
SwaggerModule.setup("docs", app, document);
|
SwaggerModule.setup('docs', app, document);
|
||||||
await app.listen(8067);
|
await app.listen(8067);
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|||||||
@@ -527,6 +527,7 @@ export class OrderService {
|
|||||||
preOrder.esc_ajustarfinanceiro = "N";
|
preOrder.esc_ajustarfinanceiro = "N";
|
||||||
preOrder.esc_obternsu = "N";
|
preOrder.esc_obternsu = "N";
|
||||||
preOrder.esc_vloutrasdespweb = 0;
|
preOrder.esc_vloutrasdespweb = 0;
|
||||||
|
preOrder.vloutrasdesp = cart.shippingValue;
|
||||||
preOrder.pedidopagoecommerce = "S";
|
preOrder.pedidopagoecommerce = "S";
|
||||||
preOrder.numpedmktplace = "";
|
preOrder.numpedmktplace = "";
|
||||||
preOrder.numitens = cart.itens.length;
|
preOrder.numitens = cart.itens.length;
|
||||||
@@ -643,34 +644,34 @@ export class OrderService {
|
|||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
if (cart.shippingValue > 0) {
|
// if (cart.shippingValue > 0) {
|
||||||
const itemOrder = new Pcpeditemp();
|
// const itemOrder = new Pcpeditemp();
|
||||||
itemOrder.tipointegracao = "W";
|
// itemOrder.tipointegracao = "W";
|
||||||
itemOrder.integradora = 10;
|
// itemOrder.integradora = 10;
|
||||||
itemOrder.numpedrca = idPreOrder;
|
// itemOrder.numpedrca = idPreOrder;
|
||||||
itemOrder.numpedweb = idPreOrder;
|
// itemOrder.numpedweb = idPreOrder;
|
||||||
itemOrder.codcli = cart.idCustomer;
|
// itemOrder.codcli = cart.idCustomer;
|
||||||
itemOrder.codusur = idSellerPreorder; //cart.idSeller;
|
// itemOrder.codusur = idSellerPreorder; //cart.idSeller;
|
||||||
itemOrder.numseq = numeroSeq;
|
// itemOrder.numseq = numeroSeq;
|
||||||
itemOrder.codprod = 48500;
|
// itemOrder.codprod = 48500;
|
||||||
itemOrder.codauxiliar = 48500;
|
// itemOrder.codauxiliar = 48500;
|
||||||
itemOrder.codfilialretira = '12';
|
// itemOrder.codfilialretira = '12';
|
||||||
itemOrder.tipoentrega = 'EF';
|
// itemOrder.tipoentrega = 'EF';
|
||||||
itemOrder.ptabela = Number.parseFloat(cart.shippingValue.toString());
|
// itemOrder.ptabela = Number.parseFloat(cart.shippingValue.toString());
|
||||||
itemOrder.pvenda = Number.parseFloat(cart.shippingValue.toString());
|
// itemOrder.pvenda = Number.parseFloat(cart.shippingValue.toString());
|
||||||
itemOrder.qt = 1;
|
// itemOrder.qt = 1;
|
||||||
itemOrder.data = new Date();
|
// itemOrder.data = new Date();
|
||||||
|
|
||||||
|
|
||||||
await queryRunner.manager
|
// await queryRunner.manager
|
||||||
.createQueryBuilder()
|
// .createQueryBuilder()
|
||||||
.insert()
|
// .insert()
|
||||||
.into(Pcpeditemp)
|
// .into(Pcpeditemp)
|
||||||
.values(itemOrder)
|
// .values(itemOrder)
|
||||||
.execute();
|
// .execute();
|
||||||
|
|
||||||
numeroSeq = numeroSeq + 1;
|
// numeroSeq = numeroSeq + 1;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// execute some operations on this transaction:
|
// execute some operations on this transaction:
|
||||||
await queryRunner.manager
|
await queryRunner.manager
|
||||||
|
|||||||
@@ -1448,7 +1448,7 @@ export class SalesService {
|
|||||||
const queryRunner = connectionDb.createQueryRunner();
|
const queryRunner = connectionDb.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
try {
|
try {
|
||||||
const sql = 'SELECT ESVCALCULOFRETE.CODTABELAFRETE as "id" ' +
|
/*const sql = 'SELECT ESVCALCULOFRETE.CODTABELAFRETE as "id" ' +
|
||||||
' ,ESVCALCULOFRETE.CODFILIAL as "store" ' +
|
' ,ESVCALCULOFRETE.CODFILIAL as "store" ' +
|
||||||
' ,ESVCALCULOFRETE.CODCIDADE as "cityId" ' +
|
' ,ESVCALCULOFRETE.CODCIDADE as "cityId" ' +
|
||||||
' ,PCCIDADE.NOMECIDADE as "cityName" ' +
|
' ,PCCIDADE.NOMECIDADE as "cityName" ' +
|
||||||
@@ -1462,7 +1462,22 @@ export class SalesService {
|
|||||||
' AND ESVCALCULOFRETE.CODCIDADE = PCCIDADE.CODCIDADE ' +
|
' AND ESVCALCULOFRETE.CODCIDADE = PCCIDADE.CODCIDADE ' +
|
||||||
' AND ESVCALCULOFRETE.CODCIDADE = :1 ' +
|
' AND ESVCALCULOFRETE.CODCIDADE = :1 ' +
|
||||||
' AND ESVCALCULOFRETE.IDCART = :2 ' +
|
' AND ESVCALCULOFRETE.IDCART = :2 ' +
|
||||||
' ORDER BY VLFRETE';
|
' ORDER BY VLFRETE';*/
|
||||||
|
|
||||||
|
const sql = `SELECT 0 as "id"
|
||||||
|
,'1' as "store"
|
||||||
|
,ESVCALCULOFRETE.CODCIDADE as "cityId"
|
||||||
|
,PCCIDADE.NOMECIDADE as "cityName"
|
||||||
|
,NULL as "carrierId"
|
||||||
|
,'SIMPLIFIQUE HOMECENTER' as "carrierName"
|
||||||
|
,0 as "minSale"
|
||||||
|
,ESVCALCULOFRETE.VLFRETE as "deliveryValue"
|
||||||
|
,NULL as "deliveryTime"
|
||||||
|
FROM ESVCALCULOFRETE, PCCIDADE
|
||||||
|
WHERE ESVCALCULOFRETE.CODCIDADE = PCCIDADE.CODCIDADE
|
||||||
|
AND ESVCALCULOFRETE.CODCIDADE = :1
|
||||||
|
AND ESVCALCULOFRETE.IDCART = :2
|
||||||
|
ORDER BY VLFRETE`;
|
||||||
|
|
||||||
const deliveryTaxTable = await queryRunner.manager
|
const deliveryTaxTable = await queryRunner.manager
|
||||||
.query(sql, [cityId, cartId]);
|
.query(sql, [cityId, cartId]);
|
||||||
@@ -1514,7 +1529,22 @@ export class SalesService {
|
|||||||
const queryRunner = connectionDb.createQueryRunner();
|
const queryRunner = connectionDb.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
try {
|
try {
|
||||||
const sql = 'SELECT ESVCALCULOFRETE.CODTABELAFRETE as "id" ' +
|
const sql = `SELECT 0 as "id"
|
||||||
|
,'1' as "store"
|
||||||
|
,ESVCALCULOFRETE.CODCIDADE as "cityId"
|
||||||
|
,PCCIDADE.NOMECIDADE as "cityName"
|
||||||
|
,NULL as "carrierId"
|
||||||
|
,'SIMPLIFIQUE HOMECENTER' as "carrierName"
|
||||||
|
,0 as "minSale"
|
||||||
|
,ESVCALCULOFRETE.VLFRETE as "deliveryValue"
|
||||||
|
,NULL as "deliveryTime"
|
||||||
|
FROM ESVCALCULOFRETE, PCCIDADE
|
||||||
|
WHERE ESVCALCULOFRETE.CODCIDADE = PCCIDADE.CODCIDADE
|
||||||
|
AND ESVCALCULOFRETE.CODCIDADE = :1
|
||||||
|
AND ESVCALCULOFRETE.IDCART = :2
|
||||||
|
ORDER BY VLFRETE`;
|
||||||
|
|
||||||
|
/*const sql = 'SELECT ESVCALCULOFRETE.CODTABELAFRETE as "id" ' +
|
||||||
' ,ESVCALCULOFRETE.CODFILIAL as "store" ' +
|
' ,ESVCALCULOFRETE.CODFILIAL as "store" ' +
|
||||||
' ,ESVCALCULOFRETE.CODCIDADE as "cityId" ' +
|
' ,ESVCALCULOFRETE.CODCIDADE as "cityId" ' +
|
||||||
' ,PCCIDADE.NOMECIDADE as "cityName" ' +
|
' ,PCCIDADE.NOMECIDADE as "cityName" ' +
|
||||||
@@ -1528,7 +1558,7 @@ export class SalesService {
|
|||||||
' AND ESVCALCULOFRETE.CODCIDADE = PCCIDADE.CODCIDADE ' +
|
' AND ESVCALCULOFRETE.CODCIDADE = PCCIDADE.CODCIDADE ' +
|
||||||
' AND ESVCALCULOFRETE.CODCIDADE = :1 ' +
|
' AND ESVCALCULOFRETE.CODCIDADE = :1 ' +
|
||||||
' AND ESVCALCULOFRETE.IDCART = :2 ' +
|
' AND ESVCALCULOFRETE.IDCART = :2 ' +
|
||||||
' ORDER BY VLFRETE';
|
' ORDER BY VLFRETE';*/
|
||||||
|
|
||||||
let deliveryTaxTable = await queryRunner.manager
|
let deliveryTaxTable = await queryRunner.manager
|
||||||
.query(sql, [dataDeliveryTax.cityId, dataDeliveryTax.cartId]);
|
.query(sql, [dataDeliveryTax.cityId, dataDeliveryTax.cartId]);
|
||||||
|
|||||||
Reference in New Issue
Block a user