Skip to content

Commit 735a67e

Browse files
authored
Merge pull request #4 from xnodeoncode/test/deploy
Add deployment settings
2 parents 4f48bb2 + adc4dbb commit 735a67e

7 files changed

Lines changed: 175 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Auto-merge on approval
2+
on:
3+
pull_request_review:
4+
types: [submitted]
5+
6+
jobs:
7+
automerge:
8+
if: ${{ github.event.review.state == 'approved' }}
9+
runs-on: ubuntu-latest
10+
permissions:
11+
pull-requests: write
12+
contents: write
13+
checks: read
14+
steps:
15+
- name: Attempt merge when approved
16+
run: |
17+
echo "Auto-merge on approval disabled."
18+
echo "Please merge the PR manually after required checks and approvals pass."

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
jobs:
1010
build:
11+
name: Build and Test
1112
runs-on: ubuntu-latest
1213

1314
steps:

.github/workflows/deploy.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Deploy to Azure (on merge to main)
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
env:
8+
DOTNET_VERSION: "9.0.x"
9+
10+
jobs:
11+
build-and-deploy:
12+
name: Build, Publish and Deploy
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Setup .NET
19+
uses: actions/setup-dotnet@v4
20+
with:
21+
dotnet-version: ${{ env.DOTNET_VERSION }}
22+
23+
- name: Restore
24+
run: dotnet restore Aquiis.sln
25+
26+
- name: Publish
27+
run: dotnet publish ./Aquiis.SimpleStart/Aquiis.SimpleStart.csproj -c Release -o ./publish
28+
29+
- name: Azure Login (for deployment)
30+
uses: azure/login@v1
31+
with:
32+
creds: ${{ secrets.AZURE_CREDENTIALS }}
33+
34+
- name: Deploy with Azure CLI
35+
run: |
36+
az webapp deploy \
37+
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
38+
--name ${{ secrets.AZURE_WEBAPP_NAME }} \
39+
--src-path ./publish
40+
41+
- name: Save publish profile to file
42+
run: |
43+
echo "${{ secrets.AZURE_PUBLISH_PROFILE }}" > /tmp/publish_profile.xml
44+
45+
- name: Extract DB settings and export to GITHUB_ENV
46+
run: |
47+
DB_FILE=$(jq -r '.ApplicationSettings.DatabaseFileName // "app_v0.0.0.db"' Aquiis.SimpleStart/appsettings.json)
48+
PREV_DB_FILE=$(jq -r '.ApplicationSettings.PreviousDatabaseFileName // ""' Aquiis.SimpleStart/appsettings.json)
49+
APP_VERSION=$(jq -r '.ApplicationSettings.Version // ""' Aquiis.SimpleStart/appsettings.json)
50+
SCHEMA_VERSION=$(jq -r '.ApplicationSettings.SchemaVersion // ""' Aquiis.SimpleStart/appsettings.json)
51+
echo "DB_FILE=$DB_FILE" >> "$GITHUB_ENV"
52+
echo "PREV_DB_FILE=$PREV_DB_FILE" >> "$GITHUB_ENV"
53+
echo "APP_VERSION=$APP_VERSION" >> "$GITHUB_ENV"
54+
echo "SCHEMA_VERSION=$SCHEMA_VERSION" >> "$GITHUB_ENV"
55+
echo "DB_PATH=/home/data/$DB_FILE" >> "$GITHUB_ENV"
56+
shell: bash
57+
58+
- name: Create /home/data on App Service
59+
run: |
60+
chmod +x ./scripts/kudu-create-data-dir.sh
61+
./scripts/kudu-create-data-dir.sh /tmp/publish_profile.xml ${{ secrets.AZURE_WEBAPP_NAME }}
62+
63+
- name: Backup existing DB (if any)
64+
run: |
65+
chmod +x ./scripts/kudu-backup-db.sh
66+
./scripts/kudu-backup-db.sh /tmp/publish_profile.xml ${{ secrets.AZURE_WEBAPP_NAME }} "$DB_PATH" || true
67+
68+
- name: Azure Login (for App Settings)
69+
uses: azure/login@v1
70+
with:
71+
creds: ${{ secrets.AZURE_CREDENTIALS }}
72+
73+
- name: Configure App Settings (set SQLite connection string and app metadata)
74+
run: |
75+
az webapp config appsettings set \
76+
--resource-group "${{ secrets.AZURE_RESOURCE_GROUP }}" \
77+
--name "${{ secrets.AZURE_WEBAPP_NAME }}" \
78+
--settings \
79+
"ConnectionStrings__DefaultConnection=DataSource=/home/data/$DB_FILE;Cache=Shared" \
80+
"ApplicationSettings__Version=$APP_VERSION" \
81+
"ApplicationSettings__DatabaseFileName=$DB_FILE" \
82+
"ApplicationSettings__PreviousDatabaseFileName=$PREV_DB_FILE" \
83+
"ApplicationSettings__SchemaVersion=$SCHEMA_VERSION" \
84+
ASPNETCORE_ENVIRONMENT=Production
85+
shell: bash

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Data/Backups/**
2121

2222
/Data/app*
2323

24+
sp_credentials.json
25+
26+
publish_profile.xml
27+
2428

2529
# Python virtual environment created per-project
2630
.venv/

scripts/kudu-backup-db.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
# Usage: ./kudu-backup-db.sh /path/to/publish_profile.xml APP_NAME [/home/data/app.db]
4+
PUBLISH_PROFILE_FILE=${1:-}
5+
APP_NAME=${2:-}
6+
SRC_DB_PATH=${3:-/home/data/app_v0.0.0.db}
7+
if [ -z "$PUBLISH_PROFILE_FILE" ] || [ -z "$APP_NAME" ]; then
8+
echo "Usage: $0 <publish-profile-xml> <webapp-name> [src-db-path]" >&2
9+
exit 2
10+
fi
11+
12+
KUDU_USER=$(grep -o 'userName="[^"]*"' "$PUBLISH_PROFILE_FILE" | head -1 | sed -E 's/userName="([^"]+)"/\1/')
13+
KUDU_PWD=$(grep -o 'userPWD="[^"]*"' "$PUBLISH_PROFILE_FILE" | head -1 | sed -E 's/userPWD="([^"]+)"/\1/')
14+
15+
16+
TS=$(date +%Y%m%d%H%M%S)
17+
BACKUP_PATH="/home/data/Backups/$(basename $SRC_DB_PATH).$TS"
18+
19+
API="https://${APP_NAME}.scm.azurewebsites.net/api/command"
20+
CMD="mkdir -p /home/data/Backups && cp '$SRC_DB_PATH' '$BACKUP_PATH' && ls -l /home/data/Backups"
21+
22+
echo "Backing up $SRC_DB_PATH -> $BACKUP_PATH on ${APP_NAME} via Kudu..."
23+
curl -s -X POST -u "$KUDU_USER:$KUDU_PWD" -H "Content-Type: application/json" -d "{\"command\":\"$CMD\"}" "$API" | jq .
24+
25+
echo "Backup complete: $BACKUP_PATH"

scripts/kudu-cleanup-backups.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
# Usage: ./kudu-cleanup-backups.sh /path/to/publish_profile.xml APP_NAME RETAIN_DAYS
4+
PUBLISH_PROFILE_FILE=${1:-}
5+
APP_NAME=${2:-}
6+
RETAIN_DAYS=${3:-30}
7+
if [ -z "$PUBLISH_PROFILE_FILE" ] || [ -z "$APP_NAME" ]; then
8+
echo "Usage: $0 <publish-profile-xml> <webapp-name> [retain-days]" >&2
9+
exit 2
10+
fi
11+
12+
KUDU_USER=$(grep -o 'userName="[^"]*"' "$PUBLISH_PROFILE_FILE" | head -1 | sed -E 's/userName="([^"]+)"/\1/')
13+
KUDU_PWD=$(grep -o 'userPWD="[^"]*"' "$PUBLISH_PROFILE_FILE" | head -1 | sed -E 's/userPWD="([^"]+)"/\1/')
14+
15+
16+
API="https://${APP_NAME}.scm.azurewebsites.net/api/command"
17+
CMD="find /home/data/Backups -type f -mtime +$RETAIN_DAYS -print -delete || true && ls -l /home/data/Backups"
18+
19+
echo "Cleaning up backups older than $RETAIN_DAYS days on ${APP_NAME} via Kudu..."
20+
curl -s -X POST -u "$KUDU_USER:$KUDU_PWD" -H "Content-Type: application/json" -d "{\"command\":\"$CMD\"}" "$API" | jq .
21+
22+
echo "Cleanup complete."

scripts/kudu-create-data-dir.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
# Usage: ./kudu-create-data-dir.sh /path/to/publish_profile.xml APP_NAME
4+
PUBLISH_PROFILE_FILE=${1:-}
5+
APP_NAME=${2:-}
6+
if [ -z "$PUBLISH_PROFILE_FILE" ] || [ -z "$APP_NAME" ]; then
7+
echo "Usage: $0 <publish-profile-xml> <webapp-name>" >&2
8+
exit 2
9+
fi
10+
11+
KUDU_USER=$(grep -o 'userName="[^"]*"' "$PUBLISH_PROFILE_FILE" | head -1 | sed -E 's/userName="([^"]+)"/\1/')
12+
KUDU_PWD=$(grep -o 'userPWD="[^"]*"' "$PUBLISH_PROFILE_FILE" | head -1 | sed -E 's/userPWD="([^"]+)"/\1/')
13+
14+
API="https://${APP_NAME}.scm.azurewebsites.net/api/command"
15+
CMD='mkdir -p /home/data && chmod 775 /home/data'
16+
17+
echo "Creating /home/data on ${APP_NAME} via Kudu..."
18+
curl -s -X POST -u "$KUDU_USER:$KUDU_PWD" -H "Content-Type: application/json" -d "{\"command\":\"$CMD\"}" "$API" | jq .
19+
20+
echo "Done."

0 commit comments

Comments
 (0)