Files
homelab/.github/workflows/deploy-production.yaml
Julia McGhee e13a008860 Copy root pnpm-lock.yaml into app context for Docker builds
Each app's Dockerfile expects a lockfile but docker build context is
scoped to the app directory. Copy it in before build, remove after.
2026-03-20 19:46:34 +00:00

67 lines
2.4 KiB
YAML

name: Deploy Production
on:
push:
branches: [main]
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Determine changed apps
id: changes
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
APPS="web,api"
else
APPS=$(pnpm turbo build --filter='...[HEAD~1]' --dry-run=json | jq -r '[.packages[] | select(startswith("@homelab/")) | sub("@homelab/";"") ] | join(",")')
fi
echo "apps=$APPS" >> "$GITHUB_OUTPUT"
- name: Build and push images
if: steps.changes.outputs.apps != ''
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
IFS=',' read -ra APPS <<< "${{ steps.changes.outputs.apps }}"
for app in "${APPS[@]}"; do
cp pnpm-lock.yaml apps/${app}/pnpm-lock.yaml
docker build \
-t ghcr.io/${{ github.repository_owner }}/homelab-${app}:${{ github.sha }} \
-t ghcr.io/${{ github.repository_owner }}/homelab-${app}:latest \
apps/${app}
rm apps/${app}/pnpm-lock.yaml
docker push ghcr.io/${{ github.repository_owner }}/homelab-${app}:${{ github.sha }}
docker push ghcr.io/${{ github.repository_owner }}/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 ghcr.io/${{ github.repository_owner }}/homelab-${app}=ghcr.io/${{ github.repository_owner }}/homelab-${app}:${{ github.sha }}
cd -
done
- name: Commit image tag updates
if: steps.changes.outputs.apps != ''
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add apps/*/k8s/overlays/production/
git diff --staged --quiet || git commit -m "deploy: update production images to ${{ github.sha }}"
git push