feat(dir): 🛠️ add CI/CD

This commit is contained in:
Collin Barrett 2024-06-07 10:18:28 -05:00
parent 0bf8e603ea
commit 21257bf8f6
2 changed files with 84 additions and 0 deletions

72
.github/workflows/directory.yml vendored Normal file
View file

@ -0,0 +1,72 @@
name: Directory API CI/CD
on:
push:
branches:
- main
- aspire # TODO: rm when merging aspire to main
paths:
- '.github/workflows/directory.yml'
- 'services/Directory/**'
- 'services/FilterLists.ServiceDefaults/**'
# TODO: uncomment when merging aspire to main
# pull_request:
# branches:
# - main
# paths:
# - '.github/workflows/directory.yml'
# - 'services/Directory/**'
# - 'services/FilterLists.ServiceDefaults/**'
env:
CONTAINER_REGISTRY: ghcr.io
CONTAINER_REPOSITORY: collinbarrett/filterlists-directory-api
CONTAINER_IMAGE_TAG_UNIQUE: ${{ github.run_id }}
CONTAINER_IMAGE_TAG_STABLE: latest-aspire # TODO: drop '-aspire' when merging aspire to main
AZURE_WEBAPP_NAME: app-filterlists-directory-prod
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.CONTAINER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build
run: dotnet build -c Release
working-directory: ./services/Directory/FilterLists.Directory.Api
- name: Publish & Push
if: github.event_name == 'push'
run: >
dotnet publish --sc \
-p:PublishProfile=DefaultContainer \
-p:ContainerRegistry=${{ env.CONTAINER_REGISTRY }} \
-p:ContainerRepository=${{ env.CONTAINER_REPOSITORY }} \
-p:ContainerImageTags='"${{ env.CONTAINER_IMAGE_TAG_UNIQUE }};${{ env.CONTAINER_IMAGE_TAG_STABLE }}"'
working-directory: ./services/Directory/FilterLists.Directory.Api
deploy:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push'
environment:
name: production
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}/swagger
steps:
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE_APP_FILTERLISTS_DIRECTORY_PROD }}
images: ${{ env.CONTAINER_REGISTRY }}/${{ env.CONTAINER_REPOSITORY }}:${{ env.CONTAINER_IMAGE_TAG_UNIQUE }}

View file

@ -7,6 +7,12 @@
<AnalysisMode>Recommended</AnalysisMode>
</PropertyGroup>
<PropertyGroup>
<PublishReadyToRunComposite>true</PublishReadyToRunComposite>
<ContainerBaseImage>mcr.microsoft.com/dotnet/runtime-deps:8.0-jammy-chiseled-extra</ContainerBaseImage>
<ContainerRuntimeIdentifier>linux-x64</ContainerRuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\FilterLists.ServiceDefaults\FilterLists.ServiceDefaults.csproj"/>
<ProjectReference Include="..\FilterLists.Directory.Application\FilterLists.Directory.Application.csproj"/>
@ -17,4 +23,10 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
</ItemGroup>
<ItemGroup>
<ContainerLabel Include="org.opencontainers.image.source" Value="https://github.com/collinbarrett/FilterLists"/>
<ContainerLabel Include="org.opencontainers.image.description" Value="filterlists.com | github.com/collinbarrett/filterlists | An ASP.NET Core API serving the core FilterList information."/>
<ContainerLabel Include="org.opencontainers.image.licenses" Value="MIT"/>
</ItemGroup>
</Project>