From c3307af0ec8338a7535b1f8a95ff279f91255560 Mon Sep 17 00:00:00 2001 From: Roberto Bochet Date: Mon, 4 Nov 2024 16:24:05 +0100 Subject: [PATCH 1/3] Allow to run as job --- docker-entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 05d04e0..9ff0692 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -10,6 +10,8 @@ do echo "Starting to create mirrors..." node /app/dist/index.js + if [ $DELAY -eq 0 ]; then break; fi + echo "Waiting for ${DELAY} seconds..." sleep "${DELAY}" done From 08935e4dbf8d86e7afdc0226003b344022046767 Mon Sep 17 00:00:00 2001 From: Roberto Bochet Date: Mon, 4 Nov 2024 16:26:13 +0100 Subject: [PATCH 2/3] Update README.md --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b0f2ae1..0a4b17f 100644 --- a/README.md +++ b/README.md @@ -34,18 +34,18 @@ private repos, they will be created as private repos on your gitea server. All configuration is performed through environment variables. Flags are considered `true` on `true`, `TRUE` or `1`. -| Parameter | Required | Type | Default | Description | -|-----------------------------|----------|--------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| GITHUB_USERNAME | yes | string | - | The name of the GitHub user or organisation to mirror. | -| GITEA_URL | yes | string | - | The url of your Gitea server. | -| GITEA_TOKEN | yes | string | - | The token for your gitea user (Settings -> Applications -> Generate New Token). **Attention: if this is set, the token will be transmitted to your specified Gitea instance!** | -| GITHUB_TOKEN | no* | string | - | GitHub token (PAT). Is mandatory in combination with `MIRROR_PRIVATE_REPOSITORIES`. | -| MIRROR_PRIVATE_REPOSITORIES | no | bool | FALSE | If set to `true` your private GitHub Repositories will be mirrored to Gitea. Requires `GITHUB_TOKEN`. | -| SKIP_FORKS | no | bool | FALSE | If set to `true` will disable the mirroring of forks from your GitHub User / Organisation. | -| DELAY | no | int | 3600 | Number of seconds between program executions. Setting this will only affect how soon after a new repo was created a mirror may appar on Gitea, but has no affect on the ongoing replication. | -| DRY_RUN | no | bool | FALSE | If set to `true` will perform no writing changes to your Gitea instance, but log the planned actions. | -| INCLUDE | no | string | "*" | Name based repository filter (include): If any filter matches, the repository will be mirrored. It supports glob format, multiple filters can be separated with commas (`,`) | -| EXCLUDE | no | string | "" | Name based repository filter (exclude). If any filter matches, the repository will not be mirrored. It supports glob format, multiple filters can be separated with commas (`,`). `EXCLUDE` filters are applied after `INCLUDE` ones. | +| Parameter | Required | Type | Default | Description | +|-----------------------------|----------|--------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| GITHUB_USERNAME | yes | string | - | The name of the GitHub user or organisation to mirror. | +| GITEA_URL | yes | string | - | The url of your Gitea server. | +| GITEA_TOKEN | yes | string | - | The token for your gitea user (Settings -> Applications -> Generate New Token). **Attention: if this is set, the token will be transmitted to your specified Gitea instance!** | +| GITHUB_TOKEN | no* | string | - | GitHub token (PAT). Is mandatory in combination with `MIRROR_PRIVATE_REPOSITORIES`. | +| MIRROR_PRIVATE_REPOSITORIES | no | bool | FALSE | If set to `true` your private GitHub Repositories will be mirrored to Gitea. Requires `GITHUB_TOKEN`. | +| SKIP_FORKS | no | bool | FALSE | If set to `true` will disable the mirroring of forks from your GitHub User / Organisation. | +| DELAY | no | int | 3600 | Number of seconds between program executions. Setting this will only affect how soon after a new repo was created a mirror may appar on Gitea, but has no affect on the ongoing replication. If set to `0` the task is only executed once. | +| DRY_RUN | no | bool | FALSE | If set to `true` will perform no writing changes to your Gitea instance, but log the planned actions. | +| INCLUDE | no | string | "*" | Name based repository filter (include): If any filter matches, the repository will be mirrored. It supports glob format, multiple filters can be separated with commas (`,`) | +| EXCLUDE | no | string | "" | Name based repository filter (exclude). If any filter matches, the repository will not be mirrored. It supports glob format, multiple filters can be separated with commas (`,`). `EXCLUDE` filters are applied after `INCLUDE` ones. | ### Docker From 34f56583e682b6dc03e9dc8c26148a90ecfd4566 Mon Sep 17 00:00:00 2001 From: Roberto Bochet Date: Sat, 9 Nov 2024 17:09:38 +0100 Subject: [PATCH 3/3] Use dedicated parameter for single run --- README.md | 25 +++++++++++++------------ docker-entrypoint.sh | 4 +++- src/configuration.mjs | 1 + 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 0a4b17f..9153bbd 100644 --- a/README.md +++ b/README.md @@ -34,18 +34,19 @@ private repos, they will be created as private repos on your gitea server. All configuration is performed through environment variables. Flags are considered `true` on `true`, `TRUE` or `1`. -| Parameter | Required | Type | Default | Description | -|-----------------------------|----------|--------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| GITHUB_USERNAME | yes | string | - | The name of the GitHub user or organisation to mirror. | -| GITEA_URL | yes | string | - | The url of your Gitea server. | -| GITEA_TOKEN | yes | string | - | The token for your gitea user (Settings -> Applications -> Generate New Token). **Attention: if this is set, the token will be transmitted to your specified Gitea instance!** | -| GITHUB_TOKEN | no* | string | - | GitHub token (PAT). Is mandatory in combination with `MIRROR_PRIVATE_REPOSITORIES`. | -| MIRROR_PRIVATE_REPOSITORIES | no | bool | FALSE | If set to `true` your private GitHub Repositories will be mirrored to Gitea. Requires `GITHUB_TOKEN`. | -| SKIP_FORKS | no | bool | FALSE | If set to `true` will disable the mirroring of forks from your GitHub User / Organisation. | -| DELAY | no | int | 3600 | Number of seconds between program executions. Setting this will only affect how soon after a new repo was created a mirror may appar on Gitea, but has no affect on the ongoing replication. If set to `0` the task is only executed once. | -| DRY_RUN | no | bool | FALSE | If set to `true` will perform no writing changes to your Gitea instance, but log the planned actions. | -| INCLUDE | no | string | "*" | Name based repository filter (include): If any filter matches, the repository will be mirrored. It supports glob format, multiple filters can be separated with commas (`,`) | -| EXCLUDE | no | string | "" | Name based repository filter (exclude). If any filter matches, the repository will not be mirrored. It supports glob format, multiple filters can be separated with commas (`,`). `EXCLUDE` filters are applied after `INCLUDE` ones. | +| Parameter | Required | Type | Default | Description | +|-----------------------------|----------|--------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| GITHUB_USERNAME | yes | string | - | The name of the GitHub user or organisation to mirror. | +| GITEA_URL | yes | string | - | The url of your Gitea server. | +| GITEA_TOKEN | yes | string | - | The token for your gitea user (Settings -> Applications -> Generate New Token). **Attention: if this is set, the token will be transmitted to your specified Gitea instance!** | +| GITHUB_TOKEN | no* | string | - | GitHub token (PAT). Is mandatory in combination with `MIRROR_PRIVATE_REPOSITORIES`. | +| MIRROR_PRIVATE_REPOSITORIES | no | bool | FALSE | If set to `true` your private GitHub Repositories will be mirrored to Gitea. Requires `GITHUB_TOKEN`. | +| SKIP_FORKS | no | bool | FALSE | If set to `true` will disable the mirroring of forks from your GitHub User / Organisation. | +| DELAY | no | int | 3600 | Number of seconds between program executions. Setting this will only affect how soon after a new repo was created a mirror may appar on Gitea, but has no affect on the ongoing replication. | +| DRY_RUN | no | bool | FALSE | If set to `true` will perform no writing changes to your Gitea instance, but log the planned actions. | +| INCLUDE | no | string | "*" | Name based repository filter (include): If any filter matches, the repository will be mirrored. It supports glob format, multiple filters can be separated with commas (`,`) | +| EXCLUDE | no | string | "" | Name based repository filter (exclude). If any filter matches, the repository will not be mirrored. It supports glob format, multiple filters can be separated with commas (`,`). `EXCLUDE` filters are applied after `INCLUDE` ones. +| SINGLE_RUN | no | bool | FALSE | If set to `TRUE` the task is only executed once. | ### Docker diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 9ff0692..0a2fb1c 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -10,7 +10,9 @@ do echo "Starting to create mirrors..." node /app/dist/index.js - if [ $DELAY -eq 0 ]; then break; fi + case $SINGLE_RUN in + (TRUE | true | 1) break;; + esac echo "Waiting for ${DELAY} seconds..." sleep "${DELAY}" diff --git a/src/configuration.mjs b/src/configuration.mjs index 66d2661..38c2765 100644 --- a/src/configuration.mjs +++ b/src/configuration.mjs @@ -44,6 +44,7 @@ export function configuration() { delay: readInt("DELAY") ?? defaultDelay, include: (readEnv("INCLUDE") ?? defaultInclude).split(",").map(f => f.trim()), exclude: (readEnv("EXCLUDE") ?? defaultExclude).split(",").map(f => f.trim()), + singleRun: readBoolean("SINGLE_RUN"), }; if (config.github.privateRepositories && config.github.token === undefined) {