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

estrutura de deploy local implementada #12

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

on:
push:
branches: [ main ]


workflow_dispatch:

jobs:
CI:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Docker Login
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PWD }}
- name: Docker Build And Push
uses: docker/[email protected]
with:
context: ./src
file: ./src/Dockerfile
push: true
tags: |
ramonmsj/rotten-potatoes:latest
ramonmsj/rotten-potatoes:v${{ github.run_number }}
CD:
needs: [CI]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Kubernetes Set Context
uses: Azure/k8s-set-context@v2
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_KUBECONFIG }}

- name: Deploy to Kubernetes cluster
uses: Azure/[email protected]
with:
images: ramonmsj/rotten-potatoes:v${{ github.run_number }}
manifests: |
k8s/deployment.yaml
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,5 @@ dmypy.json

# Pyre type checker
.pyre/

.history/
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 MongoDB
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb
spec:
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo:5.0.5
ports:
- containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: mongouser
- name: MONGO_INITDB_ROOT_PASSWORD
value: mongopwd

---
# service do mongoDB
apiVersion: v1
kind: Service
metadata:
name: mongodb
spec:
selector:
app: mongodb
ports:
- port: 27017
type: ClusterIP

---
#Deployment da aplicação web rotten-potatoes
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 6
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: ramonmsj/rotten-potatoes:v2
ports:
- containerPort: 5000
env:
# nome do banco
- name: MONGODB_DB
value: admin
# service
- name: MONGODB_HOST
value: mongodb
# porta em string
- name: MONGODB_PORT
value: "27017"
# user (mesmo do container mongo)
- name: MONGODB_USERNAME
value: mongouser
# password ( mesma do container mongo )
- name: MONGODB_PASSWORD
value: mongopwd

---
#Service
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 5000
nodePort: 30000
type: LoadBalancer
7 changes: 7 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.8-slim-buster
WORKDIR /app
COPY requirements.txt .
RUN python -m pip install -r requirements.txt
COPY . /app
EXPOSE 5000
CMD ["gunicorn", "--workers=3", "--bind", "0.0.0.0:5000", "-c", "config.py", "app:app"]
3 changes: 2 additions & 1 deletion src/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<![endif]-->

</head>

<body>
<div id="site-content">
<header class="site-header">
Expand Down Expand Up @@ -70,4 +71,4 @@ <h1 class="site-title">Rotten Potatoes</h1>

</body>

</html>
</html>