Skip to content

Commit

Permalink
Changed register implementation (multi paging)
Browse files Browse the repository at this point in the history
When there was more then 20 runners (default page size in Gitlab API)
finding runner by description failed if it was not on the first page.

removed gitlab_functions.sh, it was hard to support multi page calls

New implementation is located in:

https://github.com/FlakM/gitlab-runner-cleaner

Closes #4
Closes #5
  • Loading branch information
FlakM committed Feb 23, 2018
1 parent f99891e commit 82d71ee
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.temp
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ RUN apt-get update -y && \
RUN curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | bash
RUN apt-get -y install gitlab-runner

RUN curl -LJO https://github.com/FlakM/gitlab-runner-cleaner/releases/download/0.0.2/gitlab-runner-cleaner.sh && \
chmod +x gitlab-runner-cleaner.sh

ADD entrypoint.sh /
ADD gitlab_functions.sh /

RUN chmod +x /entrypoint.sh /gitlab_functions.sh

RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/usr/bin/dumb-init", "/entrypoint.sh"]
CMD ["run", "--user=gitlab-runner", "--working-directory=/home/gitlab-runner"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The default image needs additional step of executing script from outside of cont
| tag | version |
| --------------- | --------------|
| `0.0.3` | 10.2.0 |
| `0.0.4`-`0.0.6` | 10.4.0 |
| `0.0.4`-`0.0.9` | 10.4.0 |


# Running instructions
Expand Down Expand Up @@ -70,7 +70,7 @@ docker exec -i gitlab-runner gitlab-runner register
|`DOCKER_PRIVILEGED` | should you need to run in priviliged mode set to true (otherwise defaults to false) | false | false |
|`REGISTER_LOCKED` | should this runner be locked to this project or not | true | false |
|`ADMIN_TOKEN` | access token with admin privilages (if specified runner will be registered for projects`PROJECTS_TO_REGISTER`) | | false |
|`PROJECTS_TO_REGISTER` | project ids seperated by `;` | | false |
|`PROJECTS_TO_REGISTER` | project ids seperated by `,` or `;` | | false |
|`CUSTOM_RUNNER_NAME` | runner's description | `$HOSTNAME` | false |
|`DOCKER_VOLUMES` | volume mounted by this runner | | false |
|`DOCKER_IMAGE` | docker image to use | docker:18.01.0-ce | true |
Expand Down
15 changes: 4 additions & 11 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fi

if [ "$ADMIN_TOKEN" != "" ]; then
REGISTER_OTHER_PROJECTS="true"
PROJECTS_STRING="$PROJECTS_TO_REGISTER"
PROJECTS_STRING=`echo "$PROJECTS_TO_REGISTER" | tr ";" ","`
fi

MY_NAME="${CUSTOM_RUNNER_NAME:-$HOSTNAME}"
Expand Down Expand Up @@ -56,16 +56,9 @@ fi


if [ "$REGISTER_OTHER_PROJECTS" == "true" ]; then
source ./gitlab_functions.sh
RUNNER_ID=$(getRunnerIdByDescription "$RUNNER_NAME" "$CI_SERVER_URL" "$ADMIN_TOKEN")

projects=$(echo "$PROJECTS_STRING" | tr ";" "\n")

for PROJECT_ID in $projects
do
echo "registering runner $RUNNER_ID to [$PROJECT_ID]"
registerRunnerToProject "$RUNNER_ID" "$PROJECT_ID" "$CI_SERVER_URL" "$ADMIN_TOKEN"
done
export GITLAB_TOKEN="$ADMIN_TOKEN"

./gitlab-runner-cleaner.sh register "$RUNNER_NAME" --byId=false --projects "$PROJECTS_STRING"
fi


Expand Down
66 changes: 0 additions & 66 deletions gitlab_functions.sh

This file was deleted.

0 comments on commit 82d71ee

Please sign in to comment.