diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..b9846cfee --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,48 @@ + +name: CI+CD + +on: + push: + branches: [ conf-kubernetes ] + + workflow_dispatch: + +jobs: + CI: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Docker Login + uses: docker/login-action@v1.14.1 + with: + username: ${{ secrets.DOCKERHUB_USER }} + password: ${{ secrets.DOCKERHUB_PWD }} + + - name: Docker build and Push + uses: docker/build-push-action@v2.7.0 + with: + context: ./src + file: ./src/Dockerfile + push: true + tags: + 763ed2a0a734/rotten-potatoes:latest + CD: + needs: [CI] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Kubernetes Set Context + uses: Azure/k8s-set-context@v1.1 + with: + method: kubeconfig + kubeconfig: ${{ secrets.K8S_CONFIG }} + + - name: Deploy to Kubernetes cluster + uses: Azure/k8s-deploy@v1.3 + with: + images: 763ed2a0a734/rotten-potatoes:latest + manifests: | + k8s/deployment.yaml diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 000000000..00f859159 --- /dev/null +++ b/k8s/deployment.yaml @@ -0,0 +1,92 @@ +# Deployment do MonDB +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 MongDB +apiVersion: v1 +kind: Service +metadata: + name: mongodb +spec: + selector: + app: mongodb + ports: + - port: 27017 + type: ClusterIP +--- + # Deployment da Aplicação WEb Pagina + apiVersion: apps/v1 + kind: Deployment + metadata: + name: web + spec: + selector: + matchLabels: + app: web + template: + metadata: + labels: + app: web + spec : + containers: + - name : web + image: 763ed2a0a734/rotten-potatoes:v1 + ports: + - containerPort: 5000 + env: + - name: MONGODB_DB + value: admin + - name : MONGODB_HOST + value: mongodb + - name: MONGODB_PORT + value: "27017" + - name : MONGODB_USERNAME + value: mongouser + - name: MONGODB_PASSWORD + value: mongopwd +--- +# Service da Aplicação WEb Pagina +apiVersion: v1 +kind: Service +metadata: + name : web +spec: + selector: + app: web + ports: + - port: 80 + targetPort: 5000 + nodePort: 30000 + type: LoadBalancer + + + + + + + + + + + diff --git a/src/Dockerfile b/src/Dockerfile new file mode 100644 index 000000000..b4ea8df55 --- /dev/null +++ b/src/Dockerfile @@ -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"]