From 03cbebddd20a1122a07a92cc16bce84ab44b2692 Mon Sep 17 00:00:00 2001 From: Raghav Rastogi <51928619+raghav2404@users.noreply.github.com> Date: Sun, 15 Dec 2024 02:08:24 +0530 Subject: [PATCH] Create dotnet.yml --- .github/workflows/dotnet.yml | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/dotnet.yml diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 0000000..7de4276 --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,53 @@ +name: .NET MVC CI/CD Pipeline + +on: + push: + branches: + - main # Trigger on push to 'main' branch + pull_request: + branches: + - main # Trigger on pull request to 'main' branch + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + env: + DOTNET_VERSION: 8.0 + PUBLISH_DIR: ./publish + IMAGE_NAME: ragh2404/demoMvcCore # Docker image name + + steps: + # Step 1: Check out code + - name: Checkout code + uses: actions/checkout@v3 + + # Step 2: Set up .NET + - name: Setup .NET SDK + uses: actions/setup-dotnet@v3 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + # Step 3: Restore dependencies + - name: Restore dependencies + run: dotnet restore + + # Step 4: Build the solution + - name: Build the solution + run: dotnet build --configuration Release + + # Step 6: Build Docker Image + - name: Build Docker Image + run: | + docker build -t ${{ env.IMAGE_NAME }}:latest . + # Step 7: Log in to DockerHub (or your preferred registry) + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: raghav2404l + password: Rr24042000#Rr + + # Step 8: Push Docker image to DockerHub + - name: Push Docker Image to Docker Hub + run: | + docker push ${{ env.IMAGE_NAME }}:latest