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 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..b145c49 100644 --- a/README.md +++ b/README.md @@ -1 +1,19 @@ -# conversao-peso \ No newline at end of file +# 🐳 Desafio 01 - Docker + +# ⚓ Desafio 02 - Kubernetes + +## 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 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