The Dockerfile check in the while-read loop used `[ -f ... ] && echo`, which exits non-zero for packages without Dockerfiles. With bash's pipefail, this killed the entire step. Also remove unused GitHub workflow copies since CI runs on Gitea only.
81 lines
3.0 KiB
YAML
81 lines
3.0 KiB
YAML
name: Deploy Production
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
inputs:
|
|
apps:
|
|
description: "Comma-separated app names to build (leave empty for all)"
|
|
required: false
|
|
default: ""
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 2
|
|
|
|
- name: Setup and install
|
|
run: |
|
|
export COREPACK_HOME=/pnpm-store/.corepack
|
|
corepack enable && corepack prepare pnpm@latest --activate
|
|
export PNPM_STORE_DIR=/pnpm-store
|
|
pnpm install --frozen-lockfile
|
|
|
|
- name: Determine changed apps
|
|
id: changes
|
|
run: |
|
|
if [ "${{ gitea.event_name }}" = "workflow_dispatch" ]; then
|
|
INPUT="${{ gitea.event.inputs.apps }}"
|
|
if [ -z "$INPUT" ]; then
|
|
APPS="web,api,harness"
|
|
else
|
|
APPS="$INPUT"
|
|
fi
|
|
else
|
|
APPS=$(pnpm turbo build --filter='...[HEAD~1]' --dry-run=json | jq -r '[.packages[] | select(startswith("@homelab/")) | sub("@homelab/";"") ] | join(",")' | tr ',' '\n' | while read app; do if [ -f "apps/${app}/Dockerfile" ]; then echo "$app"; fi; done | paste -sd, -)
|
|
fi
|
|
echo "apps=$APPS" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build and push images
|
|
if: steps.changes.outputs.apps != ''
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login gitea.coreworlds.io -u lazorgurl --password-stdin
|
|
IFS=',' read -ra APPS <<< "${{ steps.changes.outputs.apps }}"
|
|
for app in "${APPS[@]}"; do
|
|
if [ -f "apps/${app}/.dockercontext" ]; then
|
|
CONTEXT="."
|
|
else
|
|
CONTEXT="apps/${app}"
|
|
fi
|
|
docker build \
|
|
-t gitea.coreworlds.io/lazorgurl/homelab-${app}:${{ gitea.sha }} \
|
|
-t gitea.coreworlds.io/lazorgurl/homelab-${app}:latest \
|
|
-f apps/${app}/Dockerfile \
|
|
$CONTEXT
|
|
docker push gitea.coreworlds.io/lazorgurl/homelab-${app}:${{ gitea.sha }}
|
|
docker push gitea.coreworlds.io/lazorgurl/homelab-${app}:latest
|
|
done
|
|
|
|
- name: Update image tags in production overlay
|
|
if: steps.changes.outputs.apps != ''
|
|
run: |
|
|
IFS=',' read -ra APPS <<< "${{ steps.changes.outputs.apps }}"
|
|
for app in "${APPS[@]}"; do
|
|
cd apps/${app}/k8s/overlays/production
|
|
kustomize edit set image gitea.coreworlds.io/lazorgurl/homelab-${app}=gitea.coreworlds.io/lazorgurl/homelab-${app}:${{ gitea.sha }}
|
|
cd -
|
|
done
|
|
|
|
- name: Commit image tag updates
|
|
if: steps.changes.outputs.apps != ''
|
|
run: |
|
|
git config user.name "gitea-actions[bot]"
|
|
git config user.email "gitea-actions[bot]@coreworlds.io"
|
|
git add apps/*/k8s/overlays/production/
|
|
git diff --staged --quiet || git commit -m "deploy: update production images to ${{ gitea.sha }}"
|
|
git push
|