diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 000000000..a20494b6e --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,49 @@ +name: CI-CD + +on: + push: + branches: [ main ] + + workflow_dispatch: + +jobs: + CI: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Docker Login + uses: docker/login-action@v1.10.0 + 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: | + ${{secrets.DOCKERHUB_USER}}/rotten-potatoes:latest + ${{secrets.DOCKERHUB_USER}}/rotten-potatoes:${{ github.run_number }} + 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: ${{secrets.DOCKERHUB_USER}}/rotten-potatoes:${{ github.run_number }} + manifests: | + kubernetes/deployment.yaml \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 000000000..0b51a6298 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Desafio 02 - šŸ³ Docker + āš“ Kubernetes + +## rotten-potatoes + +### Adiconado deploy completo da aplicaĆ§Ć£o com docker e kubernetes \ No newline at end of file diff --git a/cluster-config.yaml b/cluster-config.yaml new file mode 100644 index 000000000..56b6e3e18 --- /dev/null +++ b/cluster-config.yaml @@ -0,0 +1,14 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 + +nodes: +- role: control-plane +- role: control-plane +- role: control-plane +- role: worker +- role: worker +- role: worker + + extraPortMappings: + - containerPort: 30000 + hostPort: 8080 \ No newline at end of file diff --git a/kubernetes/deployment.yaml b/kubernetes/deployment.yaml new file mode 100644 index 000000000..65a61dd80 --- /dev/null +++ b/kubernetes/deployment.yaml @@ -0,0 +1,103 @@ +# 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:4.4.6 + 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 +apiVersion: apps/v1 +kind: Deployment + +metadata: + name: web + +spec: + replicas: 1 + + selector: + matchLabels: + app: web + + template: + metadata: + labels: + app: web + + spec: + containers: + - name: web + image: diogoferreira/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 +apiVersion: v1 +kind: Service + +metadata: + name: web + +spec: + selector: + app: web + + ports: + - port: 80 + targetPort: 5000 + nodePort: 30000 + + type: LoadBalancer \ No newline at end of file diff --git a/src/Dockerfile b/src/Dockerfile new file mode 100644 index 000000000..51edaeb48 --- /dev/null +++ b/src/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.8 +WORKDIR /app + +COPY requirements.txt . +RUN python -m pip install -r requirements.txt + +COPY . . +EXPOSE 5000 + +CMD [ "gunicorn", "--workers=3", "--bind", "0.0.0.0:5000", "app:app" ] \ No newline at end of file