Publish runner image to Gitea Container Registry
This commit is contained in:
73
.gitea/workflows/build-runner-image.yml
Normal file
73
.gitea/workflows/build-runner-image.yml
Normal file
@@ -0,0 +1,73 @@
|
||||
name: Build runner image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- runner-image/**
|
||||
- .gitea/workflows/build-runner-image.yml
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: node:20-bookworm
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: https://gitea.com/actions/checkout@v4
|
||||
|
||||
- name: Install Docker client
|
||||
run: |
|
||||
set -eu
|
||||
for attempt in 1 2 3; do
|
||||
if apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
||||
--no-install-recommends docker.io; then
|
||||
break
|
||||
fi
|
||||
if [ "$attempt" -eq 3 ]; then
|
||||
echo "Unable to install the Docker client after 3 attempts"
|
||||
exit 1
|
||||
fi
|
||||
sleep "$((attempt * 5))"
|
||||
done
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
docker version --format 'Docker client {{.Client.Version}}, server {{.Server.Version}}'
|
||||
|
||||
- name: Build, verify, and publish image
|
||||
env:
|
||||
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
run: |
|
||||
set -eu
|
||||
registry="mahgit.ir"
|
||||
image="$registry/meghdadfadaee/daily-blackout-check-runner"
|
||||
revision="$(git rev-parse --short=12 HEAD)"
|
||||
candidate="$image:$revision"
|
||||
|
||||
cleanup() {
|
||||
docker logout "$registry" >/dev/null 2>&1 || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
printf '%s' "$REGISTRY_TOKEN" | docker login "$registry" \
|
||||
--username "$REGISTRY_USERNAME" \
|
||||
--password-stdin
|
||||
|
||||
docker build \
|
||||
--pull \
|
||||
--label "org.opencontainers.image.revision=$revision" \
|
||||
--label "org.opencontainers.image.source=https://mahgit.ir/MeghdadFadaee/daily-blackout-check" \
|
||||
--tag "$candidate" \
|
||||
runner-image
|
||||
|
||||
docker run --rm "$candidate" python -c "import dotenv, jdatetime, requests"
|
||||
docker run --rm "$candidate" pytest --version
|
||||
docker run --rm "$candidate" ruff --version
|
||||
|
||||
docker push "$candidate"
|
||||
docker tag "$candidate" "$image:latest"
|
||||
docker push "$image:latest"
|
||||
@@ -9,7 +9,10 @@ jobs:
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: daily-blackout-check-runner:latest
|
||||
image: mahgit.ir/meghdadfadaee/daily-blackout-check-runner:latest
|
||||
credentials:
|
||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
env:
|
||||
PYTHONPATH: src
|
||||
steps:
|
||||
|
||||
@@ -11,7 +11,10 @@ jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: daily-blackout-check-runner:latest
|
||||
image: mahgit.ir/meghdadfadaee/daily-blackout-check-runner:latest
|
||||
credentials:
|
||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
env:
|
||||
PYTHONPATH: src
|
||||
steps:
|
||||
|
||||
Reference in New Issue
Block a user