|
| 1 | +name: API Deployment |
| 2 | + |
| 3 | +env: |
| 4 | + registryName: {your_registry_name}.azurecr.io |
| 5 | + repositoryName: techexcel/csapi |
| 6 | + dockerFolderPath: ./src/ContosoSuitesWebAPI |
| 7 | + tag: ${{github.run_number}} |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + branches: [ main ] |
| 12 | + paths: src/ContosoSuitesWebAPI/** |
| 13 | + pull_request: |
| 14 | + branches: [ main ] |
| 15 | + paths: src/ContosoSuitesWebAPI/** |
| 16 | + # Allows you to run this workflow manually from the Actions tab |
| 17 | + workflow_dispatch: |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + - name: Setup .NET |
| 26 | + uses: actions/setup-dotnet@v4 |
| 27 | + with: |
| 28 | + dotnet-version: 8.0 |
| 29 | + |
| 30 | + - name: Restore dependencies |
| 31 | + run: dotnet restore ./src/ContosoSuitesWebAPI/ContosoSuitesWebAPI.csproj |
| 32 | + - name: Build |
| 33 | + run: dotnet build --no-restore ./src/ContosoSuitesWebAPI/ContosoSuitesWebAPI.csproj |
| 34 | + |
| 35 | + dockerBuildPush: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + needs: build |
| 38 | + |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - name: Docker Login |
| 43 | + # You may pin to the exact commit or the version. |
| 44 | + # uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c |
| 45 | + uses: docker/login-action@v3 |
| 46 | + with: |
| 47 | + # Server address of Docker registry. If not set then will default to Docker Hub |
| 48 | + registry: ${{ secrets.ACR_LOGIN_SERVER }} |
| 49 | + # Username used to log against the Docker registry |
| 50 | + username: ${{ secrets.ACR_USERNAME }} |
| 51 | + # Password or personal access token used to log against the Docker registry |
| 52 | + password: ${{ secrets.ACR_PASSWORD }} |
| 53 | + # Log out from the Docker registry at the end of a job |
| 54 | + logout: true |
| 55 | + |
| 56 | + - name: Docker Build |
| 57 | + run: docker build -t $registryName/$repositoryName:$tag --build-arg build_version=$tag $dockerFolderPath |
| 58 | + |
| 59 | + - name: Docker Push |
| 60 | + run: docker push $registryName/$repositoryName:$tag |
| 61 | + |
| 62 | + deploy-to-prod: |
| 63 | + |
| 64 | + runs-on: ubuntu-latest |
| 65 | + needs: dockerBuildPush |
| 66 | + environment: |
| 67 | + name: prod |
| 68 | + url: https://{your_prefix}-api.azurewebsites.net/ |
| 69 | + |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - name: 'Login via Azure CLI' |
| 74 | + |
| 75 | + with: |
| 76 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 77 | + |
| 78 | + - uses: azure/webapps-deploy@v2 |
| 79 | + with: |
| 80 | + app-name: '{your_prefix}-api' |
| 81 | + images: {your_registry_name}.azurecr.io/techexcel/csapi:${{github.run_number}} |
0 commit comments