Skip to content

Commit d6c2be5

Browse files
committed
Update to latest Kamal Actions
1 parent bb8ce6a commit d6c2be5

File tree

3 files changed

+57
-20
lines changed

3 files changed

+57
-20
lines changed

.github/workflows/build-container.yml

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ on:
1515
# Only update envs here if you need to change them for this workflow
1616
env:
1717
DOCKER_BUILDKIT: 1
18-
KAMAL_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
19-
KAMAL_REGISTRY_USERNAME: ${{ github.actor }}
18+
KAMAL_DEPLOY_HOST: ${{ secrets.KAMAL_DEPLOY_HOST }}
2019

2120
jobs:
2221
build-container:
@@ -33,6 +32,24 @@ jobs:
3332
echo "repository_name_lower=$(echo ${{ github.repository }} | cut -d '/' -f 2 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
3433
echo "org_name=$(echo ${{ github.repository }} | cut -d '/' -f 1)" >> $GITHUB_ENV
3534
35+
# Set SERVICE_LABEL: derive from GITHUB_REPOSITORY (replace dots with dashes)
36+
echo "SERVICE_LABEL=$(echo ${{ github.repository }} | cut -d '/' -f 2 | tr '.' '-')" >> $GITHUB_ENV
37+
38+
# Set KAMAL_DEPLOY_HOST: use secret if available, otherwise use repository name
39+
if [ -n "${{ secrets.KAMAL_DEPLOY_HOST }}" ]; then
40+
DEPLOY_HOST="${{ secrets.KAMAL_DEPLOY_HOST }}"
41+
else
42+
DEPLOY_HOST="$(echo ${{ github.repository }} | cut -d '/' -f 2)"
43+
fi
44+
45+
# Validate KAMAL_DEPLOY_HOST contains at least one '.'
46+
if [[ ! "$DEPLOY_HOST" == *.* ]]; then
47+
echo "Error: KAMAL_DEPLOY_HOST must contain a hostname, e.g. example.com (got: $DEPLOY_HOST)"
48+
exit 1
49+
fi
50+
51+
echo "KAMAL_DEPLOY_HOST=$DEPLOY_HOST" >> $GITHUB_ENV
52+
3653
# This step is for the deployment of the templates only, safe to delete
3754
- name: Modify csproj for template deploy
3855
env:
@@ -45,25 +62,26 @@ jobs:
4562
id: check_client
4663
run: |
4764
if [ -d "MyApp.Client" ] && [ -f "MyApp.Client/package.json" ]; then
48-
echo "requires_npm=true" >> $GITHUB_OUTPUT
65+
echo "client_exists=true" >> $GITHUB_OUTPUT
66+
else
67+
echo "client_exists=false" >> $GITHUB_OUTPUT
4968
fi
5069
5170
- name: Setup Node.js
52-
if: steps.check_client.outputs.requires_npm == 'true'
53-
uses: actions/setup-node@v6
71+
if: steps.check_client.outputs.client_exists == 'true'
72+
uses: actions/setup-node@v3
5473
with:
5574
node-version: 24
5675

5776
- name: Install npm dependencies
58-
if: steps.check_client.outputs.requires_npm == 'true'
77+
if: steps.check_client.outputs.client_exists == 'true'
5978
working-directory: ./MyApp.Client
6079
run: npm install
6180

62-
- name: Install tailwindcss
63-
run: |
64-
mkdir -p /home/runner/.local/bin
65-
curl -o "/home/runner/.local/bin/tailwindcss" -L "https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64"
66-
chmod +x /home/runner/.local/bin/tailwindcss
81+
- name: Build client
82+
if: steps.check_client.outputs.client_exists == 'true'
83+
working-directory: ./MyApp.Client
84+
run: npm run build
6785

6886
- name: Install x tool
6987
run: dotnet tool install -g x
@@ -83,14 +101,21 @@ jobs:
83101
uses: docker/login-action@v3
84102
with:
85103
registry: ghcr.io
86-
username: ${{ env.KAMAL_REGISTRY_USERNAME }}
87-
password: ${{ env.KAMAL_REGISTRY_PASSWORD }}
104+
username: ${{ github.actor }}
105+
password: ${{ secrets.GITHUB_TOKEN }}
88106

89107
- name: Setup .NET
90108
uses: actions/setup-dotnet@v5
91109
with:
92-
dotnet-version: 8.0.x
110+
dotnet-version: 10.0.x
93111

94112
- name: Build and push Docker image
113+
env:
114+
SERVICESTACK_LICENSE: ${{ secrets.SERVICESTACK_LICENSE }}
115+
KAMAL_DEPLOY_HOST: ${{ secrets.KAMAL_DEPLOY_HOST }}
95116
run: |
96-
dotnet publish --os linux --arch x64 -c Release -p:ContainerRepository=${{ env.image_repository_name }} -p:ContainerRegistry=ghcr.io -p:ContainerImageTags=latest -p:ContainerPort=80
117+
dotnet publish --os linux --arch x64 -c Release \
118+
-p:ContainerRepository=${{ env.image_repository_name }} \
119+
-p:ContainerRegistry=ghcr.io -p:ContainerImageTags=latest \
120+
-p:ContainerPort=80 \
121+
-p:ContainerEnvironmentVariable="SERVICESTACK_LICENSE=${{ env.SERVICESTACK_LICENSE }}"

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
name: Build
23

34
on:

MyApp/MyApp.csproj

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,23 @@
4949
<Content Include="_videos\**" CopyToPublishDirectory="PreserveNewest" />
5050
</ItemGroup>
5151

52+
<PropertyGroup>
53+
<DefaultItemExcludes>$(DefaultItemExcludes);App_Data\**;node_modules\**</DefaultItemExcludes>
54+
</PropertyGroup>
55+
56+
<Target Name="CreateWwwrootFolderBuild" AfterTargets="AfterBuild">
57+
<MakeDir Directories="$(BuildDir)wwwroot" Condition="!Exists('$(BuildDir)wwwroot')" />
58+
</Target>
59+
60+
<Target Name="CreateAppDataFolder" BeforeTargets="Publish">
61+
<MakeDir Directories="$(PublishDir)App_Data" Condition="!Exists('$(PublishDir)App_Data')" />
62+
<Exec Command="npm install" />
63+
<Exec Command="npm run ui:build" />
64+
<RemoveDir Directories="$(PublishDir)wwwroot" />
5265
<ItemGroup>
53-
<Folder Include="App_Data\" />
66+
<CopyDist Include="./wwwroot/**/*.*" />
5467
</ItemGroup>
55-
56-
<Target Name="tailwind" BeforeTargets="Publish">
57-
<Exec Command="npm run ui:build" WorkingDirectory="./" />
58-
</Target>
68+
<Copy SourceFiles="@(CopyDist)" DestinationFiles="@(CopyDist->'$(PublishDir)wwwroot\%(RecursiveDir)%(Filename)%(Extension)')" />
69+
</Target>
5970

6071
</Project>

0 commit comments

Comments
 (0)