Skip to content

Commit 0d1a846

Browse files
committed
Update GitHub Actions
1 parent 90cba9a commit 0d1a846

File tree

4 files changed

+24
-73
lines changed

4 files changed

+24
-73
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/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)