Merge pull request 'feature/ci-cd' (#1) from feature/ci-cd into dev
Reviewed-on: https://git.dejodigital.com.br/dejo-core/dejo-node/pulls/1
This commit is contained in:
2
.env.example
Executable file
2
.env.example
Executable file
@ -0,0 +1,2 @@
|
||||
NODE_ENV=local
|
||||
|
||||
212
.gitea/workflows/ci-and-cd.yml
Normal file
212
.gitea/workflows/ci-and-cd.yml
Normal file
@ -0,0 +1,212 @@
|
||||
# .gitea/workflows/ci-and-cd.yml
|
||||
name: CI & CD
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- dev
|
||||
|
||||
jobs:
|
||||
lint_commits:
|
||||
name: Lint Commits
|
||||
runs-on: [self-hosted]
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Dependencies
|
||||
env:
|
||||
NODE_ENV: development
|
||||
NPM_CONFIG_PRODUCTION: 'false'
|
||||
run: npm ci --no-audit
|
||||
|
||||
- name: Lint Commit Messages
|
||||
# Se qualquer mensagem não corresponder ao Conventional Commits, este step falha
|
||||
run: npx commitlint --from=origin/master --to=HEAD
|
||||
|
||||
release:
|
||||
name: Release
|
||||
needs: lint_commits # só roda se lint_commits passar
|
||||
runs-on: [self-hosted]
|
||||
outputs:
|
||||
sha_short: ${{ steps.commit_short.outputs.sha_short }}
|
||||
is_tagged: ${{ steps.check_tag.outputs.is_tagged }}
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
|
||||
- name: Commit Short Hash
|
||||
id: commit_short
|
||||
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm ci --no-audit
|
||||
|
||||
- name: Run Semantic Release
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GITEA_URL: https://git.dejodigital.com.br
|
||||
run: npx semantic-release
|
||||
|
||||
- name: Check if Release Tag Exists
|
||||
id: check_tag
|
||||
run: |
|
||||
if git tag --points-at HEAD | grep -q '^v'; then
|
||||
echo "is_tagged=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "is_tagged=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
build_and_push:
|
||||
name: Docker | Build and Push
|
||||
needs: release
|
||||
if: ${{ needs.release.outputs.is_tagged == 'true' }} # só roda se semantic-release criou tag
|
||||
runs-on: [self-hosted]
|
||||
env:
|
||||
DEJO_NODE_AWS_REGION: us-east-1
|
||||
AWS_ECR_REPOSITORY: dev-dejo/dejo-node
|
||||
DISABLE_DISCORD_NOTIFY: true
|
||||
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
|
||||
sha_short: ${{ needs.release.outputs.sha_short }}
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Discord | Notify Start
|
||||
if: ${{ env.DISABLE_DISCORD_NOTIFY != 'true' }}
|
||||
run: |
|
||||
TAG=${GITHUB_REF#refs/tags/}
|
||||
curl -X POST -H "Content-Type: application/json" \
|
||||
-d "{\"content\": \":arrow_forward: Deploy da versão **${TAG}** iniciado...\"}" \
|
||||
"${DISCORD_WEBHOOK}"
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Copy Env
|
||||
run: cp infrastructure/.env.example infrastructure/.env
|
||||
|
||||
- name: Cache Docker layers
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: /tmp/.buildx-cache
|
||||
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
||||
restore-keys: ${{ runner.os }}-buildx
|
||||
|
||||
- name: Docker Login to AWS ECR
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ${{ secrets.DEV_DEJO_AWS_ECR_REGISTRY }}
|
||||
username: ${{ secrets.DEJO_NODE_AWS_ACCESS_KEY }}
|
||||
password: ${{ secrets.DEJO_NODE_AWS_SECRET_KEY }}
|
||||
|
||||
- name: Build and Push Backend
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: infrastructure
|
||||
file: infrastructure/Dockerfile
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.DEV_DEJO_AWS_ECR_REGISTRY }}/${{ env.AWS_ECR_REPOSITORY }}:latest
|
||||
${{ secrets.DEV_DEJO_AWS_ECR_REGISTRY }}/${{ env.AWS_ECR_REPOSITORY }}:${{ env.sha_short }}
|
||||
cache-from: type=local,src=/tmp/.buildx-cache
|
||||
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
|
||||
|
||||
- name: Moving Cache
|
||||
run: |
|
||||
rm -rf /tmp/.buildx-cache
|
||||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
||||
|
||||
kustomize_apply:
|
||||
name: Kubernetes | Kustomize Apply
|
||||
needs: build_and_push
|
||||
runs-on: [self-hosted]
|
||||
env:
|
||||
DEJO_NODE_AWS_REGION: us-east-1
|
||||
KUBE_NAMESPACE: dejo-node
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Configure AWS Credentials
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.DEJO_NODE_AWS_ACCESS_KEY }}
|
||||
aws-secret-access-key: ${{ secrets.DEJO_NODE_AWS_SECRET_KEY }}
|
||||
aws-region: ${{ env.DEJO_NODE_AWS_REGION }}
|
||||
|
||||
- name: Apply Kustomize
|
||||
run: |
|
||||
echo "${{ secrets.DEJO_NODE_KUBE_CONFIG_DATA_DEV }}" | base64 -d > kubeconfig
|
||||
export KUBECONFIG=$PWD/kubeconfig
|
||||
kubectl apply -k infrastructure/kubernetes/dev -n "${KUBE_NAMESPACE}"
|
||||
|
||||
deploy_backend:
|
||||
name: Kubernetes | Deploy App
|
||||
needs: kustomize_apply
|
||||
runs-on: [self-hosted]
|
||||
env:
|
||||
DEJO_NODE_AWS_REGION: us-east-1
|
||||
AWS_ECR_REPOSITORY: dev-dejo/dejo-node
|
||||
KUBE_NAMESPACE: dejo-node
|
||||
KUBE_DEPLOY_NAME: api-app
|
||||
DISABLE_DISCORD_NOTIFY: true
|
||||
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
|
||||
sha_short: ${{ needs.release.outputs.sha_short }}
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Configure AWS Credentials
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.DEJO_NODE_AWS_ACCESS_KEY }}
|
||||
aws-secret-access-key: ${{ secrets.DEJO_NODE_AWS_SECRET_KEY }}
|
||||
aws-region: ${{ env.DEJO_NODE_AWS_REGION }}
|
||||
|
||||
- name: Deploy API
|
||||
run: |
|
||||
echo "${{ secrets.DEJO_NODE_KUBE_CONFIG_DATA_DEV }}" | base64 -d > kubeconfig
|
||||
export KUBECONFIG=$PWD/kubeconfig
|
||||
kubectl set image deployment/${{ env.KUBE_DEPLOY_NAME }} \
|
||||
${{ env.KUBE_DEPLOY_NAME }}="${{ secrets.DEV_DEJO_AWS_ECR_REGISTRY }}/${{ env.AWS_ECR_REPOSITORY }}:${{ env.sha_short }}" \
|
||||
--record -n "${KUBE_NAMESPACE}"
|
||||
|
||||
- name: Verify Rollout
|
||||
run: |
|
||||
echo "${{ secrets.DEJO_NODE_KUBE_CONFIG_DATA_DEV }}" | base64 -d > kubeconfig
|
||||
export KUBECONFIG=$PWD/kubeconfig
|
||||
kubectl rollout status deployment/${{ env.KUBE_DEPLOY_NAME }} -n "${KUBE_NAMESPACE}"
|
||||
|
||||
- name: Discord | Notify Error
|
||||
if: ${{ failure() && env.DISABLE_DISCORD_NOTIFY != 'true' }}
|
||||
run: |
|
||||
curl -X POST -H "Content-Type: application/json" \
|
||||
-d '{"content": ":x: Erro durante o deploy! Veja logs."}' \
|
||||
"${{ env.DISCORD_WEBHOOK }}"
|
||||
exit 1
|
||||
|
||||
- name: Discord | Notify Success
|
||||
if: ${{ success() && env.DISABLE_DISCORD_NOTIFY != 'true' }}
|
||||
run: |
|
||||
curl -X POST -H "Content-Type: application/json" \
|
||||
-d '{"content": ":white_check_mark: Deploy concluído com sucesso! :rocket:"}' \
|
||||
"${{ env.DISCORD_WEBHOOK }}"
|
||||
|
||||
21
.gitignore
vendored
Normal file
21
.gitignore
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Local .terraform directories
|
||||
### Terraform ###
|
||||
**/.terraform/*
|
||||
*.tfstate
|
||||
*.tfstate.*
|
||||
crash.log
|
||||
*.tfvars
|
||||
override.tf
|
||||
override.tf.json
|
||||
*_override.tf
|
||||
*_override.tf.json
|
||||
.terraformrc
|
||||
terraform.rc
|
||||
*.lock
|
||||
*.lock.*
|
||||
*.DS_Store
|
||||
*.txt*
|
||||
*/**/builds
|
||||
*/**/sealedsecrets_result
|
||||
*.zip
|
||||
/node_modules/
|
||||
35
.releaserc
Normal file
35
.releaserc
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"branches": ["master"],
|
||||
"plugins": [
|
||||
[
|
||||
"@semantic-release/commit-analyzer",
|
||||
{
|
||||
"preset": "conventionalcommits",
|
||||
"releaseRules": [
|
||||
{ "type": "feat", "release": "minor" },
|
||||
{ "type": "fix", "release": "patch" },
|
||||
{ "type": "revert", "release": "major" }
|
||||
]
|
||||
}
|
||||
],
|
||||
"@semantic-release/release-notes-generator",
|
||||
[
|
||||
"@semantic-release/changelog",
|
||||
{ "changelogFile": "CHANGELOG.md" }
|
||||
],
|
||||
[
|
||||
"@semantic-release/git",
|
||||
{
|
||||
"assets": ["CHANGELOG.md"],
|
||||
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
||||
}
|
||||
],
|
||||
[
|
||||
"@saithodev/semantic-release-gitea",
|
||||
{
|
||||
"giteaUrl": "https://git.dejodigital.com.br",
|
||||
"assets": ["CHANGELOG.md"]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
22
Dockerfile
Normal file
22
Dockerfile
Normal file
@ -0,0 +1,22 @@
|
||||
# Dockerfile para o DEJO Node
|
||||
|
||||
FROM golang:1.23 as builder
|
||||
WORKDIR /app
|
||||
|
||||
# Copiar arquivos e instalar dependências
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
COPY . .
|
||||
RUN go build -o dejo-node ./cmd/main.go
|
||||
|
||||
# Criar imagem final
|
||||
FROM debian:bullseye-slim
|
||||
WORKDIR /root/
|
||||
|
||||
COPY --from=builder /app/dejo-node ./dejo-node
|
||||
|
||||
# Definir variáveis de ambiente padrão
|
||||
ENV CONFIG_PATH="/config/config.yaml"
|
||||
|
||||
CMD ["./dejo-node"]
|
||||
5
commitlint.config.js
Normal file
5
commitlint.config.js
Normal file
@ -0,0 +1,5 @@
|
||||
// commitlint.config.js
|
||||
module.exports = {
|
||||
extends: ['@commitlint/config-conventional']
|
||||
};
|
||||
|
||||
13
infrastructure/.env.example
Executable file
13
infrastructure/.env.example
Executable file
@ -0,0 +1,13 @@
|
||||
NODE_ENV=local
|
||||
|
||||
REDIS_HOST=localhost
|
||||
REDIS_PORT=6379
|
||||
REDIS_TTL=5
|
||||
REDIS_TLS=false
|
||||
REDIS_PASSWORD=redis
|
||||
|
||||
DATABASE_HOST=localhost
|
||||
DATABASE_PORT=5432
|
||||
DATABASE_USERNAME=postgres
|
||||
DATABASE_NAME=dejo
|
||||
DATABASE_SYNCHRONIZE=false
|
||||
14
infrastructure/docker/.env.dev
Executable file
14
infrastructure/docker/.env.dev
Executable file
@ -0,0 +1,14 @@
|
||||
NODE_ENV=development
|
||||
|
||||
REDIS_HOST=redis
|
||||
REDIS_PORT=6379
|
||||
REDIS_TTL=5
|
||||
REDIS_TLS=false
|
||||
REDIS_PASSWORD=redis
|
||||
|
||||
DATABASE_HOST=postgres
|
||||
DATABASE_PORT=5432
|
||||
DATABASE_USERNAME=postgres
|
||||
DATABASE_PASSWORD=postgres
|
||||
DATABASE_NAME=dejo-node
|
||||
DATABASE_SYNCHRONIZE=false
|
||||
40
infrastructure/hooks/commit-msg
Executable file
40
infrastructure/hooks/commit-msg
Executable file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Path to the commit message file (provided by Git).
|
||||
COMMIT_MSG_FILE=$1
|
||||
|
||||
# Read the commit message from the file.
|
||||
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")
|
||||
|
||||
CONVENTIONAL_COMMIT_REGEX='^(feat|fix|docs|style|refactor|test|chore|build|ci|perf|revert)(\([a-zA-Z0-9_.-]+\))?(!)?:\s.*$'
|
||||
|
||||
# Check if the commit message matches the regex
|
||||
if ! [[ $COMMIT_MSG =~ $CONVENTIONAL_COMMIT_REGEX ]]; then
|
||||
echo "ERRO: A mensagem de commit não segue o formato do Conventional Commits."
|
||||
echo
|
||||
echo "O formato correto da mensagem de commit é obrigatório:"
|
||||
echo " <tipo>(<escopo opcional>): <descrição>"
|
||||
echo
|
||||
echo "Os tipos válidos são:"
|
||||
echo " feat: Uma nova funcionalidade."
|
||||
echo " fix: Correção de um bug."
|
||||
echo " docs: Alterações na documentação."
|
||||
echo " style: Alterações de estilo de código (formatação, ponto-e-vírgula ausente, etc.)."
|
||||
echo " refactor: Refatoração de código (nem corrige bug nem adiciona funcionalidade)."
|
||||
echo " test: Adicionar ou atualizar testes."
|
||||
echo " chore: Tarefas rotineiras como atualização de dependências ou ferramentas de build."
|
||||
echo " build: Alterações que afetam o sistema de build ou dependências externas."
|
||||
echo " ci: Alterações nos arquivos de configuração de CI ou scripts."
|
||||
echo " perf: Melhorias de desempenho."
|
||||
echo " revert: Reverter um commit anterior."
|
||||
echo
|
||||
echo "Exemplos:"
|
||||
echo " feat(auth): adicionar funcionalidade de login"
|
||||
echo " fix(api)!: resolver problema de timeout"
|
||||
echo " docs(readme): atualizar instruções de instalação"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
28
infrastructure/kubernetes/dev/app/health-probes.yml
Normal file
28
infrastructure/kubernetes/dev/app/health-probes.yml
Normal file
@ -0,0 +1,28 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: dejo-node
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: deje-node
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health/liveness
|
||||
port: 8080
|
||||
initialDelaySeconds: 3
|
||||
periodSeconds: 5
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health/readiness
|
||||
port: 8080
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 10
|
||||
startupProbe:
|
||||
httpGet:
|
||||
path: /health/startup
|
||||
port: 8080
|
||||
failureThreshold: 30
|
||||
periodSeconds: 10
|
||||
|
||||
10
infrastructure/kubernetes/dev/app/image-tag.yml
Normal file
10
infrastructure/kubernetes/dev/app/image-tag.yml
Normal file
@ -0,0 +1,10 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: dejo-node
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: dejo-node
|
||||
image: 859024677525.dkr.ecr.us-east-1.amazonaws.com/dev-dejo/dejo-node:latest
|
||||
19
infrastructure/kubernetes/dev/app/ingress.yml
Normal file
19
infrastructure/kubernetes/dev/app/ingress.yml
Normal file
@ -0,0 +1,19 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: dejo-node-ingress
|
||||
annotations:
|
||||
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
|
||||
spec:
|
||||
rules:
|
||||
- host: dev-dejo-node.dejo.digital
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: dejo-node-svc
|
||||
port:
|
||||
number: 8545
|
||||
|
||||
8
infrastructure/kubernetes/dev/base/app/configmap.yml
Normal file
8
infrastructure/kubernetes/dev/base/app/configmap.yml
Normal file
@ -0,0 +1,8 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: dejo-node-config
|
||||
data:
|
||||
# ex.: configuração genérica, se precisar
|
||||
LOG_LEVEL: "info"
|
||||
|
||||
33
infrastructure/kubernetes/dev/base/app/deployment.yml
Normal file
33
infrastructure/kubernetes/dev/base/app/deployment.yml
Normal file
@ -0,0 +1,33 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: dejo-node
|
||||
labels:
|
||||
app: dejo-node
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: dejo-node
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: dejo-node
|
||||
spec:
|
||||
containers:
|
||||
- name: dejo-node
|
||||
image: dejo/node:latest
|
||||
ports:
|
||||
- containerPort: 8545
|
||||
- containerPort: 30303
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: dejo-node-config
|
||||
volumeMounts:
|
||||
- name: blockchain-storage
|
||||
mountPath: /data
|
||||
volumes:
|
||||
- name: blockchain-storage
|
||||
persistentVolumeClaim:
|
||||
claimName: dejo-node-pvc
|
||||
|
||||
19
infrastructure/kubernetes/dev/base/app/hpa.yml
Normal file
19
infrastructure/kubernetes/dev/base/app/hpa.yml
Normal file
@ -0,0 +1,19 @@
|
||||
apiVersion: autoscaling/v2beta2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: dejo-node-hpa
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: dejo-node
|
||||
minReplicas: 2
|
||||
maxReplicas: 10
|
||||
metrics:
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: 70
|
||||
|
||||
8
infrastructure/kubernetes/dev/base/app/ingress.yml
Normal file
8
infrastructure/kubernetes/dev/base/app/ingress.yml
Normal file
@ -0,0 +1,8 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: dejo-node-ingress
|
||||
labels:
|
||||
app: dejo-node
|
||||
spec: {}
|
||||
|
||||
13
infrastructure/kubernetes/dev/base/app/pvc.yml
Normal file
13
infrastructure/kubernetes/dev/base/app/pvc.yml
Normal file
@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: dejo-node-pvc
|
||||
labels:
|
||||
app: dejo-node
|
||||
spec:
|
||||
accessModes: ["ReadWriteOnce"]
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Gi
|
||||
storageClassName: gp3
|
||||
|
||||
18
infrastructure/kubernetes/dev/base/app/service.yml
Normal file
18
infrastructure/kubernetes/dev/base/app/service.yml
Normal file
@ -0,0 +1,18 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: dejo-node-svc
|
||||
labels:
|
||||
app: dejo-node
|
||||
spec:
|
||||
type: LoadBalancer
|
||||
selector:
|
||||
app: dejo-node
|
||||
ports:
|
||||
- name: rpc
|
||||
port: 8545
|
||||
targetPort: 8545
|
||||
- name: p2p
|
||||
port: 30303
|
||||
targetPort: 30303
|
||||
|
||||
13
infrastructure/kubernetes/dev/base/kustomization.yml
Normal file
13
infrastructure/kubernetes/dev/base/kustomization.yml
Normal file
@ -0,0 +1,13 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
resources:
|
||||
- ./app/deployment.yml
|
||||
- ./app/service.yml
|
||||
- ./app/pvc.yml
|
||||
- ./app/configmap.yml
|
||||
# - ./app/hpa.yml
|
||||
- ./app/ingress.yml
|
||||
|
||||
commonLabels:
|
||||
app: dejo-node
|
||||
15
infrastructure/kubernetes/dev/kustomization.yml
Normal file
15
infrastructure/kubernetes/dev/kustomization.yml
Normal file
@ -0,0 +1,15 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
namespace: dejo-node
|
||||
resources:
|
||||
- base
|
||||
|
||||
patchesStrategicMerge:
|
||||
# se você precisar alterar só a imagem, replicas, ingress, etc:
|
||||
- app/image-tag.yml
|
||||
- app/ingress.yml
|
||||
- app/health-probes.yml
|
||||
commonLabels:
|
||||
env: dev
|
||||
|
||||
25
infrastructure/terraform/dev/.terraform.lock.hcl
generated
Normal file
25
infrastructure/terraform/dev/.terraform.lock.hcl
generated
Normal file
@ -0,0 +1,25 @@
|
||||
# This file is maintained automatically by "terraform init".
|
||||
# Manual edits may be lost in future updates.
|
||||
|
||||
provider "registry.terraform.io/hashicorp/aws" {
|
||||
version = "5.99.1"
|
||||
constraints = ">= 5.43.0, >= 5.83.0"
|
||||
hashes = [
|
||||
"h1:967WCGUW/vgrjUMBvC+HCie1DVgOXHwUkhm2ng3twJw=",
|
||||
"zh:00b0a61c6d295300f0aa7a79a7d40e9f836164f1fff816d38324c148cd846887",
|
||||
"zh:1ee9d5ccb67378704642db62113ac6c0d56d69408a9c1afb9a8e14b095fc0733",
|
||||
"zh:2035977ed418dcb18290785c1eeb79b7133b39f718c470346e043ac48887ffc7",
|
||||
"zh:67e3ca1bf7061900f81cf958d5c771a2fd6048c2b185bec7b27978349b173a90",
|
||||
"zh:87fadbe5de7347ede72ad879ff8d8d9334103cd9aa4a321bb086bfac91654944",
|
||||
"zh:901d170c457c2bff244a2282d9de595bdb3ebecc33a2034c5ce8aafbcff66db9",
|
||||
"zh:92c07d6cf530679565b87934f9f98604652d787968cce6a3d24c148479b7e34b",
|
||||
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
|
||||
"zh:a7d4803b4c5ff17f029f8b270c91480442ece27cec7922c38548bcfea2ac2d26",
|
||||
"zh:afda848da7993a07d29018ec25ab6feda652e01d4b22721da570ce4fcc005292",
|
||||
"zh:baaf16c98b81bad070e0908f057a97108ecd6e8c9f754d7a79b18df4c8453279",
|
||||
"zh:c3dd496c5014427599d6b6b1c14c7ebb09a15df78918ae0be935e7bfa83b894c",
|
||||
"zh:e2b84c1d40b3f2c4b1d74bf170b9e932983b61bac0e6dab2e36f5057ddcc997f",
|
||||
"zh:e49c92cb29c53b4573ed4d9c946486e6bcfc1b63f1aee0c79cc7626f3d9add03",
|
||||
"zh:efae8e339c4b13f546e0f96c42eb95bf8347de22e941594849b12688574bf380",
|
||||
]
|
||||
}
|
||||
15
infrastructure/terraform/dev/dns.tf
Executable file
15
infrastructure/terraform/dev/dns.tf
Executable file
@ -0,0 +1,15 @@
|
||||
#data "aws_route53_zone" "dev-dejo" {
|
||||
# name = "dev.dejo.digital"
|
||||
# private_zone = false
|
||||
#}
|
||||
|
||||
#resource "aws_route53_record" "this" {
|
||||
# zone_id = data.aws_route53_zone.dev-dejo-be.zone_id
|
||||
# name = local.azion.domain.cname
|
||||
# type = "CNAME"
|
||||
# ttl = 60
|
||||
|
||||
# records = [
|
||||
# module.azion-backend.azion_domain.domain_name
|
||||
# ]
|
||||
#}
|
||||
3
infrastructure/terraform/dev/ecr.tf
Executable file
3
infrastructure/terraform/dev/ecr.tf
Executable file
@ -0,0 +1,3 @@
|
||||
resource "aws_ecr_repository" "this" {
|
||||
name = "dev-dejo/dejo-node"
|
||||
}
|
||||
48
infrastructure/terraform/dev/locals.tf
Executable file
48
infrastructure/terraform/dev/locals.tf
Executable file
@ -0,0 +1,48 @@
|
||||
locals {
|
||||
region = "us-east-1"
|
||||
|
||||
owner = "dejo"
|
||||
env = "dev"
|
||||
maintainer = "dejo"
|
||||
app = "dejo-node"
|
||||
tier = "backend"
|
||||
base_name = "${local.env}-${local.maintainer}-${local.app}"
|
||||
kms_key_name = "alias/${local.base_name}-terraform-bucket-key"
|
||||
|
||||
eks = {
|
||||
# After change cluster_name, change the the secret: DEV_DEJO_KUBE_CONFIG_DATA
|
||||
# The value is a base64 from kubeconfig, example: cat ~/.kubeconfig | base64 -w 0
|
||||
cluster_name = "dev-dejo"
|
||||
lb_name = "a7d3a64e7cd704e17a87740e579df9bc"
|
||||
|
||||
namespace = "dejo-node"
|
||||
service_account_name = "api-app-sa"
|
||||
}
|
||||
|
||||
s3 = {
|
||||
bucket = "${local.owner}-${local.env}-${local.app}-permanent-storage"
|
||||
acl = "private"
|
||||
|
||||
versioning = {
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
# event_bus = {
|
||||
# name = "dev-dejo-event-bus"
|
||||
# }
|
||||
|
||||
custom_tags = {
|
||||
App = upper(local.app)
|
||||
Tier = title(local.tier)
|
||||
}
|
||||
|
||||
default_tags = {
|
||||
Owner = title(local.owner)
|
||||
Env = title(local.env)
|
||||
Maintainer = title(local.maintainer)
|
||||
ManagedBy = "Terraform"
|
||||
BaseName = local.base_name
|
||||
App = "${local.maintainer}-${local.app}"
|
||||
}
|
||||
}
|
||||
4
infrastructure/terraform/dev/output.tf
Executable file
4
infrastructure/terraform/dev/output.tf
Executable file
@ -0,0 +1,4 @@
|
||||
#output "azion_domain_id" {
|
||||
# description = "Azion domain ID"
|
||||
# value = module.azion-backend.azion_domain.id
|
||||
#}
|
||||
25
infrastructure/terraform/dev/provider.tf
Executable file
25
infrastructure/terraform/dev/provider.tf
Executable file
@ -0,0 +1,25 @@
|
||||
provider "aws" {
|
||||
profile = "dejo-dev"
|
||||
region = "us-east-1"
|
||||
|
||||
default_tags {
|
||||
tags = local.default_tags
|
||||
}
|
||||
}
|
||||
|
||||
provider "aws" {
|
||||
alias = "virginia"
|
||||
profile = "dejo-dev"
|
||||
region = "us-east-1"
|
||||
|
||||
default_tags {
|
||||
tags = local.default_tags
|
||||
}
|
||||
}
|
||||
|
||||
#provider "aws" {
|
||||
# alias = "sao_paulo"
|
||||
# profile = "dejo-prd"
|
||||
# region = "sa-east-1"
|
||||
#}
|
||||
|
||||
15
infrastructure/terraform/dev/role.tf
Executable file
15
infrastructure/terraform/dev/role.tf
Executable file
@ -0,0 +1,15 @@
|
||||
module "kubernetes-backend-role" {
|
||||
source = "../../../../iac/aws/dejo-terraform/modules/kubernetes-backend-role/"
|
||||
|
||||
env = local.env
|
||||
app = local.app
|
||||
|
||||
eks_cluster_name = local.eks.cluster_name
|
||||
eks_namespace = local.eks.namespace
|
||||
eks_service_account_name = local.eks.service_account_name
|
||||
|
||||
allowed_event_names = [
|
||||
"ProductUserPublished"
|
||||
]
|
||||
}
|
||||
|
||||
41
infrastructure/terraform/dev/s3.tf
Executable file
41
infrastructure/terraform/dev/s3.tf
Executable file
@ -0,0 +1,41 @@
|
||||
# Criação da chave KMS para criptografia do bucket
|
||||
resource "aws_kms_key" "dev_dejo_node" {
|
||||
description = "KMS key to encrypt S3 bucket objects for ${local.base_name}"
|
||||
deletion_window_in_days = 7
|
||||
enable_key_rotation = true
|
||||
|
||||
tags = merge(
|
||||
local.default_tags,
|
||||
{
|
||||
Name = "${local.base_name}-bucket-key"
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
# Alias para facilitar referência à chave KMS
|
||||
resource "aws_kms_alias" "dev_dejo_node" {
|
||||
name = local.kms_key_name
|
||||
target_key_id = aws_kms_key.dev_dejo_node.key_id
|
||||
}
|
||||
|
||||
# Bucket S3 criptografado com KMS
|
||||
module "s3_bucket" {
|
||||
source = "terraform-aws-modules/s3-bucket/aws"
|
||||
version = "~> 4.0"
|
||||
|
||||
bucket = local.s3.bucket
|
||||
# acl = local.s3.acl
|
||||
versioning = local.s3.versioning
|
||||
|
||||
server_side_encryption_configuration = {
|
||||
rule = {
|
||||
apply_server_side_encryption_by_default = {
|
||||
kms_master_key_id = aws_kms_key.dev_dejo_node.arn
|
||||
sse_algorithm = "aws:kms"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tags = local.default_tags
|
||||
}
|
||||
|
||||
11
infrastructure/terraform/dev/state.tf
Executable file
11
infrastructure/terraform/dev/state.tf
Executable file
@ -0,0 +1,11 @@
|
||||
terraform {
|
||||
backend "s3" {
|
||||
profile = "dejo-dev"
|
||||
bucket = "dev-dejo-terraform"
|
||||
key = "state/dejo-node/infrastructure/dev.tfstate"
|
||||
region = "us-east-1"
|
||||
encrypt = true
|
||||
kms_key_id = "alias/dev-dejo-terraform-bucket-key"
|
||||
use_lockfile = true
|
||||
}
|
||||
}
|
||||
8919
package-lock.json
generated
Normal file
8919
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
16
package.json
Normal file
16
package.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"scripts": {
|
||||
"prepare": "git config core.hooksPath infrastructure/hooks"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@saithodev/semantic-release-gitea": "^1.0.0",
|
||||
"@semantic-release/changelog": "^6.0.0",
|
||||
"@semantic-release/commit-analyzer": "^9.0.0",
|
||||
"@semantic-release/git": "^10.0.0",
|
||||
"@semantic-release/release-notes-generator": "^10.0.0",
|
||||
"semantic-release": "^24.2.5",
|
||||
"@commitlint/cli": "^19.8.1",
|
||||
"@commitlint/config-conventional": "^19.8.1"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user