From 730e0e2defe4d2210d11961a2bc55567886e0207 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Tue, 27 Dec 2022 19:30:29 +0100 Subject: [PATCH] Update documentation --- .gitignore | 3 +-- Containerfile | 3 --- README.md | 63 ++++++++++++-------------------------------- compose.yaml | 13 +++++++++ template_config.yaml | 59 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 51 deletions(-) create mode 100644 compose.yaml create mode 100644 template_config.yaml diff --git a/.gitignore b/.gitignore index df694cb..964d7bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ /Cargo.lock +config.yaml /dev_data/ -*.json *.log /scripts/ /target/ -*.yaml diff --git a/Containerfile b/Containerfile index ed5364f..54c5bcb 100644 --- a/Containerfile +++ b/Containerfile @@ -16,9 +16,6 @@ RUN cargo build --release --bin git-webhook-client FROM docker.io/library/debian:stable-slim AS runtime WORKDIR app -ARG data_dir=/volumes/data -ENV DATABASE_URL=$data_dir/db/db.sqlite -ENV GWC_CONFIG_FILE=$data_dir/config.yaml RUN apt update && \ apt install libsqlite3-dev -y COPY --from=builder /app/target/release/git-webhook-client /usr/local/bin/git-webhook-client diff --git a/README.md b/README.md index de586d0..07b2b31 100644 --- a/README.md +++ b/README.md @@ -9,70 +9,41 @@ Currently, only Gitea is supported. If you want support for Gitlab or Github, th - Verify the webhook event with a secret. - Run a configured command to a specific repository on a webhook event. - Save the output of the command. -- Show an output by visiting the url of the client. -- Supported configuration for multiple repositories. +- Show an output by visiting its URL. +- Send email after a webhook trigger. +- Support configuration for multiple repositories. - Written in Rust :D ## Getting started -### Requirements - -- `cargo` to compile the source code. -- Development package for SQLite (`sqlite-devel` on Fedora) +First, clone the repository and create the configuration file (see below). ### Configuration -The program looks for the configuration file configured with the environment variable `GWC_CONFIG_FILE` that contains the following: +The program looks for the configuration file set with the environment variable `GWC_CONFIG_FILE`. - +Use the commented template configuration file `template_config.yaml` as a starting point. -1. `secret`: The secret of the webhook. -1. `base_url`: The base_url of the webhook client. -1. `hooks`: List of webhooks. -1. `clone_url`: Repository url. -1. `current_dir`: The directory to run the command in. -1. `command`: The command without any arguments. -1. `args`: List of arguments separated by a comma. +### Running -#### Example configuration file: +#### Containerized - +With Docker or Podman, use the compose file `compose.yaml` as a starting point. -```yaml -secret: CHANGE_ME! -base_url: https://webhook.mo8it.com +#### Not containerized -hooks: - clone_url: https://codeberg.org/Mo8it/git-webhook-client - current_dir: . - command: ls - args: ["-l", "-a", "test_directory"] -``` +Requirements: -#### First setup +- `cargo` to compile the source code. +- Development package for SQLite (`sqlite-devel` on Fedora, `libsqlite3-dev` on Debian) - +Run the command `cargo install --path .` to compile. -- Clone the repository. -- Create the configuration file. -- Run the following to initialize the database: - ```bash - cargo install diesel_cli --no-default-features --features sqlite - DATABASE_URL=PATH/TO/DATABASE/DIRECTORY/db.sqlite diesel_cli migration run - cargo build --release - ``` - -#### Run - -After running `cargo build --release`, the binary can be found in the directory `target/release/git-webhook-client`. To run it, you have to specify the environment variable `DATABASE_URL`: - -```bash -DATABASE_URL=PATH/TO/DATABASE/DIRECTORY/db.sqlite target/release/git-webhook-client -``` +Run the command `GWC_CONFIG_FILE=/path/to/config.yaml ~/.cargo/bin/git-webhook-client` to start the client. #### Setup on the git server -Setup the webhook for the configured repositories on the git server. Don't forget to enter the same secret that you did specify in the configuration file. +Setup the webhook for the configured repositories on the git server. Don't forget to enter the same secret that you did specify in the YAML configuration file. #### Show output @@ -80,7 +51,7 @@ After an event, the client responds with a URL that shows the log. The id in tha If you want to see the last log, just visit the `base_url` from the configuration. -To see a specific log with an id, visit the URL: `base_url/?id=THE_ID_OF_AN_EVENT`. +To see a specific log with an id, visit the URL: `base_url/?id=THE_ID_OF_THE_EVENT`. You can specify a negative ID to see the last events. `id=-1` corresponds to the last log, `id=-2` corresponds to the log before it and so on. diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..3fbd754 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,13 @@ +--- + +services: + gwc: + container_name: git-webhook-client + build: + context: . + dockerfile: Containerfile + restart: unless-stopped + volumes: + - ./data:/volumes/data:Z + environment: + - GWC_CONFIG_FILE=/volumes/data/config.yaml diff --git a/template_config.yaml b/template_config.yaml new file mode 100644 index 0000000..9100cdb --- /dev/null +++ b/template_config.yaml @@ -0,0 +1,59 @@ +--- + +# The secret of the webhook +secret: CHANGE_ME! + +# The base URL of the webhook client +base_url: https://webhook.mo8it.com + +# SQLite database path +sqlite_db_path: /path/to/db.sqlite + +socket_address: + # IP address to bind to. + # Change to [127, 0, 0, 1] if you want to run the client locally. + address: [0, 0, 0, 0] + # Port to bind to + port: 8080 + +# Email server connection +email_server: + server_name: posteo.de + email: change_me@posteo.net + password: EMAIL_PASSWORD + +# Email FROM +email_from: + name: Webhook + user: change_me + domain: posteo.net + +# Email TO +email_to: + name: Me + user: me + domain: proton.me + +logging: + # Log file directory + directory: /path/to/log/dir + # Log file name + filename: log.txt + +# List of webhooks +hooks: + - # Name shown in email subject + name: GWC + # Repository clone URL + clone_url: https://codeberg.org/Mo8it/git-webhook-client.git + # The directory to run the command in + current_dir: /volumes/scripts + # The command to run without any args + command: ls + # List of args for the command + args: ["-l", "-a", "old_scripts"] + - name: AdvLabDB + clone_url: https://codeberg.org/Mo8it/advlabdb.git + current_dir: /volumes/advlabdb/scripts + command: ./backup.sh + args: []