Compare commits

..

No commits in common. "95a86b62ef8215e69cb9d838de15b7406c961645" and "ca84c6f04104604aca0ac15ee7473e13c1e46471" have entirely different histories.

2 changed files with 34 additions and 52 deletions

View file

@ -1,54 +1,36 @@
# Forgejo Runner
# README for Docker Image Build and Publish Workflows
The entrypoint script sets up and runs the `forgejo-runner`, including configuring the runner file and managing the registration process. The script supports custom configurations for Forgejo, Docker, and environment variables.
## Overview
It is important to note that using the `command` docker flag will override the entrypoint *by design*, this is to make it compatible with older manual configurations
This repository contains two GitHub Actions workflows that automate the building and publishing of Docker images to an OCI registry.
## Environment Variables
### Workflows
### Required Variables
1. **On Commit to Main**
- **Trigger:** Activates on commits to the `main` branch (tags are excluded).
- **Purpose:** Builds and publishes a Docker image for each commit.
> Only needed during registration of the runner.
> After initial registration the runner operates off of the runner.
- **`FORGEJO_URL`**: The URL of the Forgejo instance. Default: `http://forgejo:3000` Only needed during registration of the runner.
- **`FORGEJO_SECRET`**: Secret used for Forgejo runner creation. Only needed during registration of the runner.
- **`RUNNER_TOKEN`**: Token used for runner registration. Only needed during registration of the runner.
2. **On Tag Push**
- **Trigger:** Activates when a new tag is pushed.
- **Purpose:** Builds and publishes a Docker image for the tag and tags it as `latest`.
## Prerequisites
- **`RUNNER_NAME`** (Optional): Name for the runner. Default: The hostname of the container.
### Optional Configuration Variables
- **`DEBUG`**: Enables debug logging. Default: `false`
- **Secrets Needed:**
- `OCI_TOKEN`: Your OCI registry token.
- `OCI_USER`: Your OCI registry username.
- **`RUNNER_FILE`**: Path to the runner file. Default: `runner.json`
- **`CONFIG_FILE`**: Path to the configuration file. Default: `/data/config.yml`
- **`ENV_FILE`**: Path to the environment file. Default: `/data/.env`
- **`RUNNER_LABELS`**: Labels to attach to the runner. Default:
- `docker:docker://code.forgejo.org/oci/node:20-bookworm`
- `ubuntu-22.04:docker://catthehacker/ubuntu:act-22.04`
## How to Use
- **`DOCKER_HOST`**: Docker host URL. Default: `tcp://docker:2367`
- **`DOCKER_CERT_PATH`**: Path to Docker certificates. Default: `/certs/client`
- **`DOCKER_TLS_VERIFY`**: Whether Docker TLS verification is enabled. Default: `1`
- **`DOCKER_PRIVILEGED`**: Whether to run the container in privileged mode. Default: `false`
- **`MAX_REG_ATTEMPTS`**: Maximum number of registration attempts. Default: `10`
- **`SKIP_WAIT`**: Whether to skip the wait before starting the runner. Default: `false`
1. **Clone the Repository:** Get a local copy of this repository.
2. **Modify Dockerfile:** Update the `Dockerfile` for your application.
3. **Push Changes:** Push changes to the `main` branch or create a new tag.
4. **Check Workflow Status:** View the Actions tab in Forgjo to monitor workflow runs.
## Notes
- The entrypoint will automatically create and configure a `config.yml` file if it does not already exist.
- The runner will attempt to connect to the Forgejo instance and register the runner automatically.
- If `FORGEJO_SECRET` is not provided, the runner will use the `RUNNER_TOKEN` for registration.
- If the registration fails, the script will retry according to the `MAX_REG_ATTEMPTS` value.
## Troubleshooting
- Ensure your Docker environment is compatible with multi-platform builds if necessary.
- **Invalid Configuration**: If the runner does not start, ensure that all required environment variables are set and that the configuration file is valid.
- **Network Issues**: Check your `DOCKER_HOST` and `DOCKER_CERT_PATH` to ensure that Docker is properly configured for secure communication.
## License
This image is distributed under the MIT license. See the LICENSE file for more details.
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

View file

@ -26,8 +26,8 @@ fi
# Handle if `command` is passed, as command appends arguments to the entrypoint
if [ "$#" -gt 0 ]; then
run_command $@
exit
run_command $@
exit
fi
# Handle and alter the config file
@ -99,19 +99,19 @@ if [[ ! -s "${RUNNER_FILE}" ]]; then
while [[ $success -eq 0 ]] && [[ $try -lt ${MAX_REG_ATTEMPTS:-10} ]]; do
if [[ ! -z "${FORGEJO_SECRET}" ]]; then
run_command forgejo-runner create-runner-file --connect \
--instance "${FORGEJO_URL:-http://forgejo:3000}" \
--name "${RUNNER_NAME:-$(hostname)}" \
--secret "${FORGEJO_SECRET}" \
${CONFIG_ARG} \
${EXTRA_ARGS} 2>&1 | tee /tmp/reg.log
--instance "${FORGEJO_URL:-http://forgejo:3000}" \
--name "${RUNNER_NAME:-$(hostname)}" \
--secret "${FORGEJO_SECRET}" \
${CONFIG_ARG}\
${EXTRA_ARGS} 2>&1 | tee /tmp/reg.log
else
run_command forgejo-runner register \
--instance "${FORGEJO_URL:-http://forgejo:3000}" \
--name "${RUNNER_NAME:-$(hostname)}" \
--token "${RUNNER_TOKEN}" \
--no-interactive \
${CONFIG_ARG} \
${EXTRA_ARGS} 2>&1 | tee /tmp/reg.log
--instance "${FORGEJO_URL:-http://forgejo:3000}" \
--name "${RUNNER_NAME:-$(hostname)}" \
--token "${RUNNER_TOKEN}" \
--no-interactive \
${CONFIG_ARG}\
${EXTRA_ARGS} 2>&1 | tee /tmp/reg.log
fi
cat /tmp/reg.log | grep -E 'connection successful|registered successfully' >/dev/null
if [[ $? -eq 0 ]]; then