diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4ceaa6ce19dfd00b16f8ef7446b07e475a670a78..d01ca6c33a149b76c6110947dd29efa4d0e39702 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,6 @@ image: adarnimrod/ci-images:docker stages: - test - build - - run pre-commit: stage: test @@ -44,45 +43,3 @@ build-ns4: - ns4.shore.co.il variables: *build_vars script: *build_script - -run-host01: - stage: run - tags: - - host01.shore.co.il - variables: - RUNNER_NAME: host01.shore.co.il - RUNNER_TAG_LIST: host01.shore.co.il - REGISTER_RUN_UNTAGGED: "false" - when: manual - script: &run-script - - docker-compose up --detach --remove-orphans - # yamllint disable rule:line-length - - | - for i in $(seq 12) - do - docker container inspect --format '{{ .State.Health.Status }}' $(docker-compose ps -q) | grep -v '^healthy$' || break - sleep 10 - done - ! docker container inspect --format '{{ .State.Health.Status }}' $(docker-compose ps -q) | grep -v '^healthy$' - -run-kodi: - stage: run - tags: - - kodi.shore.co.il - variables: - RUNNER_NAME: kodi.shore.co.il - RUNNER_TAG_LIST: kodi.shore.co.il - REGISTER_RUN_UNTAGGED: "false" - when: manual - script: *run-script - -run-ns4: - stage: run - tags: - - ns4.shore.co.il - variables: - RUNNER_NAME: ns4.shore.co.il - RUNNER_TAG_LIST: ns4.shore.co.il - REGISTER_RUN_UNTAGGED: "true" - when: manual - script: *run-script diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7e7b05015b44e90fc6a50fda6f5dc17143615422..f214fdca6a25a450f9386d8ad2c835689d92bed5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,3 +27,8 @@ repos: hooks: - id: docker-compose - id: hadolint + - repo: https://git.shore.co.il/nimrod/shell-pre-commit.git + sha: v0.6.0 + hooks: + - id: shell-lint + - id: shellcheck diff --git a/README.md b/README.md index d2c4eace4151fb369ed32392f974241070c797d6..cade3a6af0968631a0b8fa970348209a82405d70 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,12 @@ dockerd socket mounted inside the container). ## Usage -First, get the registration token from https://git.shore.co.il/admin/runners. To -build and run on `ns4.shore.co.il`, just run: +The CI will pull and build images, all that's left to do is recreate the +containers. But the jobs fail is the runner is recreated during the job. The +workaround is the `deploy` script. + ``` -DOCKER_HOST=ssh://ns4.shore.co.il docker-compose build && DOCKER_HOST=ssh://ns4.shore.co.il REGISTRATION_TOKEN='INSERT_TOKEN' RUNNER_NAME=ns4.shore.co.il REGISTER_RUN_UNTAGGED="true" docker-compose up -d +REGISTRATION_TOKEN='INSERT_TOKEN' ./deploy ``` ## License diff --git a/deploy b/deploy new file mode 100755 index 0000000000000000000000000000000000000000..14b03892820af72363784b4ac23aa180eeef7f40 --- /dev/null +++ b/deploy @@ -0,0 +1,32 @@ +#!/bin/sh +set -eu + +deploy() { + echo "Deploying to $1" >&2 + export DOCKER_HOST="ssh://$1" + export RUNNER_NAME="$1" + until docker-compose up --detach --remove-orphans 2>/dev/null; do true; done + # shellcheck disable=SC2034 + for i in $(seq 12) + do + # shellcheck disable=SC2046 + docker container inspect --format '{{ .State.Health.Status }}' $(docker-compose ps -q) | grep -v '^healthy$' || break + sleep 10 + done + # shellcheck disable=SC2046 + ! docker container inspect --format '{{ .State.Health.Status }}' $(docker-compose ps -q) | grep -v '^healthy$' + unset DOCKER_HOST + unset RUNNER_NAME +} + +if [ -z "${REGISTRATION_TOKEN:-}" ] +then + echo "REGISTRATION_TOKEN isn't set." >&2 + exit 1 +fi + +export REGISTER_RUN_UNTAGGED="false" +deploy "host01.shore.co.il" +deploy "kodi.shore.co.il" +export REGISTER_RUN_UNTAGGED="true" +deploy "ns4.shore.co.il"