diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..8d6c0f2 --- /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: . + file: ./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 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"] + 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..ffcb867 --- /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: LoadBalancer