books/.forgejo/workflows/ci.yml
Djohn 0d353037c2
Some checks failed
books / docker (push) Successful in 8s
books / deploy (push) Failing after 3s
fix: use ubuntu runner for deploy (has git)
2026-02-07 11:05:53 +01:00

78 lines
2.3 KiB
YAML

# books
name: books
on:
push:
branches: [main]
pull_request:
env:
REGISTRY: code.core.ci/softwarehuset
IMAGES: |
./Dockerfile|books|.
jobs:
docker:
name: docker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to registry
run: echo "${{ secrets.FORGEJO_TOKEN }}" | docker login code.core.ci -u djohn --password-stdin
- name: Build & Push images
run: |
set -e
if [ "${{ github.event_name }}" = "pull_request" ]; then
TAG="pr-${{ github.event.number }}"
else
TAG="${{ github.sha }}"
fi
IS_MAIN="${{ github.ref == 'refs/heads/main' }}"
echo "${{ env.IMAGES }}" | grep -v '^[[:space:]]*$' | while IFS='|' read -r dockerfile image context; do
dockerfile=$(echo "$dockerfile" | xargs)
image=$(echo "$image" | xargs)
context=$(echo "$context" | xargs)
[ -z "$dockerfile" ] && continue
FULL_IMAGE="${{ env.REGISTRY }}/${image}"
echo "🐳 Building: ${FULL_IMAGE}:${TAG}"
docker build -f "${dockerfile}" -t "${FULL_IMAGE}:${TAG}" "${context}"
docker push "${FULL_IMAGE}:${TAG}"
if [ "$IS_MAIN" = "true" ]; then
docker tag "${FULL_IMAGE}:${TAG}" "${FULL_IMAGE}:latest"
docker push "${FULL_IMAGE}:latest"
fi
done
deploy:
name: deploy
needs: [docker]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/v1.31.0/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
- name: Deploy
env:
KUBECONFIG_DATA: ${{ secrets.KUBE_CONFIG }}
run: |
echo "$KUBECONFIG_DATA" | base64 -d > /tmp/kubeconfig
export KUBECONFIG=/tmp/kubeconfig
cd k8s/prod
kubectl kustomize . | kubectl apply -f -
kubectl -n books set image deployment/books web=${{ env.REGISTRY }}/books:${{ github.sha }}
kubectl -n books rollout status deployment/books --timeout=120s