Skip to content

Commit 4c699d1

Browse files
committed
Update GitHub Actions
1 parent a59b516 commit 4c699d1

File tree

5 files changed

+41
-83
lines changed

5 files changed

+41
-83
lines changed

.github/workflows/build-container.yml

Lines changed: 7 additions & 23 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
@@ -83,20 +81,6 @@ jobs:
8381
working-directory: ./MyApp.Client
8482
run: npm run build
8583

86-
- name: Install x tool
87-
run: dotnet tool install -g x
88-
89-
- name: Apply Production AppSettings
90-
env:
91-
APPSETTINGS_PATCH: ${{ secrets.APPSETTINGS_PATCH }}
92-
if: env.APPSETTINGS_PATCH != null
93-
working-directory: ./MyApp
94-
run: |
95-
cat <<EOF >> appsettings.json.patch
96-
${{ secrets.APPSETTINGS_PATCH }}
97-
EOF
98-
x patch appsettings.json.patch
99-
10084
- name: Login to GitHub Container Registry
10185
uses: docker/login-action@v3
10286
with:
@@ -115,7 +99,7 @@ jobs:
11599
KAMAL_DEPLOY_HOST: ${{ secrets.KAMAL_DEPLOY_HOST }}
116100
run: |
117101
dotnet publish --os linux --arch x64 -c Release \
118-
-p:ContainerRepository=${{ env.image_repository_name }} \
102+
-p:ContainerRepository=${{ env.IMAGE }} \
119103
-p:ContainerRegistry=ghcr.io -p:ContainerImageTags=latest \
120104
-p:ContainerPort=80 \
121105
-p:ContainerEnvironmentVariable="SERVICESTACK_LICENSE=${{ env.SERVICESTACK_LICENSE }}"

.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

.kamal/secrets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD
77
KAMAL_REGISTRY_USERNAME=$KAMAL_REGISTRY_USERNAME
88
SERVICESTACK_LICENSE=$SERVICESTACK_LICENSE
9+
APPSETTINGS_JSON_BASE64=$APPSETTINGS_JSON_BASE64
910

1011
# Option 2: Read secrets via a command
1112
# RAILS_MASTER_KEY=$(cat config/master.key)

config/deploy.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +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-
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+
#
812
# Using environment variables keeps this configuration reusable across multiple apps.
9-
# 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.
1014

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

14-
# Name of the container image. (e.g. ghcr.io/acne/example.org)
15-
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'] %>
1620

1721
# Required for use of ASP.NET Core with Kamal-Proxy.
1822
env:
@@ -21,6 +25,7 @@ env:
2125
# secrets from ./kamal/secrets
2226
secret:
2327
- SERVICESTACK_LICENSE
28+
- APPSETTINGS_JSON_BASE64
2429

2530
# Deploy to these servers.
2631
servers:
@@ -55,7 +60,7 @@ builder:
5560
arch: amd64
5661

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

6065
#accessories:
6166
# litestream:

load-env.sh

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

0 commit comments

Comments
 (0)