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 :
@@ -28,18 +27,34 @@ jobs:
2827
2928 - name : Set up environment variables
3029 run : |
31- echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
32- echo "repository_name=$(echo ${{ github.repository }} | cut -d '/' -f 2)" >> $GITHUB_ENV
33- echo "repository_name_lower=$(echo ${{ github.repository }} | cut -d '/' -f 2 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
34- echo "org_name=$(echo ${{ github.repository }} | cut -d '/' -f 1)" >> $GITHUB_ENV
30+ echo "IMAGE=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
31+ repo_name="$(echo ${{ github.repository }} | cut -d '/' -f 2)"
32+
33+ # Set SERVICE: derive from repo name (replace dots with dashes)
34+ echo "SERVICE=$(echo $repo_name | tr '[:upper:]' '[:lower:]' | tr '.' '-')" >> $GITHUB_ENV
35+
36+ # Set KAMAL_DEPLOY_HOST: use secret if available, otherwise use repository name
37+ if [ -n "${{ secrets.KAMAL_DEPLOY_HOST }}" ]; then
38+ DEPLOY_HOST="${{ secrets.KAMAL_DEPLOY_HOST }}"
39+ else
40+ DEPLOY_HOST="$repo_name"
41+ fi
42+
43+ # Validate KAMAL_DEPLOY_HOST contains at least one '.'
44+ if [[ ! "$DEPLOY_HOST" == *.* ]]; then
45+ echo "Error: KAMAL_DEPLOY_HOST must contain a hostname, e.g. example.com (got: $DEPLOY_HOST)"
46+ exit 1
47+ fi
48+
49+ echo "KAMAL_DEPLOY_HOST=$DEPLOY_HOST" >> $GITHUB_ENV
3550
3651 # This step is for the deployment of the templates only, safe to delete
3752 - name : Modify csproj for template deploy
3853 env :
3954 KAMAL_DEPLOY_IP : ${{ secrets.KAMAL_DEPLOY_IP }}
4055 if : env.KAMAL_DEPLOY_IP != null
4156 run : |
42- sed -i 's#<ContainerLabel Include="service" Value="my-app" />#<ContainerLabel Include="service" Value="${{ env.repository_name_lower }}" />#g' MyApp/MyApp.csproj
57+ sed -i 's#<ContainerLabel Include="service" Value="my-app" />#<ContainerLabel Include="service" Value="${{ env.SERVICE }}" />#g' MyApp/MyApp.csproj
4358
4459 - name : Check for Client directory and package.json
4560 id : check_client
@@ -54,39 +69,37 @@ jobs:
5469 if : steps.check_client.outputs.client_exists == 'true'
5570 uses : actions/setup-node@v3
5671 with :
57- node-version : 22
72+ node-version : 24
5873
5974 - name : Install npm dependencies
6075 if : steps.check_client.outputs.client_exists == 'true'
6176 working-directory : ./MyApp.Client
6277 run : npm install
6378
64- - name : Install x tool
65- run : dotnet tool install -g x
66-
67- - name : Apply Production AppSettings
68- env :
69- APPSETTINGS_PATCH : ${{ secrets.APPSETTINGS_PATCH }}
70- if : env.APPSETTINGS_PATCH != null
71- working-directory : ./MyApp
72- run : |
73- cat <<EOF >> appsettings.json.patch
74- ${{ secrets.APPSETTINGS_PATCH }}
75- EOF
76- x patch appsettings.json.patch
79+ - name : Build client
80+ if : steps.check_client.outputs.client_exists == 'true'
81+ working-directory : ./MyApp.Client
82+ run : npm run build
7783
7884 - name : Login to GitHub Container Registry
7985 uses : docker/login-action@v3
8086 with :
8187 registry : ghcr.io
82- username : ${{ env.KAMAL_REGISTRY_USERNAME }}
83- password : ${{ env.KAMAL_REGISTRY_PASSWORD }}
88+ username : ${{ github.actor }}
89+ password : ${{ secrets.GITHUB_TOKEN }}
8490
8591 - name : Setup .NET
8692 uses : actions/setup-dotnet@v5
8793 with :
8894 dotnet-version : 10.0.x
8995
9096 - name : Build and push Docker image
97+ env :
98+ SERVICESTACK_LICENSE : ${{ secrets.SERVICESTACK_LICENSE }}
99+ KAMAL_DEPLOY_HOST : ${{ secrets.KAMAL_DEPLOY_HOST }}
91100 run : |
92- dotnet publish --os linux --arch x64 -c Release -p:ContainerRepository=${{ env.image_repository_name }} -p:ContainerRegistry=ghcr.io -p:ContainerImageTags=latest -p:ContainerPort=80
101+ dotnet publish --os linux --arch x64 -c Release \
102+ -p:ContainerRepository=${{ env.IMAGE }} \
103+ -p:ContainerRegistry=ghcr.io -p:ContainerImageTags=latest \
104+ -p:ContainerPort=80 \
105+ -p:ContainerEnvironmentVariable="SERVICESTACK_LICENSE=${{ env.SERVICESTACK_LICENSE }}"
0 commit comments