Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include prometheus #7

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
57 changes: 57 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CI-CD

on:
push:
branches: ["main"]
workflow_dispatch:
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Obter o codigo da aplicacao
uses: actions/checkout@v4

- name: Autenticar no Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Construcao e Envio da Imagem Docker
uses: docker/build-push-action@v6
with:
context: ./src
push: true
file: ./src/Dockerfile
tags: |
jcdcjr/fake-shop:latest
jcdcjr/fake-shop:v${{ github.run_number }}

cd:
runs-on: ubuntu-latest
needs: [ci]
permissions:
id-token: write
contents: read
actions: read
steps:
- name: Obter o codigo da aplicacao
uses: actions/checkout@v4

- name: Autenticar na AWS
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Configurar o kubectl
run: aws eks update-kubeconfig --name aula-k8s

- name: Deploy dos manifestos no Kubernetes
uses: Azure/k8s-deploy@v5
with:
manifests: |
./k8s/deployment.yaml
images: |
jcdcjr/fake-shop:v${{ github.run_number }}
Binary file added grafana/dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 90 additions & 0 deletions k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#deployment do banco de dados
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgre
spec:
selector:
matchLabels:
app: postgre
template:
metadata:
labels:
app: postgre
spec:
containers:
- name: postgre
image: postgres:13.16
ports:
- containerPort: 5432
env:
- name: POSTGRES_DB
value: fakeshop
- name: POSTGRES_USER
value: fakeshop
- name: POSTGRES_PASSWORD
value: Pg1234

---

apiVersion: v1
kind: Service
metadata:
name: postgre
spec:
selector:
app: postgre
ports:
- port: 5432
targetPort: 5432

---
#deployment da aplicacao web
apiVersion: apps/v1
kind: Deployment
metadata:
name: fakeshop
spec:
replicas: 10
selector:
matchLabels:
app: fakeshop
template:
metadata:
annotations:
prometheus.io/scrape: 'true'
prometheus.io/port: '5000'
prometheus.io/path: '/metrics'
labels:
app: fakeshop
spec:
containers:
- name: fakeshop
image: jcdcjr/fake-shop:v2
ports:
- containerPort: 5000
env:
- name: DB_HOST
value: postgre
- name: DB_USER
value: fakeshop
- name: DB_PASSWORD
value: Pg1234
- name: DB_NAME
value: fakeshop
- name: FLASK_APP
value: index.py

---

apiVersion: v1
kind: Service
metadata:
name: fakeshop
spec:
selector:
app: fakeshop
ports:
- port: 80
targetPort: 5000
type: LoadBalancer
Loading