bcc74328d6
Build & Push Docker Image / build (push) Successful in 2m28s
On tag push (vX.Y.Z) the image is additionally pushed as IMAGE:vX.Y.Z; sha-... and latest tags stay as-is and the k8s manifest keeps using sha-...
58 lines
2.0 KiB
YAML
58 lines
2.0 KiB
YAML
name: Build & Push Docker Image
|
|
run-name: Build ${{ gitea.ref_name }}
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
tags: ["v*"]
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
DOCKER_HOST: tcp://172.17.0.1:2375
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Install Docker CLI
|
|
run: |
|
|
apt-get update -qq
|
|
apt-get install -y -qq docker.io
|
|
docker version
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.kubebase.de -u ${{ secrets.REGISTRY_USER }} --password-stdin
|
|
|
|
- name: Build and push
|
|
run: |
|
|
SHA=$(git rev-parse --short HEAD)
|
|
FULL_SHA=$(git rev-parse HEAD)
|
|
IMAGE="git.kubebase.de/${{ gitea.repository }}"
|
|
if [ "${{ gitea.ref_type }}" = "tag" ]; then VERSION="${{ gitea.ref_name }}"; else VERSION=""; fi
|
|
TAGS="-t ${IMAGE}:sha-${SHA} -t ${IMAGE}:latest"
|
|
if [ -n "$VERSION" ]; then TAGS="${TAGS} -t ${IMAGE}:${VERSION}"; fi
|
|
docker build --no-cache \
|
|
--build-arg COMMIT_SHA="$FULL_SHA" \
|
|
--build-arg BUILD_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
|
|
--build-arg VERSION="$VERSION" \
|
|
$TAGS .
|
|
docker push "${IMAGE}:sha-${SHA}"
|
|
docker push "${IMAGE}:latest"
|
|
if [ -n "$VERSION" ]; then docker push "${IMAGE}:${VERSION}"; fi
|
|
|
|
- name: Update k8s manifest in admin/apps
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
|
run: |
|
|
SHA=$(git rev-parse --short HEAD)
|
|
git clone "https://admin:${GITEA_TOKEN}@git.kubebase.de/admin/apps.git" /tmp/apps
|
|
cd /tmp/apps
|
|
cd apps/system/toolrate/overlays/k3s
|
|
sed -i "s|newTag: .*|newTag: sha-${SHA}|" kustomization.yaml
|
|
git config user.name "Gitea Actions"
|
|
git config user.email "actions@git.kubebase.de"
|
|
git add -A
|
|
git diff --cached --quiet || git commit -m "chore: update toolrate image to sha-${SHA}"
|
|
git push
|