Skip to content

Commit

Permalink
Try to move the container label service to github actions rather than…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
Layoric committed Nov 8, 2024
1 parent 52d69b7 commit 94de38b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <<EOF >> appsettings.json.patch
Expand All @@ -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/[email protected]
Expand All @@ -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 }}"
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions MyApp/MyApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
<Using Include="ServiceStack" />
</ItemGroup>

<ItemGroup>
<ContainerLabel Include="service" Value="pvq-app" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.*" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.*" />
Expand Down

0 comments on commit 94de38b

Please sign in to comment.