From a31df71d2b064b9b4bf0bc9e3f1a1cd10076944b Mon Sep 17 00:00:00 2001 From: pika Date: Sat, 12 Apr 2025 12:46:33 +0200 Subject: [PATCH] batman --- .forgejo/workflows/build-and-push.yml | 29 +++++++++++++ Dockerfile | 10 +++++ README.md | 62 +++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 .forgejo/workflows/build-and-push.yml create mode 100644 Dockerfile create mode 100644 README.md diff --git a/.forgejo/workflows/build-and-push.yml b/.forgejo/workflows/build-and-push.yml new file mode 100644 index 0000000..0711b21 --- /dev/null +++ b/.forgejo/workflows/build-and-push.yml @@ -0,0 +1,29 @@ +name: Build and Push to Forgejo Registry + +on: + push: + branches: [main] + paths: + - '**/Dockerfile' + - '**/build-and-push.yml' + # schedule: + # - cron: "0 0 * * 0" # Weekly at 00:00 UTC Sunday + +jobs: + checkout: + runs-on: self-hosted + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Login to registry + uses: docker/login-actions@v3 + with: + registry: ${{ vars.FORGEJO_URL }} + username: ${{ vars.FORGEJO_USERNAME }} + password: ${{ secrets.FORGEJO_PACKAGE_TOKEN }} + + - name: Build 'n Push + run: | + docker build -t git.k4li.de/docker/forgejo-runner:latest . + docker push git.k4li.de/docker/forgejo-runner:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..90e2ec4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM ghcr.io/catthehacker/ubuntu:act-22.04 + +RUN export RUNNER_VERSION=$(curl -X 'GET' https://data.forgejo.org/api/v1/repos/forgejo/runner/releases/latest | jq .name -r | cut -c 2-) && wget -O forgejo-runner https://code.forgejo.org/forgejo/runner/releases/download/v${RUNNER_VERSION}/forgejo-runner-${RUNNER_VERSION}-linux-amd64 && chmod +x forgejo-runner && mv forgejo-runner /usr/bin/ + +RUN useradd --create-home runner && usermod -aG docker runner + +USER runner +WORKDIR /home/runner + +CMD ["forgejo-runner", "daemon"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..3b88818 --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +## Forgejo-Runner + +This is a minor modifyed version of `ghcr.io/catthehacker/ubuntu:act-22.04`. It houses the forgejo-runner binary and executes it on startup with "daemon". + +This runner needs dind to execute docker commands in a secured environment. + +```yaml +services: + docker-in-docker: + image: docker:dind + container_name: "docker_dind" + hostname: docker + privileged: "true" + command: ["dockerd", "-H", "tcp://0.0.0.0:2375", "--tls=false"] + restart: "unless-stopped" + + pika-runner: + image: pika-runner:latest + depends_on: + - docker-in-docker + environment: + DOCKER_HOST: "tcp://docker:2375" + volumes: + - ./config:/home/runner +``` + +Now run `docker compose run --rm pika-runner forgejo-runner register` + +You should be asked to input your forgejo url like `https://git.k4li.de/`, your runner token, which you aquire in admin mode when adding runners. Then it askes for the label to use. In my case, this label works perfectly fine for me `self-hosted:host://-self-hosted` + +After this, you can successfully build docker images, and use almost every github actions workflow you like. INSIDE DOCKER!! + +example workflow that works: + +> [!INFO] +> This is my workflow to push my modifyed caddy container to my registry + +```yaml workflow.yml +name: Build and Push to Forgejo Registry + +on: + push: + branches: [main] + +jobs: + checkout: + runs-on: self-hosted + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Login to Forgejo Container Registry + uses: docker/login-action@v3 + with: + registry: git.k4li.de + username: ${{ vars.FORGEJO_USERNAME }} + password: ${{ vars.FORGEJO_PASSWORD }} + - name: Build n Push + run: | + docker build -t git.k4li.de/docker/caddy:latest . + docker push git.k4li.de/docker/caddy:latest +```