From 94de38bf71de4c3b1b0b3c0d2810fb5f3e78310c Mon Sep 17 00:00:00 2001 From: Darren Reid Date: Fri, 8 Nov 2024 11:51:55 +1100 Subject: [PATCH] Try to move the container label service to github actions rather than csproj since we don't want to deploy from locally. This will still support commands locally to monitor/review since container label is in deploy.yml. --- .github/workflows/release.yml | 20 +++++++++++++++----- MyApp/MyApp.csproj | 4 ---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bee6fda..50bb44a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,6 +33,16 @@ jobs: run: | echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV echo "repository_name=$(echo ${{ github.repository }} | cut -d '/' -f 2)" >> $GITHUB_ENV + if find . -maxdepth 2 -type f -name "Configure.Db.Migrations.cs" | grep -q .; then + echo "HAS_MIGRATIONS=true" >> $GITHUB_ENV + else + echo "HAS_MIGRATIONS=false" >> $GITHUB_ENV + fi + if [ -n "${{ secrets.APPSETTINGS_PATCH }}" ]; then + echo "HAS_APPSETTINGS_PATCH=true" >> $GITHUB_ENV + else + echo "HAS_APPSETTINGS_PATCH=false" >> $GITHUB_ENV + fi - name: Login to GitHub Container Registry uses: docker/login-action@v3 @@ -48,9 +58,9 @@ jobs: - name: Install x tool run: dotnet tool install -g x - - # Temp test + - name: Apply Production AppSettings + if: env.HAS_APPSETTINGS_PATCH == 'true' working-directory: ./MyApp run: | cat <> appsettings.json.patch @@ -60,7 +70,7 @@ jobs: - name: Build and push Docker image run: | - dotnet publish --os linux --arch x64 -c Release -p:ContainerRepository=${{ env.image_repository_name }} -p:ContainerRegistry=ghcr.io -p:ContainerImageTags=latest -p:ContainerPort=80 + dotnet publish --os linux --arch x64 -c Release -p:ContainerRepository=${{ env.image_repository_name }} -p:ContainerRegistry=ghcr.io -p:ContainerImageTags=latest -p:ContainerPort=80 -p:ContainerLabel_service=${{ env.repository_name }} - name: Set up SSH key uses: webfactory/ssh-agent@v0.9.0 @@ -84,7 +94,6 @@ jobs: - name: Kamal bootstrap run: kamal server bootstrap - # This ensures the web.env has been setup ready for deployments - name: Check if first run and execute kamal app boot if necessary run: | FIRST_RUN_FILE=".${{ env.repository_name }}" @@ -96,9 +105,10 @@ jobs: fi - name: Ensure file permissions - run: kamal server exec --no-interactive "mkdir -p /opt/docker/${{ env.repository_name }}/App_Data && chown -R 1654:1654 /opt/docker/${{ env.repository_name }}/App_Data" + run: kamal server exec --no-interactive "mkdir -p /opt/docker/${{ env.repository_name }}/App_Data && chown -R 1654:1654 /opt/docker/${{ env.repository_name }}" - name: Migration + if: env.HAS_MIGRATIONS == 'true' run: kamal app exec --no-reuse --no-interactive --version=latest "--AppTasks=migrate" - name: Deploy with Kamal diff --git a/MyApp/MyApp.csproj b/MyApp/MyApp.csproj index 15ba943..aa2a699 100644 --- a/MyApp/MyApp.csproj +++ b/MyApp/MyApp.csproj @@ -13,10 +13,6 @@ - - - -