From 9520c1b92038affa0910b28d4440418e4a635fc2 Mon Sep 17 00:00:00 2001 From: Henrique Souza Date: Tue, 28 Sep 2021 12:27:54 -0300 Subject: [PATCH 1/5] feat: dockfile --- Dockerfile | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3d7247b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM mcr.microsoft.com/dotnet/sdk:5.0 AS base +ARG BUILD_CONFIGURATION=Debug +ENV ASPNETCORE_ENVIRONMENT=Development +ENV DOTNET_USE_POLLING_FILE_WATCHER=true +ENV ASPNETCORE_URLS=http://+:80 +EXPOSE 80 +WORKDIR /app + +FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build +WORKDIR /src +COPY ["ConversaoPeso.Web/ConversaoPeso.Web.csproj", "ConversaoPeso.Web/"] +RUN dotnet restore "ConversaoPeso.Web/ConversaoPeso.Web.csproj" +COPY . . +RUN dotnet build "ConversaoPeso.Web/ConversaoPeso.Web.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "ConversaoPeso.Web/ConversaoPeso.Web.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "ConversaoPeso.Web.dll"] + From 15cf1d4e71fc0795e792e0d42f52b4a351ab6cf5 Mon Sep 17 00:00:00 2001 From: Henrique Souza Date: Thu, 30 Sep 2021 17:58:07 -0300 Subject: [PATCH 2/5] feat; k8s --- k8s/deployment.yaml | 19 +++++++++++++++++++ k8s/service.yaml | 11 +++++++++++ 2 files changed, 30 insertions(+) create mode 100644 k8s/deployment.yaml create mode 100644 k8s/service.yaml diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 0000000..7049a2a --- /dev/null +++ b/k8s/deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: conversaopeso-deployment +spec: + replicas: 3 + selector: + matchLabels: + app: conversaopeso + template: + metadata: + labels: + app: conversaopeso + spec: + containers: + - name: conversaopeso + image: ohsouza/conversaopeso:v1 + ports: + - containerPort: 8080 \ No newline at end of file diff --git a/k8s/service.yaml b/k8s/service.yaml new file mode 100644 index 0000000..909d53d --- /dev/null +++ b/k8s/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: conversaopeso-service +spec: + selector: + app: conversaopeso + ports: + - port: 8081 + targetPort: 80 + type: ClusterIP From 2feb6cab81dc76e402441b768302d69d8af16053 Mon Sep 17 00:00:00 2001 From: Henrique Souza Date: Fri, 1 Oct 2021 12:15:18 -0300 Subject: [PATCH 3/5] loadbalancer --- k8s/service.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/service.yaml b/k8s/service.yaml index 909d53d..ffcb867 100644 --- a/k8s/service.yaml +++ b/k8s/service.yaml @@ -8,4 +8,4 @@ spec: ports: - port: 8081 targetPort: 80 - type: ClusterIP + type: LoadBalancer From 60161272bcfc31175d1e29477630aab0edea88ac Mon Sep 17 00:00:00 2001 From: Henrique Souza Date: Fri, 1 Oct 2021 12:17:40 -0300 Subject: [PATCH 4/5] Create main.yml --- .github/workflows/main.yml | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..14ed120 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,50 @@ +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: | + ohsouza/conversaopeso:latest + ohsouza/conversaopeso:v${{ 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: ohsouza/conversaopeso:v${{ github.run_number }} + manifests: | + k8s/deployment.yaml + k8s/service.yaml From 22e43bf04f5bf67f92c2a8c342f69d89b55a600c Mon Sep 17 00:00:00 2001 From: Henrique Souza Date: Fri, 1 Oct 2021 12:19:52 -0300 Subject: [PATCH 5/5] Update main.yml --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 14ed120..8d6c0f2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,8 +22,8 @@ jobs: - name: Docker Build and Push uses: docker/build-push-action@v2.7.0 with: - context: ./src - file: ./src/Dockerfile + context: . + file: ./Dockerfile push: true tags: | ohsouza/conversaopeso:latest