From 7b34e716cc433a99626ec6621ecdc46e8d354c35 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Fri, 11 Dec 2020 20:56:01 +0200 Subject: [PATCH] Updates. - New version. - pre-commit. - GitLab CI/CD. - Always pull new images. --- .env | 2 -- .gitlab-ci.yml | 61 +++++++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 29 ++++++++++++++++++++ README.md | 9 ++---- runner/Dockerfile | 4 +-- 5 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 .gitlab-ci.yml create mode 100644 .pre-commit-config.yaml diff --git a/.env b/.env index 612149e..6c9c3de 100644 --- a/.env +++ b/.env @@ -1,3 +1 @@ COMPOSE_PROJECT_NAME=gitlab-runner -DOCKER_HOST=ssh://host01.shore.co.il -RUNNER_NAME=host01.shore.co.il diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..5b5095f --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,61 @@ +--- +image: adarnimrod/ci-images:docker + +stages: + - test + - build + - run + +pre-commit: + stage: test + image: adarnimrod/ci-images:pre-commit + variables: + XDG_CACHE_HOME: "$CI_PROJECT_DIR/.cache" + # Disabled until https://github.com/pre-commit/pre-commit/issues/1387 is + # resolved. + SKIP: "hadolint,docker-compose" + script: + - pre-commit run --all-files + cache: + paths: + - .cache/ + +build: + stage: build + tags: + - "$host" + variables: + COMPOSE_DOCKER_CLI_BUILD: "1" + DOCKER_BUILDKIT: "1" + script: + - docker-compose build --no-cache --pull + - docker-compose pull --quiet + parallel: ¶llel + matrix: + - host: + - host01.shore.co.il + - kodi.shore.co.il + REGISTER_RUN_UNTAGGED: "false" + - host: + - ns4.shore.co.il + REGISTER_RUN_UNTAGGED: "true" + +run: + stage: run + tags: + - $host + variables: + RUNNER_NAME: "$host" + RUNNER_TAG_LIST: "$host" + when: manual + 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$' + parallel: *parallel diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..7e7b050 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,29 @@ +# vim:ff=unix ts=2 sw=2 ai expandtab +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-added-large-files + - id: check-merge-conflict + - id: detect-private-key + - id: trailing-whitespace + - repo: https://github.com/adrienverge/yamllint + rev: v1.17.0 + hooks: + - id: yamllint + - repo: https://github.com/amperser/proselint/ + rev: 0.10.2 + hooks: + - id: proselint + types: [plain-text] + exclude: LICENSE + - repo: https://github.com/Yelp/detect-secrets + rev: v0.13.0 + hooks: + - id: detect-secrets + - repo: https://git.shore.co.il/nimrod/docker-pre-commit.git/ + rev: v0.3.0 + hooks: + - id: docker-compose + - id: hadolint diff --git a/README.md b/README.md index 33c8131..c09f89c 100644 --- a/README.md +++ b/README.md @@ -12,15 +12,10 @@ dockerd socket mounted inside the container). ## Usage First of all, get the registration token from -https://git.shore.co.il/admin/runners. To build and run on `host01.shore.co.il`, +https://git.shore.co.il/admin/runners. To build and run on `ns4.shore.co.il`, just run: ``` -docker-compose build && REGISTRATION_TOKEN='INSERT_TOKEN' docker-compose up -d -``` - -If you want to run on a different host (for example `ns4.shore.co.il`), run: -``` -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 docker-compose up -d +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 ``` ## License diff --git a/runner/Dockerfile b/runner/Dockerfile index 7ea9f97..d897693 100644 --- a/runner/Dockerfile +++ b/runner/Dockerfile @@ -1,9 +1,9 @@ -FROM gitlab/gitlab-runner:alpine-v13.6.0-rc1 +FROM gitlab/gitlab-runner:alpine-v13.7.0-rc1 RUN apk add --no-cache --update docker COPY --chown=root:root entrypoint /entrypoint0 ENV DOCKER_VOLUMES=/var/run/docker.sock:/var/run/docker.sock \ RUNNER_EXECUTOR=docker \ - DOCKER_PULL_POLICY=if-not-present + DOCKER_PULL_POLICY=always ENTRYPOINT [ "/entrypoint0" ] CMD [ "run", "--user=gitlab-runner", "--working-directory=/home/gitlab-runner" ] HEALTHCHECK CMD gitlab-runner list 2>&1 | grep -qF "$CI_SERVER_URL" -- GitLab