1515# Only update envs here if you need to change them for this workflow
1616env :
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
2120jobs :
2221 build-container :
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 }}"
0 commit comments