77 lines
2.3 KiB
YAML
77 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
|
|
container:
|
|
image: bitnami/kubectl:1.31
|
|
steps:
|
|
- name: Checkout
|
|
env:
|
|
TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
|
run: |
|
|
cd /tmp && git clone --depth=1 "https://djohn:${TOKEN}@code.core.ci/${{ github.repository }}.git" repo
|
|
- name: Deploy
|
|
env:
|
|
KUBECONFIG_DATA: ${{ secrets.KUBE_CONFIG }}
|
|
run: |
|
|
echo "$KUBECONFIG_DATA" | base64 -d > /tmp/kubeconfig
|
|
export KUBECONFIG=/tmp/kubeconfig
|
|
cd /tmp/repo/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
|