diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..9f5b3a195 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,60 @@ +# This is a basic workflow to help you get started with Actions + +name: CI-CD # Nome do workflow + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ meubranch ] +# pull_request: +# branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + CI: + # The type of runner that the job will run on + # Agente de execucao ... setup de maquina que eu preciso executar meu pipeline + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: # Execucoes que eu vou ter no job --- acoes + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 # Download do codigo no repositorio + - 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 + with: + context: ./src + file: ./src/Dockerfile + push: true + tags: | + jmscatena/rotten-potatoes:latest + jmscatena/rotten-potatoes:${{ github.run_number }} + CD: + needs: CI + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 # Download do codigo no repositorio + - name: Kubernetes set context + uses: Azure/k8s-set-context@v1.1 + with: + method: kubeconfig + kubeconfig: ${{ secrets.K8S_KUBCONFIG }} + + - name: Deploy to Kubernetes cluster + uses: Azure/k8s-deploy@v1.3 + with: + images: jmscatena/rotten-potatoes:${{ github.run_number }} + manifests: | + k8s/manifest.yaml + + diff --git a/cluster.yaml b/cluster.yaml new file mode 100644 index 000000000..245402b05 --- /dev/null +++ b/cluster.yaml @@ -0,0 +1,11 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/vlalpha4 +nodes: +- 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/k8s/cluster.yaml b/k8s/cluster.yaml new file mode 100644 index 000000000..a0db6518f --- /dev/null +++ b/k8s/cluster.yaml @@ -0,0 +1,12 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: +- role: control-plane +- role: control-plane +- role: worker +- role: worker +- role: worker +- role: worker + extraPortMappings: + - containerPort: 30000 + hostPort: 8080 diff --git a/k8s/manifest.yaml b/k8s/manifest.yaml new file mode 100644 index 000000000..7929d3684 --- /dev/null +++ b/k8s/manifest.yaml @@ -0,0 +1,78 @@ +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.9 + ports: + - containerPort: 27017 + env: + - name: MONGO_INITDB_ROOT_USERNAME + value: "mongouser" + - name: MONGO_INITDB_ROOT_PASSWORD + value: "mongopwd" +--- +apiVersion: v1 +kind: Service +metadata: + name: mongodb +spec: + selector: + app: mongodb + ports: + - port: 27017 + type: ClusterIP +--- +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: jmscatena/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" +--- +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..57207e8cb --- /dev/null +++ b/src/Dockerfile @@ -0,0 +1,7 @@ +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"] diff --git a/src/templates/base.html b/src/templates/base.html index d16e3ee70..c927f7329 100644 --- a/src/templates/base.html +++ b/src/templates/base.html @@ -6,7 +6,7 @@ - Rotten Potatoes + Rotten Potatoes Versao 2.0 @@ -28,7 +28,7 @@
-

Rotten Potatoes

+

Rotten Potatoes Versao 2.1

Review de VĂ­deos
@@ -70,4 +70,4 @@

Rotten Potatoes

- \ No newline at end of file +