Skip to content

Commit 13acaf2

Browse files
committed
Upgrade to .NET 10
1 parent 5152e02 commit 13acaf2

File tree

16 files changed

+248
-161
lines changed

16 files changed

+248
-161
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'
71+
if: steps.check_client.outputs.client_exists == 'true'
5372
uses: actions/setup-node@v3
5473
with:
55-
node-version: 22
74+
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: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
name: Build
23

34
on:
@@ -16,10 +17,26 @@ jobs:
1617
- name: Setup dotnet
1718
uses: actions/setup-dotnet@v5
1819
with:
19-
dotnet-version: 8.0.x
20+
dotnet-version: 10.0.x
21+
22+
- name: Restore NuGet packages (use repo NuGet.config)
23+
run: dotnet restore MyApp.slnx --configfile ./NuGet.Config
24+
25+
# If your feed requires authentication, enable and configure the step below.
26+
# This example uses a Personal Access Token stored in secrets.NUGET_API_KEY.
27+
# Alternatively, you can use the NuGet Authenticate action from Azure Pipelines.
28+
# - name: Authenticate private NuGet feed
29+
# env:
30+
# NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
31+
# run: |
32+
# dotnet nuget add source "https://YOUR_FEED_URL/index.json" \
33+
# --name "PrivateFeed" \
34+
# --username "YOUR_USERNAME" \
35+
# --password "$NUGET_API_KEY" \
36+
# --store-password-in-clear-text
2037

2138
- name: build
22-
run: dotnet build
39+
run: dotnet build --no-restore
2340
working-directory: .
2441

2542
- name: test

.github/workflows/release.yml

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ on:
1414

1515
env:
1616
DOCKER_BUILDKIT: 1
17-
KAMAL_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
18-
KAMAL_REGISTRY_USERNAME: ${{ github.actor }}
1917
SERVICESTACK_LICENSE: ${{ secrets.SERVICESTACK_LICENSE }}
18+
KAMAL_DEPLOY_IP: ${{ secrets.KAMAL_DEPLOY_IP }}
19+
KAMAL_DEPLOY_HOST: ${{ secrets.KAMAL_DEPLOY_HOST }}
20+
KAMAL_REGISTRY_USERNAME: ${{ github.actor }}
21+
KAMAL_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
2022

2123
jobs:
2224
release:
@@ -38,24 +40,12 @@ jobs:
3840
echo "HAS_MIGRATIONS=false" >> $GITHUB_ENV
3941
fi
4042
41-
# This step is for the deployment of the templates only, safe to delete
42-
- name: Modify deploy.yml
43-
env:
44-
KAMAL_DEPLOY_IP: ${{ secrets.KAMAL_DEPLOY_IP }}
45-
if: env.KAMAL_DEPLOY_IP != null
46-
run: |
47-
sed -i "s/service: my-app/service: ${{ env.repository_name_lower }}/g" config/deploy.yml
48-
sed -i "s#image: my-user/myapp#image: ${{ env.image_repository_name }}#g" config/deploy.yml
49-
sed -i "s/- 192.168.0.1/- ${{ secrets.KAMAL_DEPLOY_IP }}/g" config/deploy.yml
50-
sed -i "s/host: my-app.example.com/host: ${{ secrets.KAMAL_DEPLOY_HOST }}/g" config/deploy.yml
51-
sed -i "s/MyApp/${{ env.repository_name }}/g" config/deploy.yml
52-
5343
- name: Login to GitHub Container Registry
5444
uses: docker/login-action@v3
5545
with:
5646
registry: ghcr.io
57-
username: ${{ env.KAMAL_REGISTRY_USERNAME }}
58-
password: ${{ env.KAMAL_REGISTRY_PASSWORD }}
47+
username: ${{ github.actor }}
48+
password: ${{ secrets.GITHUB_TOKEN }}
5949

6050
- name: Set up SSH key
6151
uses: webfactory/[email protected]
@@ -80,29 +70,47 @@ jobs:
8070
run: |
8171
kamal server bootstrap
8272
73+
- name: Ensure directories exist with correct permissions
74+
run: |
75+
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"
77+
78+
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"
80+
8381
- name: Check if first run and execute kamal app boot if necessary
8482
run: |
85-
FIRST_RUN_FILE=".${{ env.repository_name }}"
86-
if ! kamal server exec --no-interactive -q "test -f $FIRST_RUN_FILE"; then
87-
kamal server exec --no-interactive -q "touch $FIRST_RUN_FILE" || true
83+
FIRST_RUN_FILE="~/first-run/${{ env.repository_name }}"
84+
if ! kamal server exec -q "test -f $FIRST_RUN_FILE"; then
85+
kamal server exec -q "mkdir -p ~/first-run && touch $FIRST_RUN_FILE" || true
86+
87+
if [ -n "${{env.INIT_DB_SQL}}" ]; then
88+
echo "Initializing DB with INIT_DB_SQL secret..."
89+
# Save the SQL content to a temporary file
90+
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
92+
fi
93+
# Start all kamal accessories
94+
kamal accessory boot all || true
95+
96+
# Deploy latest version
8897
kamal deploy -q -P --version latest || true
8998
else
9099
echo "Not first run, skipping kamal app boot"
91-
fi
100+
fi
92101
93-
- name: Ensure file permissions
102+
- name: Verify file permissions before deploy
103+
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"
105+
106+
- name: Deploy with Kamal
94107
run: |
95-
kamal server exec --no-interactive "mkdir -p /opt/docker/${{ env.repository_name }}/App_Data && chown -R 1654:1654 /opt/docker/${{ env.repository_name }}"
108+
kamal lock release -v
109+
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'
111+
kamal deploy -P --version latest
96112
97113
- name: Migration
98114
if: env.HAS_MIGRATIONS == 'true'
99115
run: |
100-
kamal server exec --no-interactive 'echo "${{ env.KAMAL_REGISTRY_PASSWORD }}" | docker login ghcr.io -u ${{ env.KAMAL_REGISTRY_USERNAME }} --password-stdin'
101-
kamal server exec --no-interactive "docker pull ghcr.io/${{ env.image_repository_name }}:latest || true"
102116
kamal app exec --no-reuse --no-interactive --version=latest "--AppTasks=migrate"
103-
104-
- name: Deploy with Kamal
105-
run: |
106-
kamal lock release -v
107-
kamal server exec --no-interactive 'echo "${{ env.KAMAL_REGISTRY_PASSWORD }}" | docker login ghcr.io -u ${{ env.KAMAL_REGISTRY_USERNAME }} --password-stdin'
108-
kamal deploy -P --version latest

MyApp.ServiceInterface/MyApp.ServiceInterface.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.*" />
11-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.*" />
12-
<PackageReference Include="ServiceStack" Version="8.*" />
13-
<PackageReference Include="ServiceStack.Ormlite" Version="8.*" />
10+
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="10.*" />
11+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.*" />
12+
<PackageReference Include="ServiceStack" Version="10.*" />
13+
<PackageReference Include="ServiceStack.Ormlite" Version="10.*" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

MyApp.ServiceModel/MyApp.ServiceModel.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="ServiceStack.Interfaces" Version="8.*" />
10+
<PackageReference Include="ServiceStack.Interfaces" Version="10.*" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

MyApp.Tests/MyApp.Tests.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<DebugType>portable</DebugType>
@@ -12,11 +12,11 @@
1212
<ProjectReference Include="..\MyApp.ServiceInterface\MyApp.ServiceInterface.csproj" />
1313
<ProjectReference Include="..\MyApp.ServiceModel\MyApp.ServiceModel.csproj" />
1414

15-
<PackageReference Include="NUnit" Version="3.*" />
16-
<PackageReference Include="NUnit3TestAdapter" Version="4.*" />
17-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
18-
<PackageReference Include="ServiceStack" Version="8.*" />
19-
<PackageReference Include="ServiceStack.Kestrel" Version="8.*" />
15+
<PackageReference Include="NUnit" Version="4.*" />
16+
<PackageReference Include="NUnit3TestAdapter" Version="5.*" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.*" />
18+
<PackageReference Include="ServiceStack" Version="10.*" />
19+
<PackageReference Include="ServiceStack.Kestrel" Version="10.*" />
2020
</ItemGroup>
2121

2222
</Project>

MyApp.sln

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

MyApp.slnx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Solution>
2+
<Project Path="MyApp.ServiceInterface/MyApp.ServiceInterface.csproj" />
3+
<Project Path="MyApp.ServiceModel/MyApp.ServiceModel.csproj" />
4+
<Project Path="MyApp.Tests/MyApp.Tests.csproj" />
5+
<Project Path="MyApp/MyApp.csproj" />
6+
</Solution>

MyApp/Configure.Db.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using ServiceStack.Data;
33
using ServiceStack.OrmLite;
44
using MyApp.Data;
5+
using Microsoft.EntityFrameworkCore.Diagnostics;
56

67
[assembly: HostingStartup(typeof(MyApp.ConfigureDb))]
78

@@ -12,14 +13,16 @@ public class ConfigureDb : IHostingStartup
1213
public void Configure(IWebHostBuilder builder) => builder
1314
.ConfigureServices((context, services) => {
1415
var connectionString = context.Configuration.GetConnectionString("DefaultConnection")
15-
?? "DataSource=App_Data/app.db;Cache=Shared";
16+
?? "DataSource=App_Data/app.db;Cache=Shared";
1617

1718
services.AddOrmLite(options => options.UseSqlite(connectionString));
1819

1920
// $ dotnet ef migrations add CreateIdentitySchema
2021
// $ dotnet ef database update
21-
services.AddDbContext<ApplicationDbContext>(options =>
22-
options.UseSqlite(connectionString, b => b.MigrationsAssembly(nameof(MyApp))));
22+
services.AddDbContext<ApplicationDbContext>(options => {
23+
options.UseSqlite(connectionString, b => b.MigrationsAssembly(nameof(MyApp)));
24+
options.ConfigureWarnings(w => w.Ignore(RelationalEventId.PendingModelChangesWarning));
25+
});
2326

2427
// Enable built-in Database Admin UI at /admin-ui/database
2528
services.AddPlugin(new AdminDatabaseFeature());

0 commit comments

Comments
 (0)