All checks were successful
Build MapleDeploy Coolify Image / build (push) Successful in 34s
131 lines
5.1 KiB
YAML
131 lines
5.1 KiB
YAML
name: Build MapleDeploy Coolify Image
|
|
|
|
on:
|
|
push:
|
|
branches: [mapledeploy]
|
|
paths-ignore:
|
|
- "*.md"
|
|
- ".github/**"
|
|
|
|
env:
|
|
REGISTRY: forgejo.mapledeploy.ca
|
|
CDN_STORAGE_ZONE: coolify-update
|
|
CDN_PULL_ZONE_ID: "5338895"
|
|
CDN_BASE_URL: https://updates.mapledeploy.ca
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Get version
|
|
id: version
|
|
run: |
|
|
# Reads one version constant out of config/constants.php.
|
|
# The match is anchored at the start of the line, so a nested key on
|
|
# another line (e.g. "'nightly' => ['version' => '5.9.9']") cannot be
|
|
# picked up, and the trailing greedy .* takes the LAST quoted string on
|
|
# the line, so both upstream shapes work:
|
|
# 'version' => '4.2.0',
|
|
# 'version' => env('COOLIFY_VERSION') ?: '4.3.12',
|
|
# Empty or non-version results fail the build instead of tagging the
|
|
# image and versions.json with garbage.
|
|
extract_version() {
|
|
key="$1"
|
|
value=$(sed -n "s/^[[:space:]]*'${key}' => .*'\([^']*\)'.*/\1/p" config/constants.php | head -1)
|
|
if [ -z "$value" ]; then
|
|
echo "ERROR: could not extract '${key}' from config/constants.php" >&2
|
|
grep -n "'${key}' =>" config/constants.php >&2 || true
|
|
exit 1
|
|
fi
|
|
if ! printf '%s' "$value" | grep -Eq '^[0-9]+(\.[0-9]+)+([-.][0-9A-Za-z.]+)?$'; then
|
|
echo "ERROR: extracted ${key} '${value}' does not look like a version." >&2
|
|
echo " The '${key}' entry in config/constants.php probably changed shape;" >&2
|
|
echo " see docs/operations/COOLIFY_FORK.md (How version bumping works)." >&2
|
|
exit 1
|
|
fi
|
|
printf '%s' "$value"
|
|
}
|
|
|
|
# `exit 1` inside the function only leaves the command substitution's
|
|
# subshell, so each call needs its own `|| exit 1`.
|
|
BASE_VERSION=$(extract_version version) || exit 1
|
|
HELPER_VERSION=$(extract_version helper_version) || exit 1
|
|
REALTIME_VERSION=$(extract_version realtime_version) || exit 1
|
|
TIMESTAMP=$(date -u +%Y%m%d%H%M)
|
|
VERSION="${BASE_VERSION}.${TIMESTAMP}"
|
|
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"
|
|
echo "HELPER_VERSION=${HELPER_VERSION}" >> "$GITHUB_OUTPUT"
|
|
echo "REALTIME_VERSION=${REALTIME_VERSION}" >> "$GITHUB_OUTPUT"
|
|
echo "Building version: ${VERSION} (helper: ${HELPER_VERSION}, realtime: ${REALTIME_VERSION})"
|
|
|
|
- name: Login to Forgejo registry
|
|
run: |
|
|
echo "${{ secrets.FORGEJO_TOKEN }}" | docker login ${{ env.REGISTRY }} -u ${{ github.repository_owner }} --password-stdin
|
|
|
|
- name: Build image
|
|
run: |
|
|
DOCKER_BUILDKIT=1 docker build -f docker/production/Dockerfile \
|
|
--build-arg MAPLEDEPLOY_VERSION=${{ steps.version.outputs.VERSION }} \
|
|
-t ${{ env.REGISTRY }}/${{ github.repository }}:${{ steps.version.outputs.VERSION }} \
|
|
-t ${{ env.REGISTRY }}/${{ github.repository }}:latest \
|
|
.
|
|
|
|
- name: Push image
|
|
run: |
|
|
docker push ${{ env.REGISTRY }}/${{ github.repository }}:${{ steps.version.outputs.VERSION }}
|
|
docker push ${{ env.REGISTRY }}/${{ github.repository }}:latest
|
|
|
|
- name: Generate versions.json
|
|
run: |
|
|
cat > versions.json <<EOF
|
|
{
|
|
"coolify": {
|
|
"v4": {
|
|
"version": "${{ steps.version.outputs.VERSION }}"
|
|
},
|
|
"helper": {
|
|
"version": "${{ steps.version.outputs.HELPER_VERSION }}"
|
|
},
|
|
"realtime": {
|
|
"version": "${{ steps.version.outputs.REALTIME_VERSION }}"
|
|
}
|
|
}
|
|
}
|
|
EOF
|
|
echo "Generated versions.json:"
|
|
cat versions.json
|
|
|
|
- name: Install curl
|
|
run: apk add --no-cache curl
|
|
|
|
- name: Upload artifacts to Bunny CDN
|
|
run: |
|
|
STORAGE_URL="https://storage.bunnycdn.com/${{ env.CDN_STORAGE_ZONE }}/coolify"
|
|
|
|
upload() {
|
|
local file="$1"
|
|
local dest="$2"
|
|
echo "Uploading ${file} -> ${dest}"
|
|
curl -fsSL -X PUT "${STORAGE_URL}/${dest}" \
|
|
-H "AccessKey: ${{ secrets.BUNNY_CDN_STORAGE_KEY }}" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
--data-binary @"${file}"
|
|
}
|
|
|
|
upload versions.json versions.json
|
|
upload scripts/upgrade.sh upgrade.sh
|
|
upload scripts/upgrade-postgres.sh upgrade-postgres.sh
|
|
upload docker-compose.yml docker-compose.yml
|
|
upload docker-compose.prod.yml docker-compose.prod.yml
|
|
upload .env.production .env.production
|
|
|
|
echo "All artifacts uploaded."
|
|
|
|
- name: Purge CDN cache
|
|
run: |
|
|
curl -fsSL -X POST "https://api.bunny.net/pullzone/${{ env.CDN_PULL_ZONE_ID }}/purgeCache" \
|
|
-H "AccessKey: ${{ secrets.BUNNY_API_KEY }}" \
|
|
-H "Content-Type: application/json"
|
|
echo "CDN cache purged."
|