From d8cba9237f9096700130cd3f131f7c0c38716a39 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Tue, 23 Apr 2019 17:06:06 -0400 Subject: [PATCH 01/21] Geo: logcursor v1 Add `gitlab-geo-logcursor` container, based on `gitlab-rails-ee` This container only builds on EE. Executes `/srv/gitlab/ee/bin/geo_log_cursor` after ensuring that the Geo database is ready by checking `rake geo:db:version` This does not seed or migrate the Geo database, and there are no changes to enable this elsewhere! Signed-off-by: Jason Plum --- .gitlab-ci.yml | 16 +++++++ gitlab-geo-logcursor/Dockerfile | 18 +++++++ gitlab-geo-logcursor/scripts/healthcheck | 6 +++ gitlab-geo-logcursor/scripts/process-wrapper | 12 +++++ gitlab-geo-logcursor/scripts/wait-for-deps | 49 ++++++++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 gitlab-geo-logcursor/Dockerfile create mode 100755 gitlab-geo-logcursor/scripts/healthcheck create mode 100755 gitlab-geo-logcursor/scripts/process-wrapper create mode 100755 gitlab-geo-logcursor/scripts/wait-for-deps diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8333233ca..6d6cdb087 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -223,6 +223,22 @@ gitlab-task-runner-ce: - gitlab-rails-ce <<: *except-ee +gitlab-geo-logcursor: + <<: *job-base + stage: phase-five + script: + - ruby_version=$(get_version gitlab-ruby) + - rails_version=$(get_version gitlab-rails) + - rails_container=($(echo -n "$ruby_version$rails_version$GITLAB_VERSION$(date -u +%D)" | sha1sum)) + - export CONTAINER_VERSION=($(echo -n "$rails_container$TARGET_VERSION" | sha1sum)) + - export BASE_IMAGE="$CI_REGISTRY_IMAGE/gitlab-rails-ee:$rails_container" + - build_if_needed --build-arg "FROM_IMAGE=$CI_REGISTRY_IMAGE/gitlab-rails-ee" + --build-arg "TAG=$rails_container" + - push_if_master_or_tag $GITLAB_REF_SLUG + dependencies: + - gitlab-rails-ee + <<: *except-ce + gitlab-unicorn-ee: <<: *job-base stage: phase-six diff --git a/gitlab-geo-logcursor/Dockerfile b/gitlab-geo-logcursor/Dockerfile new file mode 100644 index 000000000..505212ed2 --- /dev/null +++ b/gitlab-geo-logcursor/Dockerfile @@ -0,0 +1,18 @@ +ARG CI_REGISTRY_IMAGE="registry.gitlab.com/gitlab-org/build/cng" +ARG TAG=latest +ARG FROM_IMAGE="$CI_REGISTRY_IMAGE/gitlab-rails-ee" + +FROM ${FROM_IMAGE}:${TAG} + +ARG DATADIR=/var/opt/gitlab +ARG CONFIG=/srv/gitlab/config +ARG GITLAB_USER=git + +USER $GITLAB_USER:$GITLAB_USER + +COPY scripts/ /scripts + +CMD /scripts/process-wrapper + +HEALTHCHECK --interval=30s --timeout=30s --retries=5 \ +CMD /scripts/healthcheck diff --git a/gitlab-geo-logcursor/scripts/healthcheck b/gitlab-geo-logcursor/scripts/healthcheck new file mode 100755 index 000000000..5af5dca0f --- /dev/null +++ b/gitlab-geo-logcursor/scripts/healthcheck @@ -0,0 +1,6 @@ +#!/bin/bash + +set -e + +# Check that geo_log_cursor is running +/usr/bin/pgrep "geo_log_cursor" diff --git a/gitlab-geo-logcursor/scripts/process-wrapper b/gitlab-geo-logcursor/scripts/process-wrapper new file mode 100755 index 000000000..219c5e1b0 --- /dev/null +++ b/gitlab-geo-logcursor/scripts/process-wrapper @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +cd /srv/gitlab + +echo "Starting geo_log_cursor" +/srv/gitlab/ee/bin/geo_log_cursor >> /var/log/gitla/geo_log_cursor.log 2>&1 & + +tail -f /var/log/gitlab/* + +wait diff --git a/gitlab-geo-logcursor/scripts/wait-for-deps b/gitlab-geo-logcursor/scripts/wait-for-deps new file mode 100755 index 000000000..5c91c7964 --- /dev/null +++ b/gitlab-geo-logcursor/scripts/wait-for-deps @@ -0,0 +1,49 @@ +#!/bin/bash + +WAIT_FOR_TIMEOUT="${WAIT_FOR_TIMEOUT:-5}" + +cd /srv/gitlab + +# fetch the schema desired version directly from the source code +SCHEMA_VERSION=$(grep '(version: ' /srv/gitlab/ee/geo/db/schema.rb | sed -e 's/.* \([[:digit:]]\+\)) do/\1/') + +# Compare desired schema version to active schema version in the database +# - set BYPASS_SCHEMA_VERSION to skip version check, and only test DB online +function checkSchemaVersion() { + # Ask for the current DB schema version, via Rake + DB_SCHEMA_VERSION=$(/srv/gitlab/bin/bundle exec rake geo:db:version) + + # If rake failed, we're not connected to the DB, and DB_SCHEMA_VERSION is empty. + if [ $? -ne 0 ]; then + return 1 + fi + + # Output the current schema version + echo "Geo Database Schema" + echo $DB_SCHEMA_VERSION + echo "Geo Codebase version: $SCHEMA_VERSION" + # Some uses (migrations) only care if the DB is up + if [ -n "${BYPASS_SCHEMA_VERSION}" ]; then + return 0 + fi + + # DB_SCHEMA_VERSION ~ 'Current version: ##########', strip to just number. + DB_SCHEMA_VERSION=${DB_SCHEMA_VERSION##Current version: } + + # Compare local to db, pass if local less than or equal to db + [ $SCHEMA_VERSION -le $DB_SCHEMA_VERSION ]; + return $? +} + +for i in $(seq 1 $WAIT_FOR_TIMEOUT); do + echo "Checking database connection and schema version" + if checkSchemaVersion ; then + if [ "$@" ]; then + exec "$@" + else + exit 0 + fi + fi + sleep 1 +done +exit 1 -- GitLab From 24078e24cf79402d8f76c9aaefe6470ee61dc814 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Fri, 3 May 2019 18:51:15 +0000 Subject: [PATCH 02/21] Apply suggestion to gitlab-geo-logcursor/scripts/process-wrapper --- gitlab-geo-logcursor/scripts/process-wrapper | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab-geo-logcursor/scripts/process-wrapper b/gitlab-geo-logcursor/scripts/process-wrapper index 219c5e1b0..a4009a058 100755 --- a/gitlab-geo-logcursor/scripts/process-wrapper +++ b/gitlab-geo-logcursor/scripts/process-wrapper @@ -5,7 +5,7 @@ set -e cd /srv/gitlab echo "Starting geo_log_cursor" -/srv/gitlab/ee/bin/geo_log_cursor >> /var/log/gitla/geo_log_cursor.log 2>&1 & +/srv/gitlab/ee/bin/geo_log_cursor >> /var/log/gitlab/geo_log_cursor.log 2>&1 & tail -f /var/log/gitlab/* -- GitLab From 1d63a9ced91093629d1ed3c6e3aa8283a874a8ac Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Wed, 5 Jun 2019 14:06:48 -0400 Subject: [PATCH 03/21] Geo: logcursor: add debug environment variable Add `DEBUG` environment variable handling to the process-wapper script --- gitlab-geo-logcursor/scripts/process-wrapper | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gitlab-geo-logcursor/scripts/process-wrapper b/gitlab-geo-logcursor/scripts/process-wrapper index a4009a058..b4a95724f 100755 --- a/gitlab-geo-logcursor/scripts/process-wrapper +++ b/gitlab-geo-logcursor/scripts/process-wrapper @@ -4,9 +4,12 @@ set -e cd /srv/gitlab -echo "Starting geo_log_cursor" -/srv/gitlab/ee/bin/geo_log_cursor >> /var/log/gitlab/geo_log_cursor.log 2>&1 & +debug='' +if [ "${DEBUG}x" -ne "x"]; then + debug='--debug' +fi -tail -f /var/log/gitlab/* +echo "Starting geo_log_cursor" +/srv/gitlab/ee/bin/geo_log_cursor ${debug} >> /var/log/gitlab/geo_log_cursor.log 2>&1 wait -- GitLab From 007bdc9360683d7929dd7af211cfeb3a868930d1 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Wed, 5 Jun 2019 14:13:18 -0400 Subject: [PATCH 04/21] Geo: logcursor: fix logging output Fix the logging output of the geo_log_cursor, to be to a file & output. --- gitlab-geo-logcursor/scripts/process-wrapper | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gitlab-geo-logcursor/scripts/process-wrapper b/gitlab-geo-logcursor/scripts/process-wrapper index b4a95724f..304e4b42b 100755 --- a/gitlab-geo-logcursor/scripts/process-wrapper +++ b/gitlab-geo-logcursor/scripts/process-wrapper @@ -4,12 +4,17 @@ set -e cd /srv/gitlab +LOGFILE=/var/log/gitlab/geo_log_cursor.log +touch $LOGFILE + debug='' -if [ "${DEBUG}x" -ne "x"]; then +if [ "${DEBUG}x" != "x"]; then debug='--debug' fi echo "Starting geo_log_cursor" -/srv/gitlab/ee/bin/geo_log_cursor ${debug} >> /var/log/gitlab/geo_log_cursor.log 2>&1 +/srv/gitlab/ee/bin/geo_log_cursor ${debug} >> $LOGFILE 2>&1 + +tail -f $LOGFILE wait -- GitLab From 606f00fdabb1c16ead1f6b343a1d01f52c5b88de Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Wed, 5 Jun 2019 14:39:20 -0400 Subject: [PATCH 05/21] Geo: logcursor: fix typo in wrapper --- gitlab-geo-logcursor/scripts/process-wrapper | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab-geo-logcursor/scripts/process-wrapper b/gitlab-geo-logcursor/scripts/process-wrapper index 304e4b42b..10e20233a 100755 --- a/gitlab-geo-logcursor/scripts/process-wrapper +++ b/gitlab-geo-logcursor/scripts/process-wrapper @@ -8,7 +8,7 @@ LOGFILE=/var/log/gitlab/geo_log_cursor.log touch $LOGFILE debug='' -if [ "${DEBUG}x" != "x"]; then +if [ "${DEBUG}x" != "x" ]; then debug='--debug' fi -- GitLab From 94764374838a629cf3897147b07a18b359a9950b Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Wed, 5 Jun 2019 15:30:37 -0400 Subject: [PATCH 06/21] Geo: logcursor: remove log & debug flag, not useful - Remove logging to a file (no output) - Remove debug flagging (no effect) Neither are useful --- gitlab-geo-logcursor/scripts/process-wrapper | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/gitlab-geo-logcursor/scripts/process-wrapper b/gitlab-geo-logcursor/scripts/process-wrapper index 10e20233a..b737f1156 100755 --- a/gitlab-geo-logcursor/scripts/process-wrapper +++ b/gitlab-geo-logcursor/scripts/process-wrapper @@ -4,17 +4,7 @@ set -e cd /srv/gitlab -LOGFILE=/var/log/gitlab/geo_log_cursor.log -touch $LOGFILE - -debug='' -if [ "${DEBUG}x" != "x" ]; then - debug='--debug' -fi - echo "Starting geo_log_cursor" -/srv/gitlab/ee/bin/geo_log_cursor ${debug} >> $LOGFILE 2>&1 - -tail -f $LOGFILE +/srv/gitlab/ee/bin/geo_log_cursor wait -- GitLab From d882576a999714dbec589e5f96374643ca6447fe Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Wed, 3 Jul 2019 19:08:06 +0000 Subject: [PATCH 07/21] geologcursor: add log tailing Add touch & log tailing for `geo.log` per @brodock --- gitlab-geo-logcursor/scripts/process-wrapper | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gitlab-geo-logcursor/scripts/process-wrapper b/gitlab-geo-logcursor/scripts/process-wrapper index b737f1156..aa6baa3b2 100755 --- a/gitlab-geo-logcursor/scripts/process-wrapper +++ b/gitlab-geo-logcursor/scripts/process-wrapper @@ -4,7 +4,11 @@ set -e cd /srv/gitlab +touch /var/log/gitlab/geo.log + echo "Starting geo_log_cursor" -/srv/gitlab/ee/bin/geo_log_cursor +/srv/gitlab/ee/bin/geo_log_cursor ${GEO_LOGCURSOR_ARGUMENTS} 2&1 > /var/log/gitlab/geo_stdout.log & + +tail -f /var/log/gitlab/* wait -- GitLab From ec5e9ae39cf9f57e808b9b03382fc9b429682ce2 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Mon, 8 Jul 2019 18:59:52 +0000 Subject: [PATCH 08/21] Apply suggestion to gitlab-geo-logcursor/scripts/process-wrapper --- gitlab-geo-logcursor/scripts/process-wrapper | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab-geo-logcursor/scripts/process-wrapper b/gitlab-geo-logcursor/scripts/process-wrapper index aa6baa3b2..0c948dc2e 100755 --- a/gitlab-geo-logcursor/scripts/process-wrapper +++ b/gitlab-geo-logcursor/scripts/process-wrapper @@ -7,7 +7,7 @@ cd /srv/gitlab touch /var/log/gitlab/geo.log echo "Starting geo_log_cursor" -/srv/gitlab/ee/bin/geo_log_cursor ${GEO_LOGCURSOR_ARGUMENTS} 2&1 > /var/log/gitlab/geo_stdout.log & +/srv/gitlab/ee/bin/geo_log_cursor ${GEO_LOGCURSOR_ARGUMENTS} 2>&1 1>/var/log/gitlab/geo_output.log & tail -f /var/log/gitlab/* -- GitLab From ff666c32aa21c61fcae9184e65e2a208e818cd88 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Mon, 8 Jul 2019 16:45:25 -0400 Subject: [PATCH 09/21] geo: add touch to geo_stdout.log Add touch for geo_stdout.log, as it needs to be present for `tail -f`, but there is no output at that time. --- gitlab-geo-logcursor/scripts/process-wrapper | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab-geo-logcursor/scripts/process-wrapper b/gitlab-geo-logcursor/scripts/process-wrapper index 0c948dc2e..b81927177 100755 --- a/gitlab-geo-logcursor/scripts/process-wrapper +++ b/gitlab-geo-logcursor/scripts/process-wrapper @@ -4,7 +4,7 @@ set -e cd /srv/gitlab -touch /var/log/gitlab/geo.log +touch /var/log/gitlab/geo.log /var/log/gitlab/geo_output.log echo "Starting geo_log_cursor" /srv/gitlab/ee/bin/geo_log_cursor ${GEO_LOGCURSOR_ARGUMENTS} 2>&1 1>/var/log/gitlab/geo_output.log & -- GitLab From 7ae7fb17d8acea9f67591f6c70bdc1a9976d2a20 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Wed, 17 Jul 2019 16:55:10 -0400 Subject: [PATCH 10/21] geo: fix ci build stage to six --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6d6cdb087..0582117b5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -225,7 +225,7 @@ gitlab-task-runner-ce: gitlab-geo-logcursor: <<: *job-base - stage: phase-five + stage: phase-six script: - ruby_version=$(get_version gitlab-ruby) - rails_version=$(get_version gitlab-rails) -- GitLab From b1499109739ae30426f517da3a85d503039505e9 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Wed, 17 Jul 2019 17:03:22 -0400 Subject: [PATCH 11/21] geo: add mkdir for logs Add mkdir for /var/log/gitlab/gitlab-rails & touch geo.log there. --- gitlab-geo-logcursor/scripts/process-wrapper | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitlab-geo-logcursor/scripts/process-wrapper b/gitlab-geo-logcursor/scripts/process-wrapper index b81927177..80b5c0998 100755 --- a/gitlab-geo-logcursor/scripts/process-wrapper +++ b/gitlab-geo-logcursor/scripts/process-wrapper @@ -4,7 +4,8 @@ set -e cd /srv/gitlab -touch /var/log/gitlab/geo.log /var/log/gitlab/geo_output.log +mkdir -p /var/log/gitlab/gitlab-rails/ +touch /var/log/gitlab/gitlab-rails/geo.log /var/log/gitlab/geo_output.log echo "Starting geo_log_cursor" /srv/gitlab/ee/bin/geo_log_cursor ${GEO_LOGCURSOR_ARGUMENTS} 2>&1 1>/var/log/gitlab/geo_output.log & -- GitLab From 7569849833c6652b5d9c1a2d782c943bea387183 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Wed, 17 Jul 2019 20:55:18 -0400 Subject: [PATCH 12/21] geo: fix ci push_ function --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0582117b5..45ac0a0e7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -234,7 +234,7 @@ gitlab-geo-logcursor: - export BASE_IMAGE="$CI_REGISTRY_IMAGE/gitlab-rails-ee:$rails_container" - build_if_needed --build-arg "FROM_IMAGE=$CI_REGISTRY_IMAGE/gitlab-rails-ee" --build-arg "TAG=$rails_container" - - push_if_master_or_tag $GITLAB_REF_SLUG + - push_if_master_or_stable_or_tag $GITLAB_REF_SLUG dependencies: - gitlab-rails-ee <<: *except-ce -- GitLab From 5fc387374ea9bd4c4b893d5600df5ff098989e2a Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Thu, 18 Jul 2019 14:28:06 -0400 Subject: [PATCH 13/21] geo-logcursor: geo.log is in /var/log/gitlab Move the geo.log location back to /var/log/gitlab Adjust the parameter ordering for redirect & log file. Cosmetic. --- gitlab-geo-logcursor/scripts/process-wrapper | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gitlab-geo-logcursor/scripts/process-wrapper b/gitlab-geo-logcursor/scripts/process-wrapper index 80b5c0998..27147fed1 100755 --- a/gitlab-geo-logcursor/scripts/process-wrapper +++ b/gitlab-geo-logcursor/scripts/process-wrapper @@ -4,11 +4,10 @@ set -e cd /srv/gitlab -mkdir -p /var/log/gitlab/gitlab-rails/ -touch /var/log/gitlab/gitlab-rails/geo.log /var/log/gitlab/geo_output.log +touch /var/log/gitlab/geo.log /var/log/gitlab/geo_output.log echo "Starting geo_log_cursor" -/srv/gitlab/ee/bin/geo_log_cursor ${GEO_LOGCURSOR_ARGUMENTS} 2>&1 1>/var/log/gitlab/geo_output.log & +/srv/gitlab/ee/bin/geo_log_cursor ${GEO_LOGCURSOR_ARGUMENTS} >> /var/log/gitlab/geo_output.log 2>&1 & tail -f /var/log/gitlab/* -- GitLab From 452d4de84dc106704d52e637574b1ab7de844e87 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Wed, 25 Sep 2019 22:30:55 -0400 Subject: [PATCH 14/21] geo-logcursor: rework process-wrapper Rework the process wrapper script for geo-logcursor container such that we're specifically waiting on the pid of the actual process. Add the `--stdout-logging` flag to the command call, testing per mkozono request. Future: no `tail` or `wait` call --- gitlab-geo-logcursor/scripts/process-wrapper | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gitlab-geo-logcursor/scripts/process-wrapper b/gitlab-geo-logcursor/scripts/process-wrapper index 27147fed1..bae960c03 100755 --- a/gitlab-geo-logcursor/scripts/process-wrapper +++ b/gitlab-geo-logcursor/scripts/process-wrapper @@ -4,11 +4,19 @@ set -e cd /srv/gitlab -touch /var/log/gitlab/geo.log /var/log/gitlab/geo_output.log +# pre-create the log file. +touch /var/log/gitlab/geo.log +# Start geo_log_cursor, logging via stdout. echo "Starting geo_log_cursor" -/srv/gitlab/ee/bin/geo_log_cursor ${GEO_LOGCURSOR_ARGUMENTS} >> /var/log/gitlab/geo_output.log 2>&1 & +/srv/gitlab/ee/bin/geo_log_cursor --stdout-logging \ + ${GEO_LOGCURSOR_ARGUMENTS} \ + >> /var/log/gitlab/geo.log 2>&1 & +# Capture the pid, so we can wait specifically on it. +GEO_PID=$! -tail -f /var/log/gitlab/* +# Catch all the logs from gitlab codebase +tail -f /var/log/gitlab/* & -wait +# Wait for geo_log_cursor to stop +wait $GEO_PID -- GitLab From 3effccb313125f651f96cff8a6a9a0b384e988fc Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Thu, 26 Sep 2019 16:44:23 -0400 Subject: [PATCH 15/21] Geo: simplify logcursor process wrapper Simplify the `process-wrapper` script for `geo_log_cursor`, directly calling it with `--stdout-logging` and remove all extraneous tail-ing. --- gitlab-geo-logcursor/scripts/process-wrapper | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/gitlab-geo-logcursor/scripts/process-wrapper b/gitlab-geo-logcursor/scripts/process-wrapper index bae960c03..bd6bd2326 100755 --- a/gitlab-geo-logcursor/scripts/process-wrapper +++ b/gitlab-geo-logcursor/scripts/process-wrapper @@ -4,19 +4,6 @@ set -e cd /srv/gitlab -# pre-create the log file. -touch /var/log/gitlab/geo.log - # Start geo_log_cursor, logging via stdout. echo "Starting geo_log_cursor" -/srv/gitlab/ee/bin/geo_log_cursor --stdout-logging \ - ${GEO_LOGCURSOR_ARGUMENTS} \ - >> /var/log/gitlab/geo.log 2>&1 & -# Capture the pid, so we can wait specifically on it. -GEO_PID=$! - -# Catch all the logs from gitlab codebase -tail -f /var/log/gitlab/* & - -# Wait for geo_log_cursor to stop -wait $GEO_PID +/srv/gitlab/ee/bin/geo_log_cursor --stdout-logging ${GEO_LOGCURSOR_ARGUMENTS} -- GitLab From 50bfa91e9bc408c4abc8774eba295b5af7089773 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Thu, 26 Sep 2019 16:45:37 -0400 Subject: [PATCH 16/21] Geo: support forcibly building the container in CI Add the `FORCE_IMAGE_BUILDS` environment handling to match all other current containers produced by CI. --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 45ac0a0e7..7447a6d1b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -230,6 +230,7 @@ gitlab-geo-logcursor: - ruby_version=$(get_version gitlab-ruby) - rails_version=$(get_version gitlab-rails) - rails_container=($(echo -n "$ruby_version$rails_version$GITLAB_VERSION$(date -u +%D)" | sha1sum)) + - export FORCE_IMAGE_BUILDS="${FORCE_IMAGE_BUILDS-${FORCE_RAILS_IMAGE_BUILDS-false}}" - export CONTAINER_VERSION=($(echo -n "$rails_container$TARGET_VERSION" | sha1sum)) - export BASE_IMAGE="$CI_REGISTRY_IMAGE/gitlab-rails-ee:$rails_container" - build_if_needed --build-arg "FROM_IMAGE=$CI_REGISTRY_IMAGE/gitlab-rails-ee" -- GitLab From a32d0eba4de03f9398b37f26cfe62bbe833c8659 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Tue, 1 Oct 2019 14:44:30 -0400 Subject: [PATCH 17/21] Geo: fix logcursor healthcheck Fix the healthcheck script on the logcursor container to check full path to script, using `pgrep -f`. --- gitlab-geo-logcursor/scripts/healthcheck | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab-geo-logcursor/scripts/healthcheck b/gitlab-geo-logcursor/scripts/healthcheck index 5af5dca0f..8a7066224 100755 --- a/gitlab-geo-logcursor/scripts/healthcheck +++ b/gitlab-geo-logcursor/scripts/healthcheck @@ -3,4 +3,4 @@ set -e # Check that geo_log_cursor is running -/usr/bin/pgrep "geo_log_cursor" +/usr/bin/pgrep -f "/srv/gitlab/ee/bin/geo_log_cursor" -- GitLab From a8dad1a266441ccaca9d575326f7b5d1df4593b8 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Tue, 1 Oct 2019 15:05:38 -0400 Subject: [PATCH 18/21] Geo-logcursor: de-duplicate wait-for-deps De-duplicate the wait-for-deps script from geo-logcursor container. Parameterize via `DB_SCHEMA_TARGET` environment, if `geo`, set params to check that dynamically vs duplicating the script. --- gitlab-geo-logcursor/Dockerfile | 3 ++ gitlab-geo-logcursor/scripts/wait-for-deps | 49 ---------------------- gitlab-rails/scripts/wait-for-deps | 14 ++++++- 3 files changed, 15 insertions(+), 51 deletions(-) delete mode 100755 gitlab-geo-logcursor/scripts/wait-for-deps diff --git a/gitlab-geo-logcursor/Dockerfile b/gitlab-geo-logcursor/Dockerfile index 505212ed2..6be7462bb 100644 --- a/gitlab-geo-logcursor/Dockerfile +++ b/gitlab-geo-logcursor/Dockerfile @@ -8,6 +8,9 @@ ARG DATADIR=/var/opt/gitlab ARG CONFIG=/srv/gitlab/config ARG GITLAB_USER=git +# Control the target for `wait-for-deps` schema check +ENV DB_SCHEMA_TARGET=geo + USER $GITLAB_USER:$GITLAB_USER COPY scripts/ /scripts diff --git a/gitlab-geo-logcursor/scripts/wait-for-deps b/gitlab-geo-logcursor/scripts/wait-for-deps deleted file mode 100755 index 5c91c7964..000000000 --- a/gitlab-geo-logcursor/scripts/wait-for-deps +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash - -WAIT_FOR_TIMEOUT="${WAIT_FOR_TIMEOUT:-5}" - -cd /srv/gitlab - -# fetch the schema desired version directly from the source code -SCHEMA_VERSION=$(grep '(version: ' /srv/gitlab/ee/geo/db/schema.rb | sed -e 's/.* \([[:digit:]]\+\)) do/\1/') - -# Compare desired schema version to active schema version in the database -# - set BYPASS_SCHEMA_VERSION to skip version check, and only test DB online -function checkSchemaVersion() { - # Ask for the current DB schema version, via Rake - DB_SCHEMA_VERSION=$(/srv/gitlab/bin/bundle exec rake geo:db:version) - - # If rake failed, we're not connected to the DB, and DB_SCHEMA_VERSION is empty. - if [ $? -ne 0 ]; then - return 1 - fi - - # Output the current schema version - echo "Geo Database Schema" - echo $DB_SCHEMA_VERSION - echo "Geo Codebase version: $SCHEMA_VERSION" - # Some uses (migrations) only care if the DB is up - if [ -n "${BYPASS_SCHEMA_VERSION}" ]; then - return 0 - fi - - # DB_SCHEMA_VERSION ~ 'Current version: ##########', strip to just number. - DB_SCHEMA_VERSION=${DB_SCHEMA_VERSION##Current version: } - - # Compare local to db, pass if local less than or equal to db - [ $SCHEMA_VERSION -le $DB_SCHEMA_VERSION ]; - return $? -} - -for i in $(seq 1 $WAIT_FOR_TIMEOUT); do - echo "Checking database connection and schema version" - if checkSchemaVersion ; then - if [ "$@" ]; then - exec "$@" - else - exit 0 - fi - fi - sleep 1 -done -exit 1 diff --git a/gitlab-rails/scripts/wait-for-deps b/gitlab-rails/scripts/wait-for-deps index 4d35bd1be..7d8aad79d 100755 --- a/gitlab-rails/scripts/wait-for-deps +++ b/gitlab-rails/scripts/wait-for-deps @@ -2,16 +2,26 @@ WAIT_FOR_TIMEOUT="${WAIT_FOR_TIMEOUT:-5}" +# Configure for which schema to be verifying +SCHEMA_FILE=db/schema.rb +SCHEMA_RAKE_TASK=db:version +if [ ! -z "${DB_SCHEMA_TARGET}" ]; then + if [ "${DB_SCHEMA_TARGET,,}" == "geo" ]; then + SCHEMA_FILE=ee/db/geo/schema.rb + SCHEMA_RAKE_TASK=geo:db:version + fi +fi + cd /srv/gitlab # fetch the schema desired version directly from the source code -SCHEMA_VERSION=$(grep '(version: ' /srv/gitlab/db/schema.rb | sed -e 's/_//g' -e 's/.* \([[:digit:]]\+\)) do/\1/') +SCHEMA_VERSION=$(grep '(version: ' ${SCHEMA_FILE} | sed -e 's/_//g' -e 's/.* \([[:digit:]]\+\)) do/\1/') # Compare desired schema version to active schema version in the database # - set BYPASS_SCHEMA_VERSION to skip version check, and only test DB online function checkSchemaVersion() { # Ask for the current DB schema version, via Rake - DB_SCHEMA_VERSION=$(/srv/gitlab/bin/bundle exec rake db:version) + DB_SCHEMA_VERSION=$(/srv/gitlab/bin/bundle exec rake ${SCHEMA_RAKE_TASK}) # If rake failed, we're not connected to the DB, and DB_SCHEMA_VERSION is empty. if [ $? -ne 0 ]; then -- GitLab From c6e6d3b3de3dda0c26f8374d4bd7bf3c0a7b9b76 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Thu, 3 Oct 2019 16:14:36 -0400 Subject: [PATCH 19/21] Geo: update logcursor job to new syntax for rails Update the `gitlab-geo-logcursor job` to the latest syntax for getting the version of the `gitlab-rails-ee` container --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7447a6d1b..a0b841f5c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -229,7 +229,7 @@ gitlab-geo-logcursor: script: - ruby_version=$(get_version gitlab-ruby) - rails_version=$(get_version gitlab-rails) - - rails_container=($(echo -n "$ruby_version$rails_version$GITLAB_VERSION$(date -u +%D)" | sha1sum)) + - rails_container=$(cat artifacts/rails_container_ee.txt) - export FORCE_IMAGE_BUILDS="${FORCE_IMAGE_BUILDS-${FORCE_RAILS_IMAGE_BUILDS-false}}" - export CONTAINER_VERSION=($(echo -n "$rails_container$TARGET_VERSION" | sha1sum)) - export BASE_IMAGE="$CI_REGISTRY_IMAGE/gitlab-rails-ee:$rails_container" -- GitLab From bbcfbbba75b738e4fb2fb7e173d3d2d6fd2c3d52 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Mon, 7 Oct 2019 20:21:35 +0000 Subject: [PATCH 20/21] Apply suggestion to gitlab-geo-logcursor/Dockerfile --- gitlab-geo-logcursor/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab-geo-logcursor/Dockerfile b/gitlab-geo-logcursor/Dockerfile index 6be7462bb..e457c6f94 100644 --- a/gitlab-geo-logcursor/Dockerfile +++ b/gitlab-geo-logcursor/Dockerfile @@ -1,6 +1,6 @@ ARG CI_REGISTRY_IMAGE="registry.gitlab.com/gitlab-org/build/cng" -ARG TAG=latest ARG FROM_IMAGE="$CI_REGISTRY_IMAGE/gitlab-rails-ee" +ARG TAG=latest FROM ${FROM_IMAGE}:${TAG} -- GitLab From 51aab4ce059d8381186b07a5dc428921a2928ec5 Mon Sep 17 00:00:00 2001 From: Jason Plum Date: Tue, 8 Oct 2019 11:00:07 -0400 Subject: [PATCH 21/21] apply suggestion to gitlab-rails/scripts/wait-for-deps Move to single `if`, per discussion https://gitlab.com/gitlab-org/build/CNG/merge_requests/220#note_226610841 --- gitlab-rails/scripts/wait-for-deps | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/gitlab-rails/scripts/wait-for-deps b/gitlab-rails/scripts/wait-for-deps index 7d8aad79d..2d0b91c32 100755 --- a/gitlab-rails/scripts/wait-for-deps +++ b/gitlab-rails/scripts/wait-for-deps @@ -5,11 +5,9 @@ WAIT_FOR_TIMEOUT="${WAIT_FOR_TIMEOUT:-5}" # Configure for which schema to be verifying SCHEMA_FILE=db/schema.rb SCHEMA_RAKE_TASK=db:version -if [ ! -z "${DB_SCHEMA_TARGET}" ]; then - if [ "${DB_SCHEMA_TARGET,,}" == "geo" ]; then - SCHEMA_FILE=ee/db/geo/schema.rb - SCHEMA_RAKE_TASK=geo:db:version - fi +if [ "${DB_SCHEMA_TARGET,,}" == "geo" ]; then + SCHEMA_FILE=ee/db/geo/schema.rb + SCHEMA_RAKE_TASK=geo:db:version fi cd /srv/gitlab -- GitLab