Skip to content

Commit 1fa050f

Browse files
rubenvdlindeclaude
andcommitted
Convert to ExApp architecture and add CI/CD workflows
Convert from PHP Nextcloud app to ExApp with Docker-based deployment. Add standardized CI/CD workflows for unstable release, dev-to-beta PR creation, branch protection, and lint checks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 38a9283 commit 1fa050f

21 files changed

Lines changed: 864 additions & 236 deletions

.github/workflows/build-exapp.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build and Push ExApp Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- beta
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
branches:
12+
- main
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
IMAGE_NAME: conductionnl/openklant-exapp
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
packages: write
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Log in to Container Registry
33+
if: github.event_name != 'pull_request'
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Extract metadata
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=ref,event=branch
47+
type=ref,event=pr
48+
type=semver,pattern={{version}}
49+
type=semver,pattern={{major}}.{{minor}}
50+
type=raw,value=latest,enable={{is_default_branch}}
51+
52+
- name: Build and push
53+
uses: docker/build-push-action@v5
54+
with:
55+
context: .
56+
push: ${{ github.event_name != 'pull_request' }}
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}
59+
cache-from: type=gha
60+
cache-to: type=gha,mode=max
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Main Branch Protection
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
check-branch:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check branch
13+
run: |
14+
if [[ ${GITHUB_HEAD_REF} != development ]] && [[ ${GITHUB_HEAD_REF} != documentation ]] && ! [[ ${GITHUB_HEAD_REF} =~ ^hotfix/ ]];
15+
then
16+
echo "Error: Pull request must come from 'development', 'documentation' or 'hotfix/' branch"
17+
exit 1
18+
fi
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Lint Check
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- development
7+
- main
8+
9+
jobs:
10+
lint-check:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v2
16+
17+
- name: Install dependencies
18+
run: npm i
19+
20+
- name: Linting
21+
run: npm run lint
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Create PR to Beta
2+
3+
permissions:
4+
contents: write
5+
pull-requests: write
6+
7+
on:
8+
push:
9+
branches:
10+
- development
11+
12+
jobs:
13+
create-pr:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout Code
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Create or update PR to beta
22+
env:
23+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
run: |
25+
# Check if beta branch exists
26+
if ! git ls-remote --heads origin beta | grep -q beta; then
27+
echo "Beta branch does not exist yet. Creating from development..."
28+
git push origin origin/development:refs/heads/beta
29+
fi
30+
31+
# Check if a PR already exists
32+
EXISTING_PR=$(gh pr list --base beta --head development --state open --json number --jq '.[0].number' || echo "")
33+
34+
if [ -n "$EXISTING_PR" ] && [ "$EXISTING_PR" != "null" ]; then
35+
echo "PR #$EXISTING_PR already exists, it will auto-update with new commits"
36+
else
37+
gh pr create \
38+
--base beta \
39+
--head development \
40+
--title "Release: merge development into beta" \
41+
--body "Automated PR to sync development changes to beta for beta release.
42+
43+
Merging this PR will trigger the beta release workflow."
44+
fi
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
name: Unstable Release
2+
3+
on:
4+
push:
5+
branches:
6+
- development
7+
8+
jobs:
9+
release-management:
10+
runs-on: ubuntu-latest
11+
steps:
12+
13+
- name: Checkout Code
14+
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
ssh-key: ${{ secrets.DEPLOY_KEY }}
18+
19+
- name: Set app env
20+
run: |
21+
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
22+
23+
- name: Get current version and append unstable suffix
24+
id: increment_version
25+
run: |
26+
git fetch origin main
27+
main_version=$(git show origin/main:appinfo/info.xml | grep -oP '(?<=<version>)[^<]+' || echo "")
28+
current_version=$(grep -oP '(?<=<version>)[^<]+' appinfo/info.xml || echo "")
29+
30+
IFS='.' read -ra main_version_parts <<< "$main_version"
31+
next_patch=$((main_version_parts[2] + 1))
32+
33+
unstable_counter=1
34+
if [[ $current_version =~ -unstable\.([0-9]+)$ ]]; then
35+
current_patch=$(echo $current_version | grep -oP '^[0-9]+\.[0-9]+\.(\d+)' | cut -d. -f3)
36+
if [ "$current_patch" -eq "$next_patch" ]; then
37+
unstable_counter=$((BASH_REMATCH[1] + 1))
38+
fi
39+
fi
40+
41+
unstable_version="${main_version_parts[0]}.${main_version_parts[1]}.${next_patch}-unstable.${unstable_counter}"
42+
43+
echo "NEW_VERSION=$unstable_version" >> $GITHUB_ENV
44+
echo "new_version=$unstable_version" >> $GITHUB_OUTPUT
45+
echo "Main version: $main_version"
46+
echo "Current version: $current_version"
47+
echo "Using unstable version: $unstable_version"
48+
49+
- name: Update version in info.xml
50+
run: |
51+
sed -i "s|<version>.*</version>|<version>${{ env.NEW_VERSION }}</version>|" appinfo/info.xml
52+
53+
- name: Commit version update
54+
run: |
55+
git config --local user.email "action@github.com"
56+
git config --local user.name "GitHub Action"
57+
58+
if git diff --quiet && git diff --cached --quiet; then
59+
echo "No changes to commit"
60+
else
61+
git add appinfo/info.xml
62+
git commit -m "Bump unstable version to ${{ env.NEW_VERSION }} [skip ci]"
63+
git push
64+
fi
65+
66+
- name: Prepare Signing Certificate and Key
67+
run: |
68+
echo "${{ secrets.NEXTCLOUD_SIGNING_CERT }}" > signing-cert.crt
69+
echo "${{ secrets.NEXTCLOUD_SIGNING_KEY }}" > signing-key.key
70+
71+
- name: Install npm dependencies
72+
uses: actions/setup-node@v3
73+
with:
74+
node-version: '18.x'
75+
76+
- name: Set up PHP and install extensions
77+
uses: shivammathur/setup-php@v2
78+
with:
79+
php-version: '8.2'
80+
extensions: zip, gd
81+
82+
- run: npm ci
83+
- run: npm run build
84+
- run: composer install --no-dev --optimize-autoloader --classmap-authoritative
85+
86+
- name: Copy the package files into the package
87+
run: |
88+
mkdir -p package/${{ github.event.repository.name }}
89+
rsync -av --progress \
90+
--exclude='/package' \
91+
--exclude='/.git' \
92+
--exclude='/.github' \
93+
--exclude='/.cursor' \
94+
--exclude='/.vscode' \
95+
--exclude='/node_modules' \
96+
--exclude='/src' \
97+
--exclude='/tests' \
98+
--exclude='/package.json' \
99+
--exclude='/package-lock.json' \
100+
--exclude='/composer.json' \
101+
--exclude='/composer.lock' \
102+
--exclude='/phpcs.xml' \
103+
--exclude='/phpmd.xml' \
104+
--exclude='/psalm.xml' \
105+
--exclude='/phpunit.xml' \
106+
--exclude='/.phpunit.cache' \
107+
--exclude='.phpunit.result.cache' \
108+
--exclude='/jest.config.js' \
109+
--exclude='/webpack.config.js' \
110+
--exclude='/tsconfig.json' \
111+
--exclude='/.babelrc' \
112+
--exclude='/.eslintrc.js' \
113+
--exclude='/.prettierrc' \
114+
--exclude='/stylelint.config.js' \
115+
--exclude='/.gitignore' \
116+
--exclude='/.gitattributes' \
117+
--exclude='/signing-key.key' \
118+
--exclude='/signing-cert.crt' \
119+
./ package/${{ github.event.repository.name }}/
120+
121+
- name: Create Tarball
122+
run: |
123+
cd package && tar -czf ../nextcloud-release.tar.gz ${{ github.event.repository.name }}
124+
125+
- name: Sign the TAR.GZ file with OpenSSL
126+
run: |
127+
openssl dgst -sha512 -sign signing-key.key nextcloud-release.tar.gz | openssl base64 -out nextcloud-release.signature
128+
129+
- name: Upload tarball as artifact
130+
uses: actions/upload-artifact@v4
131+
with:
132+
name: nextcloud-release-${{ env.NEW_VERSION }}
133+
path: |
134+
nextcloud-release.tar.gz
135+
nextcloud-release.signature
136+
retention-days: 30
137+
138+
- name: Git Version
139+
id: version
140+
uses: codacy/git-version@2.7.1
141+
with:
142+
release-branch: development
143+
144+
- name: Upload Unstable Release
145+
uses: ncipollo/release-action@v1.12.0
146+
with:
147+
tag: v${{ env.NEW_VERSION }}
148+
name: Unstable Release ${{ env.NEW_VERSION }}
149+
draft: false
150+
prerelease: true
151+
skipIfReleaseExists: true
152+
153+
- name: Attach tarball to GitHub release
154+
uses: svenstaro/upload-release-action@v2
155+
with:
156+
repo_token: ${{ secrets.GITHUB_TOKEN }}
157+
file: nextcloud-release.tar.gz
158+
asset_name: ${{ env.APP_NAME }}-${{ env.NEW_VERSION }}.tar.gz
159+
tag: v${{ env.NEW_VERSION }}
160+
overwrite: true
161+
162+
- name: Upload app to Nextcloud appstore
163+
uses: nextcloud-releases/nextcloud-appstore-push-action@a011fe619bcf6e77ddebc96f9908e1af4071b9c1
164+
with:
165+
app_name: ${{ env.APP_NAME }}
166+
appstore_token: ${{ secrets.NEXTCLOUD_APPSTORE_TOKEN }}
167+
download_url: https://github.com/${{ github.repository }}/releases/download/v${{ env.NEW_VERSION }}/${{ env.APP_NAME }}-${{ env.NEW_VERSION }}.tar.gz
168+
app_private_key: ${{ secrets.NEXTCLOUD_SIGNING_KEY }}
169+
nightly: true
170+
171+
- name: Verify release
172+
run: |
173+
echo "App version: ${{ env.NEW_VERSION }}"
174+
echo "Tarball contents:"
175+
tar -tvf nextcloud-release.tar.gz | head -50
176+
echo "info.xml contents:"
177+
tar -xOf nextcloud-release.tar.gz ${{ env.APP_NAME }}/appinfo/info.xml

Dockerfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# OpenKlant ExApp for Nextcloud
2+
# Wraps OpenKlant customer interaction registry with AppAPI integration
3+
#
4+
# OpenKlant is part of the Common Ground ecosystem for Dutch municipalities.
5+
# It requires:
6+
# - PostgreSQL database
7+
# - Redis for caching (optional)
8+
#
9+
# See: https://github.com/maykinmedia/open-klant
10+
11+
# Use upstream OpenKlant image as base (already has Django, uwsgi, etc.)
12+
FROM maykinmedia/open-klant:2.2.0
13+
14+
# Install additional dependencies for ExApp wrapper
15+
USER root
16+
17+
RUN apt-get update && apt-get install -y --no-install-recommends \
18+
curl \
19+
tini \
20+
&& rm -rf /var/lib/apt/lists/*
21+
22+
# Install Python dependencies for ExApp wrapper (FastAPI, uvicorn, httpx)
23+
RUN pip install --no-cache-dir \
24+
"fastapi>=0.109.0" \
25+
"uvicorn>=0.27.0" \
26+
"httpx>=0.26.0"
27+
28+
# Copy ExApp wrapper
29+
COPY ex_app /app/ex_app
30+
COPY entrypoint.sh /entrypoint.sh
31+
RUN chmod +x /entrypoint.sh
32+
33+
# Create directories for media and static files
34+
RUN mkdir -p /app/media /app/static /app/log && \
35+
chown -R nobody:nogroup /app/media /app/static /app/log
36+
37+
WORKDIR /app
38+
39+
# Environment variables (set by AppAPI)
40+
ENV APP_HOST=0.0.0.0
41+
ENV APP_PORT=9000
42+
ENV PYTHONUNBUFFERED=1
43+
44+
# OpenKlant configuration
45+
ENV OPENKLANT_PORT=8000
46+
ENV DJANGO_SETTINGS_MODULE=openklant.conf.docker
47+
48+
# OpenKlant requires these to be set (defaults for development)
49+
ENV DB_HOST=localhost
50+
ENV DB_NAME=openklant
51+
ENV DB_USER=openklant
52+
ENV DB_PASSWORD=openklant
53+
ENV SECRET_KEY=change-me-in-production
54+
ENV ALLOWED_HOSTS=*
55+
56+
# Expose ports: 9000 for AppAPI, 8000 for OpenKlant
57+
EXPOSE 9000 8000
58+
59+
# Health check - just verify the wrapper is responding (any status is ok during init)
60+
HEALTHCHECK --interval=30s --timeout=5s --start-period=90s --retries=3 \
61+
CMD curl -s http://localhost:${APP_PORT:-9000}/heartbeat | grep -q status || exit 1
62+
63+
ENTRYPOINT ["/usr/bin/tini", "--", "/entrypoint.sh"]

0 commit comments

Comments
 (0)