Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/implementacao pipelines ci cd #5

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PWD }}
- name: Build and push Docker images
uses: docker/[email protected]
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/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG }}

- name: Deploy to Kubernetes cluster
uses: Azure/[email protected]
with:
images: ${{secrets.DOCKERHUB_USER}}/conversao-peso:${{github.run_number}}
manifests: |
kubernetes/deployment.yaml
15 changes: 15 additions & 0 deletions ConversaoPeso.Web/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# conversao-peso
# 🐳 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"
```
10 changes: 10 additions & 0 deletions cluster-config.yaml
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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