Skip to content

Docker & .NET App CI/CD #18

Docker & .NET App CI/CD

Docker & .NET App CI/CD #18

name: Docker App (good fefezfezf)
on:
workflow_dispatch:
env:
EXPECTED_RESPONSE: "Hello World!" # 🔹 Définition de la variable globale
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Publish app
run: dotnet publish -c Release -o publish
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: dotnet-publish
path: publish/
test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Run tests
run: dotnet test
docker-build:
runs-on: ubuntu-latest
needs: [build, test]
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to registry
uses: docker/login-action@v2
with:
registry: https://index.docker.io/v1/
username: ${{ secrets.AzureAppService_ContainerUsername_007dc16c00194a579ee0e182f3912414 }}
password: ${{ secrets.AzureAppService_ContainerPassword_03b591a7c15d426aa4439cb5a79e30b8 }}
- name: Build and push container image to registry
uses: docker/build-push-action@v3
with:
push: true
tags: forsanta/webapi-starter-dotnet8:${{ github.sha }}
file: ./Dockerfile
deploy:
runs-on: ubuntu-latest
needs: [docker-build, test] # 🔹 attend build & test avant de lancer
environment:
name: production
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
outputs:
webapp-url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: dotnet-publish
path: ./publish
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: fefezfezf
slot-name: production
publish-profile: ${{ secrets.AzureAppService_PublishProfile_9b585dbfa0374924ab161fec5b2dea00 }}
images: forsanta/webapi-starter-dotnet8:${{ github.sha }}
check-url:
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Vérifier que l’URL retourne la valeur attendue
run: |
url="${{ needs.deploy.outputs.webapp-url }}"
echo "Test de l'URL : $url"
response=$(curl -s "$url")
echo "Réponse : $response"
if [ "$response" != "$EXPECTED_RESPONSE" ]; then
echo "❌ L'URL ne retourne pas '$EXPECTED_RESPONSE'"
exit 1
fi
echo "✅ L'URL retourne bien '$EXPECTED_RESPONSE'"