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

feat: dockfile #1

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
50 changes: 50 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PWD }}

- name: Docker Build and Push
uses: docker/[email protected]
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/[email protected]
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_CONFIG }}

- name: Deploy to Kubernetes cluster
uses: Azure/[email protected]
with:
images: ohsouza/conversaopeso:v${{ github.run_number }}
manifests: |
k8s/deployment.yaml
k8s/service.yaml
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

19 changes: 19 additions & 0 deletions k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions k8s/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: conversaopeso-service
spec:
selector:
app: conversaopeso
ports:
- port: 8081
targetPort: 80
type: LoadBalancer