Add Gitea self-hosted git/CI/registry to replace GitHub
Deploy Gitea via Helm with dedicated CloudNativePG database, in-cluster Actions runner (DinD), and built-in container registry. ArgoCD repoURLs updated to use in-cluster Gitea SSH. Preview ApplicationSet switched from GitHub PR generator to Gitea PR generator. App images now pull from gitea.coreworlds.io registry. Remaining setup after deploy: seal runner token, ArgoCD API token, and registry pull secret once Gitea is running. Add ArgoCD deploy key to Gitea repo settings.
This commit is contained in:
87
.gitea/workflows/ci.yaml
Normal file
87
.gitea/workflows/ci.yaml
Normal file
@@ -0,0 +1,87 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
concurrency:
|
||||
group: ${{ gitea.workflow }}-${{ gitea.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
changes:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
apps: ${{ steps.filter.outputs.apps }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Detect changed apps
|
||||
id: filter
|
||||
run: |
|
||||
if [ "${{ gitea.event_name }}" = "pull_request" ]; then
|
||||
CHANGED=$(git diff --name-only origin/main...HEAD)
|
||||
else
|
||||
CHANGED=$(git diff --name-only HEAD~1)
|
||||
fi
|
||||
APPS="[]"
|
||||
for app in web api harness; do
|
||||
if echo "$CHANGED" | grep -qE "^(apps/${app}/|packages/)"; then
|
||||
APPS=$(echo "$APPS" | jq -c ". + [\"${app}\"]")
|
||||
fi
|
||||
done
|
||||
echo "apps=$APPS" >> "$GITHUB_OUTPUT"
|
||||
|
||||
lint-and-test:
|
||||
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
|
||||
|
||||
- run: pnpm turbo lint test
|
||||
|
||||
build:
|
||||
needs: [changes, lint-and-test]
|
||||
runs-on: ubuntu-latest
|
||||
if: needs.changes.outputs.apps != '[]'
|
||||
strategy:
|
||||
matrix:
|
||||
app: ${{ fromJson(needs.changes.outputs.apps) }}
|
||||
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
|
||||
|
||||
- run: pnpm turbo build --filter=@homelab/${{ matrix.app }}
|
||||
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
docker build \
|
||||
-t gitea.coreworlds.io/julia/homelab-${{ matrix.app }}:${{ gitea.sha }} \
|
||||
-t gitea.coreworlds.io/julia/homelab-${{ matrix.app }}:pr-${{ gitea.event.number }} \
|
||||
apps/${{ matrix.app }}
|
||||
|
||||
- name: Push to registry
|
||||
if: gitea.event_name == 'push' || gitea.event_name == 'pull_request'
|
||||
run: |
|
||||
echo "${{ secrets.GITEA_TOKEN }}" | docker login gitea.coreworlds.io -u ${{ gitea.actor }} --password-stdin
|
||||
docker push gitea.coreworlds.io/julia/homelab-${{ matrix.app }}:${{ gitea.sha }}
|
||||
64
.gitea/workflows/deploy-preview.yaml
Normal file
64
.gitea/workflows/deploy-preview.yaml
Normal file
@@ -0,0 +1,64 @@
|
||||
name: Deploy Preview
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
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: |
|
||||
APPS=$(pnpm turbo build --filter='...[origin/main]' --dry-run=json | jq -r '[.packages[] | select(startswith("@homelab/")) | sub("@homelab/";"") ] | join(",")')
|
||||
echo "apps=$APPS" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build and push images
|
||||
if: steps.changes.outputs.apps != ''
|
||||
run: |
|
||||
echo "${{ secrets.GITEA_TOKEN }}" | docker login gitea.coreworlds.io -u ${{ gitea.actor }} --password-stdin
|
||||
IFS=',' read -ra APPS <<< "${{ steps.changes.outputs.apps }}"
|
||||
for app in "${APPS[@]}"; do
|
||||
docker build \
|
||||
-t gitea.coreworlds.io/julia/homelab-${app}:${{ gitea.sha }} \
|
||||
apps/${app}
|
||||
docker push gitea.coreworlds.io/julia/homelab-${app}:${{ gitea.sha }}
|
||||
done
|
||||
|
||||
- name: Update image tags in preview 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/preview
|
||||
kustomize edit set image gitea.coreworlds.io/julia/homelab-${app}=gitea.coreworlds.io/julia/homelab-${app}:${{ gitea.sha }}
|
||||
cd -
|
||||
done
|
||||
|
||||
- name: Comment preview URL
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { owner, repo } = context.repo;
|
||||
const issue_number = context.issue.number;
|
||||
const body = `## Preview Deploy\nNamespace: \`preview-${issue_number}\`\nArgoCD will sync automatically from branch \`${context.payload.pull_request.head.ref}\`.`;
|
||||
await fetch(`${process.env.GITHUB_API_URL}/repos/${owner}/${repo}/issues/${issue_number}/comments`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `token ${process.env.GITHUB_TOKEN}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ body })
|
||||
});
|
||||
59
.gitea/workflows/deploy-production.yaml
Normal file
59
.gitea/workflows/deploy-production.yaml
Normal file
@@ -0,0 +1,59 @@
|
||||
name: Deploy Production
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
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: |
|
||||
APPS=$(pnpm turbo build --filter='...[HEAD~1]' --dry-run=json | jq -r '[.packages[] | select(startswith("@homelab/")) | sub("@homelab/";"") ] | join(",")')
|
||||
echo "apps=$APPS" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build and push images
|
||||
if: steps.changes.outputs.apps != ''
|
||||
run: |
|
||||
echo "${{ secrets.GITEA_TOKEN }}" | docker login gitea.coreworlds.io -u ${{ gitea.actor }} --password-stdin
|
||||
IFS=',' read -ra APPS <<< "${{ steps.changes.outputs.apps }}"
|
||||
for app in "${APPS[@]}"; do
|
||||
docker build \
|
||||
-t gitea.coreworlds.io/julia/homelab-${app}:${{ gitea.sha }} \
|
||||
-t gitea.coreworlds.io/julia/homelab-${app}:latest \
|
||||
apps/${app}
|
||||
docker push gitea.coreworlds.io/julia/homelab-${app}:${{ gitea.sha }}
|
||||
docker push gitea.coreworlds.io/julia/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/julia/homelab-${app}=gitea.coreworlds.io/julia/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
|
||||
Reference in New Issue
Block a user