86 lines
2.8 KiB
YAML
86 lines
2.8 KiB
YAML
name: Build & Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
env:
|
|
REGISTRY: 192.168.1.212:1180/library
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Install build tools
|
|
run: |
|
|
apk add --no-cache curl git nodejs npm docker-cli 2>/dev/null || true
|
|
|
|
- name: Generate demo content + Dockerfile
|
|
run: |
|
|
WORK=/root/.cache/demo-frontend
|
|
rm -rf "$WORK"
|
|
mkdir -p "$WORK"
|
|
cd "$WORK"
|
|
git clone http://joe:${GITEA_TOKEN}@192.168.1.212:3000/joe/demo-frontend.git .
|
|
|
|
SHORT_SHA=${GITHUB_SHA::8}
|
|
cat > package.json <<EOF
|
|
{
|
|
"name": "demo-frontend",
|
|
"version": "1.0.0",
|
|
"scripts": {"build": "mkdir -p dist && echo '<html><body style=\"font-family:sans-serif;padding:40px;text-align:center\"><h1>Demo Frontend</h1><p>Build: ${SHORT_SHA}</p><p>Commit: ${GITHUB_SHA}</p><p>Time: $(date)</p></body></html>' > dist/index.html && echo 'OK' > dist/healthz"}
|
|
}
|
|
EOF
|
|
|
|
cat > Dockerfile <<EOF
|
|
FROM nginx:alpine
|
|
COPY dist/ /usr/share/nginx/html/
|
|
EXPOSE 80
|
|
HEALTHCHECK --interval=30s --timeout=3s CMD wget -q -O- http://localhost/healthz || exit 1
|
|
EOF
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
GITHUB_SHA: ${{ github.sha }}
|
|
|
|
- name: Build frontend
|
|
run: |
|
|
cd /root/.cache/demo-frontend
|
|
npm install --silent
|
|
npm run build
|
|
env:
|
|
GITHUB_SHA: ${{ github.sha }}
|
|
|
|
- name: Login to Harbor
|
|
run: docker login 192.168.1.212:1180 -u admin -p "$HARBOR_PASSWORD"
|
|
env:
|
|
HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }}
|
|
|
|
- name: Docker build & push
|
|
run: |
|
|
cd /root/.cache/demo-frontend
|
|
SHORT=${GITHUB_SHA::8}
|
|
TAG="${REGISTRY}/demo-frontend:${SHORT}"
|
|
LATEST="${REGISTRY}/demo-frontend:latest"
|
|
docker build -t "${TAG}" -t "${LATEST}" .
|
|
docker push "${TAG}"
|
|
docker push "${LATEST}"
|
|
echo "✓ Pushed ${TAG}"
|
|
env:
|
|
GITHUB_SHA: ${{ github.sha }}
|
|
REGISTRY: ${{ env.REGISTRY }}
|
|
|
|
- name: Update image tag in values.yaml (commit-back GitOps)
|
|
run: |
|
|
cd /root/.cache/demo-frontend
|
|
SHORT=${GITHUB_SHA::8}
|
|
sed -i "s/^ tag:.*/ tag: \"${SHORT}\"/" deploy/helm/values.yaml
|
|
git config user.email "ci@local"
|
|
git config user.name "gitea-ci"
|
|
git add deploy/helm/values.yaml
|
|
git commit -m "ci: update image tag to ${SHORT}" || echo "nothing to commit"
|
|
git push origin main
|
|
echo "✓ Pushed tag ${SHORT}"
|
|
env:
|
|
GITHUB_SHA: ${{ github.sha }}
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|