Skip to content

Commit 5a93016

Browse files
committed
Simplify .yml + remove load-env.sh
1 parent 7497570 commit 5a93016

File tree

5 files changed

+37
-76
lines changed

5 files changed

+37
-76
lines changed

.github/workflows/build-container.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,17 @@ jobs:
2727

2828
- name: Set up environment variables
2929
run: |
30-
echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
31-
echo "repository_name=$(echo ${{ github.repository }} | cut -d '/' -f 2)" >> $GITHUB_ENV
32-
echo "repository_name_lower=$(echo ${{ github.repository }} | cut -d '/' -f 2 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
33-
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)"
3432
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
33+
# Set SERVICE: derive from repo name (replace dots with dashes)
34+
echo "SERVICE=$(echo $repo_name | tr '[:upper:]' '[:lower:]' | tr '.' '-')" >> $GITHUB_ENV
3735
3836
# Set KAMAL_DEPLOY_HOST: use secret if available, otherwise use repository name
3937
if [ -n "${{ secrets.KAMAL_DEPLOY_HOST }}" ]; then
4038
DEPLOY_HOST="${{ secrets.KAMAL_DEPLOY_HOST }}"
4139
else
42-
DEPLOY_HOST="$(echo ${{ github.repository }} | cut -d '/' -f 2)"
40+
DEPLOY_HOST="$repo_name"
4341
fi
4442
4543
# Validate KAMAL_DEPLOY_HOST contains at least one '.'
@@ -56,7 +54,7 @@ jobs:
5654
KAMAL_DEPLOY_IP: ${{ secrets.KAMAL_DEPLOY_IP }}
5755
if: env.KAMAL_DEPLOY_IP != null
5856
run: |
59-
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
6058
6159
- name: Check for Client directory and package.json
6260
id: check_client
@@ -99,12 +97,12 @@ jobs:
9997
env:
10098
SERVICESTACK_LICENSE: ${{ secrets.SERVICESTACK_LICENSE }}
10199
KAMAL_DEPLOY_HOST: ${{ env.KAMAL_DEPLOY_HOST }}
102-
SERVICE_LABEL: ${{ env.SERVICE_LABEL }}
100+
SERVICE: ${{ env.SERVICE }}
103101
run: |
104102
docker build \
105103
--build-arg SERVICESTACK_LICENSE="$SERVICESTACK_LICENSE" \
106104
--build-arg KAMAL_DEPLOY_HOST="$KAMAL_DEPLOY_HOST" \
107-
--build-arg SERVICE_LABEL="$SERVICE_LABEL" \
108-
-t ghcr.io/${{ env.image_repository_name }}:latest \
105+
--build-arg SERVICE="$SERVICE" \
106+
-t ${{ env.IMAGE }}:latest \
109107
-f Dockerfile .
110-
docker push ghcr.io/${{ env.image_repository_name }}:latest
108+
docker push ${{ env.IMAGE }}:latest

.github/workflows/release.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ jobs:
3838
3939
- name: Set up environment variables
4040
run: |
41-
echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
42-
echo "repository_name=$(echo ${{ github.repository }} | cut -d '/' -f 2)" >> $GITHUB_ENV
43-
echo "repository_name_lower=$(echo ${{ github.repository }} | cut -d '/' -f 2 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
44-
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
4544
if find . -maxdepth 2 -type f -name "Configure.Db.Migrations.cs" | grep -q .; then
4645
echo "HAS_MIGRATIONS=true" >> $GITHUB_ENV
4746
else
@@ -81,22 +80,22 @@ jobs:
8180
- name: Ensure directories exist with correct permissions
8281
run: |
8382
echo "Creating directories with correct permissions"
84-
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"
8584
8685
echo "Setting app file permissions"
87-
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"
8887
8988
- name: Check if first run and execute kamal app boot if necessary
9089
run: |
91-
FIRST_RUN_FILE="~/first-run/${{ env.repository_name }}"
90+
FIRST_RUN_FILE="~/first-run/${{ env.SERVICE }}"
9291
if ! kamal server exec -q "test -f $FIRST_RUN_FILE"; then
9392
kamal server exec -q "mkdir -p ~/first-run && touch $FIRST_RUN_FILE" || true
9493
9594
if [ -n "${{env.INIT_DB_SQL}}" ]; then
9695
echo "Initializing DB with INIT_DB_SQL secret..."
9796
# Save the SQL content to a temporary file
9897
echo "${{ env.INIT_DB_SQL }}" > init-db.sql
99-
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
10099
fi
101100
# Start all kamal accessories
102101
kamal accessory boot all || true
@@ -109,13 +108,13 @@ jobs:
109108
110109
- name: Verify file permissions before deploy
111110
run: |
112-
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"
113112
114113
- name: Deploy with Kamal
115114
run: |
116115
kamal lock release -v
117116
kamal server exec --no-interactive 'echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin'
118-
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'
119118
kamal deploy -P --version latest
120119
121120
- name: Migration

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Build arguments
44
ARG KAMAL_DEPLOY_HOST
55
ARG SERVICESTACK_LICENSE
6-
ARG SERVICE_LABEL
6+
ARG SERVICE
77

88
# 1. Build .NET app + Node.js apps
99
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS dotnet-build
@@ -51,13 +51,13 @@ RUN dotnet publish MyApp/MyApp.csproj -c Release --no-restore -p:PublishProfile=
5151
# 2. Runtime image with .NET + Node
5252
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
5353
ARG SERVICESTACK_LICENSE
54-
ARG SERVICE_LABEL
54+
ARG SERVICE
5555
ARG KAMAL_DEPLOY_HOST
5656

5757
WORKDIR /app
5858

5959
# Label required by Kamal, must match config/deploy.yml service
60-
LABEL service="${SERVICE_LABEL}"
60+
LABEL service="${SERVICE}"
6161

6262
# Install Node.js >= 20.9 (Node 24.x LTS) and bash for the entrypoint script
6363
RUN apt-get update \

config/deploy.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1+
# <% require "dotenv"; Dotenv.load(".env") %>
12
# Kamal deploy config for this repository. Uses environment variables:
2-
# - GITHUB_REPOSITORY (e.g. acme/example.org) - from GitHub Action ${github.repository}
3-
# - KAMAL_REGISTRY_USERNAME (e.g. my-user) - from GitHub Action ${github.actor}
4-
# - KAMAL_REGISTRY_PASSWORD ($GITHUB_TOKEN) - from GitHub Action ${secrets.GITHUB_TOKEN}
5-
# - KAMAL_DEPLOY_IP (e.g. 100.100.100.100) - from GitHub Action Secret
6-
# - KAMAL_DEPLOY_HOST (e.g. example.org) - from GitHub Action Secret
7-
# - POSTGRES_PASSWORD (e.g. random-password) - from GitHub Action Secret
8-
3+
# - GITHUB_REPOSITORY (e.g. acme/example.org) - from GitHub Action ${github.repository}
4+
# SERVICE (e.g. example-org)
5+
# IMAGE (e.g. ghcr.io/acme/example.org)
6+
# - KAMAL_REGISTRY_USERNAME (e.g. my-user) - from GitHub Action ${github.actor}
7+
# - KAMAL_REGISTRY_PASSWORD ($GITHUB_TOKEN) - from GitHub Action ${secrets.GITHUB_TOKEN}
8+
# - KAMAL_DEPLOY_IP (e.g. 100.100.100.100) - from GitHub Action Secret
9+
# - KAMAL_DEPLOY_HOST (e.g. example.org) - from GitHub Action Secret
10+
# - POSTGRES_PASSWORD (e.g. random-password) - from GitHub Action Secret
11+
#
912
# Using environment variables keeps this configuration reusable across multiple apps.
10-
# For a simpler, app-specific setup, you can replace them with hard-coded values.
13+
# For a simpler app-specific setup (without needing .env), they can be replaced with hard-coded values.
1114

1215
# Name of your application. Used to uniquely configure containers. (e.g. example-org)
13-
service: <%= ENV['GITHUB_REPOSITORY'].to_s.split('/').last.tr('.', '-') %>
16+
service: <%= ENV['SERVICE'] %>
1417

15-
# Name of the container image. (e.g. ghcr.io/acne/example.org)
16-
image: ghcr.io/<%= ENV['GITHUB_REPOSITORY'].to_s.downcase %>
18+
# Name of the container image. (e.g. ghcr.io/acme/example.org)
19+
image: <%= ENV['IMAGE'] %>
1720

1821
# Required for use of ASP.NET Core with Kamal-Proxy.
1922
env:
@@ -57,7 +60,7 @@ builder:
5760
arch: amd64
5861

5962
volumes:
60-
- "/opt/docker/<%= ENV['GITHUB_REPOSITORY'].to_s.split('/').last %>/App_Data:/app/App_Data"
63+
- "/opt/docker/<%= ENV['SERVICE'] %>/App_Data:/app/App_Data"
6164

6265
#accessories:
6366
# litestream:

load-env.sh

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

0 commit comments

Comments
 (0)