Skip to content

Commit 5c5a195

Browse files
committed
cleanup build + deploy
1 parent 2bae2bc commit 5c5a195

4 files changed

Lines changed: 47 additions & 27 deletions

File tree

.github/workflows/build-container.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ jobs:
3232
echo "repository_name_lower=$(echo ${{ github.repository }} | cut -d '/' -f 2 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
3333
echo "org_name=$(echo ${{ github.repository }} | cut -d '/' -f 1)" >> $GITHUB_ENV
3434
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+
3538
# Set KAMAL_DEPLOY_HOST: use secret if available, otherwise use repository name
3639
if [ -n "${{ secrets.KAMAL_DEPLOY_HOST }}" ]; then
3740
DEPLOY_HOST="${{ secrets.KAMAL_DEPLOY_HOST }}"
@@ -110,10 +113,12 @@ jobs:
110113
env:
111114
SERVICESTACK_LICENSE: ${{ secrets.SERVICESTACK_LICENSE }}
112115
KAMAL_DEPLOY_HOST: ${{ env.KAMAL_DEPLOY_HOST }}
116+
SERVICE_LABEL: ${{ env.SERVICE_LABEL }}
113117
run: |
114118
docker build \
115119
--build-arg SERVICESTACK_LICENSE="$SERVICESTACK_LICENSE" \
116120
--build-arg KAMAL_DEPLOY_HOST="$KAMAL_DEPLOY_HOST" \
121+
--build-arg SERVICE_LABEL="$SERVICE_LABEL" \
117122
-t ghcr.io/${{ env.image_repository_name }}:latest \
118123
-f Dockerfile .
119124
docker push ghcr.io/${{ env.image_repository_name }}:latest

Dockerfile

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,60 @@
11
# Multi-stage Dockerfile to run ASP.NET Core + Next.js in a single container
22

3-
# 1. Build .NET app
3+
# Build arguments
4+
ARG KAMAL_DEPLOY_HOST
5+
ARG SERVICESTACK_LICENSE
6+
ARG SERVICE_LABEL
7+
8+
# 1. Build .NET app + Node.js apps
49
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS dotnet-build
10+
ARG KAMAL_DEPLOY_HOST
11+
ENV KAMAL_DEPLOY_HOST=${KAMAL_DEPLOY_HOST}
12+
513
WORKDIR /src
614

15+
# Install Node.js for building Tailwind CSS and Next.js
16+
RUN apt-get update \
17+
&& apt-get install -y curl ca-certificates gnupg \
18+
&& curl -fsSL https://deb.nodesource.com/setup_24.x | bash - \
19+
&& apt-get install -y nodejs \
20+
&& apt-get clean \
21+
&& rm -rf /var/lib/apt/lists/*
22+
723
# Copy solution and projects
824
COPY TechStacks.sln ./
925
COPY TechStacks ./TechStacks
1026
COPY TechStacks.ServiceInterface ./TechStacks.ServiceInterface
1127
COPY TechStacks.ServiceModel ./TechStacks.ServiceModel
1228

13-
# Restore and publish only the API project (avoid solution projects not copied into the image)
14-
RUN dotnet restore TechStacks/TechStacks.csproj
15-
# Disable .NET's built-in containerization (PublishProfile=DefaultContainer) inside Docker
16-
RUN dotnet publish TechStacks/TechStacks.csproj -c Release --no-restore -p:PublishProfile=
29+
# Build Tailwind CSS for .NET project
30+
WORKDIR /src/TechStacks
31+
RUN npm install
32+
RUN npm run ui:build
1733

18-
# 2. Build Next.js app
19-
FROM node:20-alpine AS next-build
20-
ARG KAMAL_DEPLOY_HOST
21-
ENV KAMAL_DEPLOY_HOST=${KAMAL_DEPLOY_HOST}
22-
23-
WORKDIR /app/client
34+
# Build Next.js app
2435

36+
WORKDIR /src/TechStacks.Client
2537
COPY TechStacks.Client/package*.json ./
2638
RUN npm ci
2739
COPY TechStacks.Client/ ./
28-
29-
# Build Next.js in server mode
3040
RUN npm run build:prod
3141

32-
# 3. Runtime image with .NET + Node
42+
# Restore and publish .NET app
43+
WORKDIR /src
44+
RUN dotnet restore TechStacks/TechStacks.csproj
45+
# Disable .NET's built-in containerization (PublishProfile=DefaultContainer) inside Docker
46+
RUN dotnet publish TechStacks/TechStacks.csproj -c Release --no-restore -p:PublishProfile=
47+
48+
# 2. Runtime image with .NET + Node
3349
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
50+
ARG SERVICESTACK_LICENSE
51+
ARG SERVICE_LABEL
52+
ARG KAMAL_DEPLOY_HOST
53+
3454
WORKDIR /app
3555

36-
# Label required by Kamal, must match config/deploy.yml service (techstacks-io)
37-
LABEL service="techstacks-io"
38-
39-
ARG SERVICESTACK_LICENSE
56+
# Label required by Kamal, must match config/deploy.yml service
57+
LABEL service="${SERVICE_LABEL}"
4058

4159
# Install Node.js >= 20.9 (Node 24.x LTS) and bash for the entrypoint script
4260
RUN apt-get update \
@@ -49,14 +67,15 @@ RUN apt-get update \
4967
# Copy published .NET app
5068
COPY --from=dotnet-build /src/TechStacks/bin/Release/net10.0/publish ./api
5169

52-
# Copy built Next.js app (including .next, node_modules, public, etc.)
53-
COPY --from=next-build /app/client ./client
70+
# Copy built Next.js app (including dist, node_modules, public, etc.)
71+
COPY --from=dotnet-build /src/TechStacks.Client ./client
5472

5573
ENV ASPNETCORE_URLS=http://0.0.0.0:8080 \
74+
INTERNAL_API_URL=http://127.0.0.1:8080 \
5675
NEXT_PORT=3000 \
5776
NODE_ENV=production \
58-
INTERNAL_API_URL=http://127.0.0.1:8080 \
59-
SERVICESTACK_LICENSE=$SERVICESTACK_LICENSE
77+
SERVICESTACK_LICENSE=$SERVICESTACK_LICENSE \
78+
KAMAL_DEPLOY_HOST=$KAMAL_DEPLOY_HOST
6079

6180
EXPOSE 8080
6281

TechStacks.Client/src/lib/api/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const getBaseUrl = () => {
55
if (typeof window === 'undefined') {
66
// Server-side (during build): use absolute URL if available
77
// This is needed for generateStaticParams to fetch data during build
8-
return process.env.INTERNAL_API_URL || process.env.apiBaseUrl || 'https://techstacks.io';
8+
return process.env.INTERNAL_API_URL || process.env.apiBaseUrl || '';
99
}
1010
// Client-side: use relative path (served by same origin or proxied)
1111
return '/';

TechStacks/TechStacks.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,4 @@
5555
<MakeDir Directories="$(PublishDir)App_Data" Condition="!Exists('$(PublishDir)App_Data')" />
5656
</Target>
5757

58-
<Target Name="tailwind" BeforeTargets="Publish">
59-
<Exec Command="npm run ui:build" WorkingDirectory="./" />
60-
</Target>
61-
6258
</Project>

0 commit comments

Comments
 (0)