Skip to content

Commit df0d8a4

Browse files
committed
Update GitHub Actions
1 parent 1082c8f commit df0d8a4

File tree

4 files changed

+54
-74
lines changed

4 files changed

+54
-74
lines changed

.github/workflows/build-container.yml

Lines changed: 37 additions & 24 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:
@@ -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 }}"

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: Build
32

43
on:

.github/workflows/release.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515
env:
1616
DOCKER_BUILDKIT: 1
1717
SERVICESTACK_LICENSE: ${{ secrets.SERVICESTACK_LICENSE }}
18+
APPSETTINGS_JSON: ${{ secrets.APPSETTINGS_JSON }}
1819
KAMAL_DEPLOY_IP: ${{ secrets.KAMAL_DEPLOY_IP }}
1920
KAMAL_DEPLOY_HOST: ${{ secrets.KAMAL_DEPLOY_HOST }}
2021
KAMAL_REGISTRY_USERNAME: ${{ github.actor }}
@@ -28,12 +29,18 @@ jobs:
2829
- name: Checkout code
2930
uses: actions/checkout@v5
3031

32+
- name: Encode APPSETTINGS_JSON for runtime
33+
if: env.APPSETTINGS_JSON != null
34+
run: |
35+
# Base64 encode to avoid shell/YAML quoting issues; keep as a single env var.
36+
b64=$(printf '%s' "$APPSETTINGS_JSON" | base64 -w0)
37+
echo "APPSETTINGS_JSON_BASE64=$b64" >> $GITHUB_ENV
38+
3139
- name: Set up environment variables
3240
run: |
33-
echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
34-
echo "repository_name=$(echo ${{ github.repository }} | cut -d '/' -f 2)" >> $GITHUB_ENV
35-
echo "repository_name_lower=$(echo ${{ github.repository }} | cut -d '/' -f 2 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
36-
echo "org_name=$(echo ${{ github.repository }} | cut -d '/' -f 1)" >> $GITHUB_ENV
41+
echo "IMAGE=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
42+
repo_name="$(echo ${{ github.repository }} | cut -d '/' -f 2)"
43+
echo "SERVICE=$(echo $repo_name | tr '[:upper:]' '[:lower:]' | tr '.' '-')" >> $GITHUB_ENV
3744
if find . -maxdepth 2 -type f -name "Configure.Db.Migrations.cs" | grep -q .; then
3845
echo "HAS_MIGRATIONS=true" >> $GITHUB_ENV
3946
else
@@ -73,22 +80,22 @@ jobs:
7380
- name: Ensure directories exist with correct permissions
7481
run: |
7582
echo "Creating directories with correct permissions"
76-
kamal server exec "mkdir -p /opt/docker/${{ env.repository_name }}/App_Data /opt/docker/${{ env.repository_name }}/initdb.d"
83+
kamal server exec "mkdir -p /opt/docker/${{ env.SERVICE }}/App_Data /opt/docker/${{ env.SERVICE }}/initdb.d"
7784
7885
echo "Setting app file permissions"
79-
kamal server exec "chown -R 1654:1654 /opt/docker/${{ env.repository_name }}/App_Data /opt/docker/${{ env.repository_name }}/initdb.d"
86+
kamal server exec "chown -R 1654:1654 /opt/docker/${{ env.SERVICE }}/App_Data /opt/docker/${{ env.SERVICE }}/initdb.d"
8087
8188
- name: Check if first run and execute kamal app boot if necessary
8289
run: |
83-
FIRST_RUN_FILE="~/first-run/${{ env.repository_name }}"
90+
FIRST_RUN_FILE="~/first-run/${{ env.SERVICE }}"
8491
if ! kamal server exec -q "test -f $FIRST_RUN_FILE"; then
8592
kamal server exec -q "mkdir -p ~/first-run && touch $FIRST_RUN_FILE" || true
8693
8794
if [ -n "${{env.INIT_DB_SQL}}" ]; then
8895
echo "Initializing DB with INIT_DB_SQL secret..."
8996
# Save the SQL content to a temporary file
9097
echo "${{ env.INIT_DB_SQL }}" > init-db.sql
91-
cat init-db.sql | kamal server exec -i "cat > /opt/docker/${{ env.repository_name }}/initdb.d/${{ env.repository_name }}.sql" && rm init-db.sql || true
98+
cat init-db.sql | kamal server exec -i "cat > /opt/docker/${{ env.SERVICE }}/initdb.d/${{ env.SERVICE }}.sql" && rm init-db.sql || true
9299
fi
93100
# Start all kamal accessories
94101
kamal accessory boot all || true
@@ -101,13 +108,13 @@ jobs:
101108
102109
- name: Verify file permissions before deploy
103110
run: |
104-
kamal server exec --no-interactive "chown -R 1654:1654 /opt/docker/${{ env.repository_name }}/App_Data /opt/docker/${{ env.repository_name }}/initdb.d"
111+
kamal server exec --no-interactive "chown -R 1654:1654 /opt/docker/${{ env.SERVICE }}/App_Data /opt/docker/${{ env.SERVICE }}/initdb.d"
105112
106113
- name: Deploy with Kamal
107114
run: |
108115
kamal lock release -v
109116
kamal server exec --no-interactive 'echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin'
110-
kamal server exec --no-interactive 'docker pull ghcr.io/${{ env.image_repository_name }}:latest'
117+
kamal server exec --no-interactive 'docker pull ${{ env.IMAGE }}:latest'
111118
kamal deploy -P --version latest
112119
113120
- name: Migration

load-env.sh

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)