From 23d5c91f28fb6c6831cf7a531a05e5db6bdf534e Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Tue, 28 Sep 2021 14:18:58 -0300 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=B3=20Adiconado=20multistage=20bui?= =?UTF-8?q?ld=20com=20docker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConversaoPeso.Web/Dockerfile | 15 +++++++++++++++ README.md | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 ConversaoPeso.Web/Dockerfile diff --git a/ConversaoPeso.Web/Dockerfile b/ConversaoPeso.Web/Dockerfile new file mode 100644 index 0000000..87d80a4 --- /dev/null +++ b/ConversaoPeso.Web/Dockerfile @@ -0,0 +1,15 @@ +FROM mcr.microsoft.com/dotnet/sdk:5.0 as build-app +WORKDIR /app +EXPOSE 80 + +COPY *.csproj ./ +RUN dotnet restore + +COPY . . +RUN dotnet publish -c Release -o out + +FROM mcr.microsoft.com/dotnet/aspnet:5.0 as publish +WORKDIR /app + +COPY --from=build-app /app/out . +ENTRYPOINT ["dotnet", "ConversaoPeso.Web.dll"] \ No newline at end of file diff --git a/README.md b/README.md index 9cdeec2..4df440d 100644 --- a/README.md +++ b/README.md @@ -1 +1,17 @@ -# conversao-peso \ No newline at end of file +# 🐳 Desafio 01 - Docker + +## conversao-peso + +## Adiconado multistage build com docker + +``` sh +docker image build -t diogoferreira/app-conversao-peso:v1 . +``` + +``` sh +docker container run -d -p 8080:8080 --name app-conversao-peso diogoferreira/app-conversao-peso:v1 +``` + +``` sh +docker container rm -f "CONTAINER ID" +``` \ No newline at end of file From 731c75ccfacbd8f95ef48b06a5e1e6161d83b5ec Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Sat, 2 Oct 2021 20:41:08 -0300 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9A=93=20Adiconado=20deploy=20com=20kube?= =?UTF-8?q?rnetes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ cluster-config.yaml | 10 +++++++++ kubernetes/deployment.yaml | 42 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 cluster-config.yaml create mode 100644 kubernetes/deployment.yaml diff --git a/README.md b/README.md index 4df440d..b145c49 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # 🐳 Desafio 01 - Docker +# ⚓ Desafio 02 - Kubernetes + ## conversao-peso ## Adiconado multistage build com docker diff --git a/cluster-config.yaml b/cluster-config.yaml new file mode 100644 index 0000000..5595eba --- /dev/null +++ b/cluster-config.yaml @@ -0,0 +1,10 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 + +nodes: +- role: control-plane +- role: control-plane +- role: control-plane +- role: worker +- role: worker +- role: worker \ No newline at end of file diff --git a/kubernetes/deployment.yaml b/kubernetes/deployment.yaml new file mode 100644 index 0000000..af0f893 --- /dev/null +++ b/kubernetes/deployment.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment + +metadata: + name: kubernetes-deployment + +spec: + replicas: 1 + + selector: + matchLabels: + app: web + + template: + metadata: + labels: + app: web + + spec: + containers: + - name: web + image: diogoferreira/app-conversao-peso:v1 + ports: + - containerPort: 80 + +--- + +apiVersion: v1 +kind: Service + +metadata: + name: web + +spec: + selector: + app: web + + ports: + - port: 80 + targetPort: 8080 + + type: LoadBalancer \ No newline at end of file From 3551edcf5a1072b65462854851191db863cdbe60 Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Sun, 3 Oct 2021 00:32:38 -0300 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8F=97=20Adiconada=20implementa=C3=A7?= =?UTF-8?q?=C3=A3o=20de=20pipelines=20CI/CD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yaml | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/main.yaml diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..e67d863 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,46 @@ +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: Build and push Docker images + uses: docker/build-push-action@v2.7.0 + with: + context: ./ConversaoPeso.Web + file: ./ConversaoPeso.Web/Dockerfile + push: true + tags: | + ${{secrets.DOCKERHUB_USER}}/conversao-peso:latest + ${{secrets.DOCKERHUB_USER}}/conversao-peso:${{ github.run_number }} + + CD: + runs-on: ubuntu-latest + needs: [CI] + 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}}/conversao-peso:${{github.run_number}} + manifests: | + kubernetes/deployment.yaml \ No newline at end of file