From a66d80e5782d4a2edf94485baf7382373a01ef2e Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 11 May 2019 02:00:59 -0500 Subject: [PATCH 1/8] Add Dockerfile to build gitlab-monitor This image expects a config file in /etc/gitlab-monitor/gitlab.yml. This is needed for https://gitlab.com/charts/gitlab/merge_requests/787. --- .gitlab-ci.yml | 13 +++++++++++++ ci_files/variables.yml | 1 + gitlab-monitor/Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 gitlab-monitor/Dockerfile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 06ad53183..e9dba780d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -279,6 +279,19 @@ gitlab-sidekiq-ce: - gitlab-rails-ce <<: *except-ee +gitlab-monitor: + <<: *job-base + stage: phase-two + script: + - ruby_version=$(get_version gitlab-ruby) + - export CONTAINER_VERSION=($(echo -n "$ruby_version$GITLAB_MONITOR_VERSION" | sha1sum)) + - build_if_needed --build-arg "GITLAB_MONITOR_VERSION=$GITLAB_MONITOR_VERSION" + --build-arg "FROM_IMAGE=$CI_REGISTRY_IMAGE/gitlab-ruby" + --build-arg "TAG=$ruby_version" + - push_if_master_or_tag + dependencies: + - gitlab-ruby + gitlab-mailroom: <<: *job-base stage: phase-two diff --git a/ci_files/variables.yml b/ci_files/variables.yml index 7ed6d75d5..439139396 100644 --- a/ci_files/variables.yml +++ b/ci_files/variables.yml @@ -3,6 +3,7 @@ variables: GITLAB_VERSION: "master" GITLAB_REF_SLUG: "master" GITLAB_ASSETS_TAG: "master" + GITLAB_MONITOR_VERSION: "v4.0.0" GITLAB_SHELL_VERSION: "master" GITLAB_WORKHORSE_VERSION: "master" GITALY_VERSION: "master" diff --git a/gitlab-monitor/Dockerfile b/gitlab-monitor/Dockerfile new file mode 100644 index 000000000..2c4419ac5 --- /dev/null +++ b/gitlab-monitor/Dockerfile @@ -0,0 +1,36 @@ +ARG CI_REGISTRY_IMAGE="registry.gitlab.com/gitlab-org/build/cng" +ARG TAG=latest +ARG FROM_IMAGE="$CI_REGISTRY_IMAGE/gitlab-ruby" +ARG GITLAB_MONITOR_VERSION=v4.0.0 +FROM ${FROM_IMAGE}:${TAG} + +ARG GITLAB_USER=git +ARG BUILD_DIR=/tmp/build +ARG GITLAB_MONITOR_VERSION + +# create gitlab user +# openssh daemon does not allow locked user to login, change ! to * +RUN adduser --disabled-password --gecos 'GitLab' ${GITLAB_USER} && \ + sed -i "s/${GITLAB_USER}:!/${GITLAB_USER}:*/" /etc/shadow + +# install build deps +RUN buildDeps='build-essential libpq-dev git' && \ + apt-get update && \ + apt-get install -y --no-install-recommends $buildDeps && \ + rm -rf /var/lib/apt/lists/* && \ + mkdir -p ${BUILD_DIR} && \ + chown ${GITLAB_USER}:${GITLAB_USER} ${BUILD_DIR} && \ + cd ${BUILD_DIR} && \ + echo "Cloning source code from https://gitlab.com/gitlab-org/gitlab-monitor.git" && \ + git clone --branch ${GITLAB_MONITOR_VERSION} https://gitlab.com/gitlab-org/gitlab-monitor.git && \ + cd gitlab-monitor && \ + gem build gitlab-monitor.gemspec && \ + gem install gitlab-monitor && \ + SUDO_FORCE_REMOVE=yes apt-get purge -y --auto-remove $buildDeps && \ + rm -rf ${BUILD_DIR} + +RUN mkdir -p /etc/gitlab-monitor; chown -R $GITLAB_USER /etc/gitlab-monitor + +USER $GITLAB_USER:$GITLAB_USER + +CMD ["/usr/bin/gitlab-mon", "web", "-c", "/etc/gitlab-monitor/gitlab-monitor.yml"] -- GitLab From f84e84323d5c564ebb782c281dd2bb5c57635bcf Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 12 May 2019 20:23:35 -0500 Subject: [PATCH 2/8] Prevent libpq-dev from being deleted --- gitlab-monitor/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitlab-monitor/Dockerfile b/gitlab-monitor/Dockerfile index 2c4419ac5..c7cc42eb8 100644 --- a/gitlab-monitor/Dockerfile +++ b/gitlab-monitor/Dockerfile @@ -14,9 +14,9 @@ RUN adduser --disabled-password --gecos 'GitLab' ${GITLAB_USER} && \ sed -i "s/${GITLAB_USER}:!/${GITLAB_USER}:*/" /etc/shadow # install build deps -RUN buildDeps='build-essential libpq-dev git' && \ +RUN buildDeps='build-essential git' && \ apt-get update && \ - apt-get install -y --no-install-recommends $buildDeps && \ + apt-get install -y --no-install-recommends $buildDeps libpq-dev && \ rm -rf /var/lib/apt/lists/* && \ mkdir -p ${BUILD_DIR} && \ chown ${GITLAB_USER}:${GITLAB_USER} ${BUILD_DIR} && \ -- GitLab From e11957387e43c9cdd7ae001f09624d55e42c1f82 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 13 May 2019 09:16:02 -0500 Subject: [PATCH 3/8] Set config environment variables It seems on occasion Helm/K8S doesn't appear to pass in these variables, so let's set reasonable defaults. --- gitlab-monitor/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gitlab-monitor/Dockerfile b/gitlab-monitor/Dockerfile index c7cc42eb8..d0619dc1f 100644 --- a/gitlab-monitor/Dockerfile +++ b/gitlab-monitor/Dockerfile @@ -33,4 +33,7 @@ RUN mkdir -p /etc/gitlab-monitor; chown -R $GITLAB_USER /etc/gitlab-monitor USER $GITLAB_USER:$GITLAB_USER +ENV CONFIG_TEMPLATE_DIRECTORY=/var/opt/gitlab-monitor/templates +ENV CONFIG_DIRECTORY=/etc/gitlab-monitor + CMD ["/usr/bin/gitlab-mon", "web", "-c", "/etc/gitlab-monitor/gitlab-monitor.yml"] -- GitLab From 1345344c723733006107cdae2eee3bf4a7fc9c8d Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 17 May 2019 13:35:01 -0700 Subject: [PATCH 4/8] Clean up gitlab-monitor build using a gem --- ci_files/variables.yml | 2 +- gitlab-monitor/Dockerfile | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/ci_files/variables.yml b/ci_files/variables.yml index 439139396..1e9861f61 100644 --- a/ci_files/variables.yml +++ b/ci_files/variables.yml @@ -3,7 +3,7 @@ variables: GITLAB_VERSION: "master" GITLAB_REF_SLUG: "master" GITLAB_ASSETS_TAG: "master" - GITLAB_MONITOR_VERSION: "v4.0.0" + GITLAB_MONITOR_VERSION: "4.0.0" GITLAB_SHELL_VERSION: "master" GITLAB_WORKHORSE_VERSION: "master" GITALY_VERSION: "master" diff --git a/gitlab-monitor/Dockerfile b/gitlab-monitor/Dockerfile index d0619dc1f..3431f25fd 100644 --- a/gitlab-monitor/Dockerfile +++ b/gitlab-monitor/Dockerfile @@ -1,9 +1,10 @@ ARG CI_REGISTRY_IMAGE="registry.gitlab.com/gitlab-org/build/cng" ARG TAG=latest ARG FROM_IMAGE="$CI_REGISTRY_IMAGE/gitlab-ruby" -ARG GITLAB_MONITOR_VERSION=v4.0.0 +ARG GITLAB_MONITOR_VERSION=4.0.0 FROM ${FROM_IMAGE}:${TAG} +# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact ARG GITLAB_USER=git ARG BUILD_DIR=/tmp/build ARG GITLAB_MONITOR_VERSION @@ -14,18 +15,14 @@ RUN adduser --disabled-password --gecos 'GitLab' ${GITLAB_USER} && \ sed -i "s/${GITLAB_USER}:!/${GITLAB_USER}:*/" /etc/shadow # install build deps -RUN buildDeps='build-essential git' && \ +RUN buildDeps='build-essential' && \ apt-get update && \ apt-get install -y --no-install-recommends $buildDeps libpq-dev && \ rm -rf /var/lib/apt/lists/* && \ mkdir -p ${BUILD_DIR} && \ chown ${GITLAB_USER}:${GITLAB_USER} ${BUILD_DIR} && \ cd ${BUILD_DIR} && \ - echo "Cloning source code from https://gitlab.com/gitlab-org/gitlab-monitor.git" && \ - git clone --branch ${GITLAB_MONITOR_VERSION} https://gitlab.com/gitlab-org/gitlab-monitor.git && \ - cd gitlab-monitor && \ - gem build gitlab-monitor.gemspec && \ - gem install gitlab-monitor && \ + gem install gitlab-monitor -v ${GITLAB_MONITOR_VERSION} && \ SUDO_FORCE_REMOVE=yes apt-get purge -y --auto-remove $buildDeps && \ rm -rf ${BUILD_DIR} @@ -35,5 +32,6 @@ USER $GITLAB_USER:$GITLAB_USER ENV CONFIG_TEMPLATE_DIRECTORY=/var/opt/gitlab-monitor/templates ENV CONFIG_DIRECTORY=/etc/gitlab-monitor +ENV CONFIG_FILENAME=gitlab-monitor.yml CMD ["/usr/bin/gitlab-mon", "web", "-c", "/etc/gitlab-monitor/gitlab-monitor.yml"] -- GitLab From f4639538ba47be70e377a1637c396c7e333d6188 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 17 May 2019 13:38:56 -0700 Subject: [PATCH 5/8] Push a tag using the monitor version in CI --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e9dba780d..9b989410d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -289,6 +289,7 @@ gitlab-monitor: --build-arg "FROM_IMAGE=$CI_REGISTRY_IMAGE/gitlab-ruby" --build-arg "TAG=$ruby_version" - push_if_master_or_tag + - push_if_master_or_tag $GITLAB_MONITOR_VERSION dependencies: - gitlab-ruby -- GitLab From 2715aaf97076f7abc6eaa0f9624c3ce2b5c4fcd0 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 17 May 2019 13:47:19 -0700 Subject: [PATCH 6/8] Remove BUILD_DIR and use env variables --- gitlab-monitor/Dockerfile | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/gitlab-monitor/Dockerfile b/gitlab-monitor/Dockerfile index 3431f25fd..c0e18fca0 100644 --- a/gitlab-monitor/Dockerfile +++ b/gitlab-monitor/Dockerfile @@ -6,7 +6,6 @@ FROM ${FROM_IMAGE}:${TAG} # https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact ARG GITLAB_USER=git -ARG BUILD_DIR=/tmp/build ARG GITLAB_MONITOR_VERSION # create gitlab user @@ -19,19 +18,15 @@ RUN buildDeps='build-essential' && \ apt-get update && \ apt-get install -y --no-install-recommends $buildDeps libpq-dev && \ rm -rf /var/lib/apt/lists/* && \ - mkdir -p ${BUILD_DIR} && \ - chown ${GITLAB_USER}:${GITLAB_USER} ${BUILD_DIR} && \ - cd ${BUILD_DIR} && \ gem install gitlab-monitor -v ${GITLAB_MONITOR_VERSION} && \ - SUDO_FORCE_REMOVE=yes apt-get purge -y --auto-remove $buildDeps && \ - rm -rf ${BUILD_DIR} - -RUN mkdir -p /etc/gitlab-monitor; chown -R $GITLAB_USER /etc/gitlab-monitor - -USER $GITLAB_USER:$GITLAB_USER + SUDO_FORCE_REMOVE=yes apt-get purge -y --auto-remove $buildDeps ENV CONFIG_TEMPLATE_DIRECTORY=/var/opt/gitlab-monitor/templates ENV CONFIG_DIRECTORY=/etc/gitlab-monitor ENV CONFIG_FILENAME=gitlab-monitor.yml +RUN mkdir -p ${CONFIG_DIRECTORY}; chown -R $GITLAB_USER ${CONFIG_DIRECTORY} + +USER $GITLAB_USER:$GITLAB_USER + CMD ["/usr/bin/gitlab-mon", "web", "-c", "/etc/gitlab-monitor/gitlab-monitor.yml"] -- GitLab From 482773809ea564ae49dc1493da501381ff405f91 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 18 May 2019 07:04:33 -0700 Subject: [PATCH 7/8] Use environment variables to start gitlab-monitor --- gitlab-monitor/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab-monitor/Dockerfile b/gitlab-monitor/Dockerfile index c0e18fca0..9446500b0 100644 --- a/gitlab-monitor/Dockerfile +++ b/gitlab-monitor/Dockerfile @@ -29,4 +29,4 @@ RUN mkdir -p ${CONFIG_DIRECTORY}; chown -R $GITLAB_USER ${CONFIG_DIRECTORY} USER $GITLAB_USER:$GITLAB_USER -CMD ["/usr/bin/gitlab-mon", "web", "-c", "/etc/gitlab-monitor/gitlab-monitor.yml"] +CMD /usr/bin/gitlab-mon web -c ${CONFIG_DIRECTORY}/${CONFIG_FILENAME} -- GitLab From 94ff0134f45015344f502848dd83e67c5f943f51 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 18 May 2019 07:08:05 -0700 Subject: [PATCH 8/8] Add TARGET_VERSION to gitlab-monitor CI config --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9b989410d..dbc439450 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -284,7 +284,8 @@ gitlab-monitor: stage: phase-two script: - ruby_version=$(get_version gitlab-ruby) - - export CONTAINER_VERSION=($(echo -n "$ruby_version$GITLAB_MONITOR_VERSION" | sha1sum)) + - ruby_container=($(echo -n "$ruby_version$GITLAB_MONITOR_VERSION" | sha1sum)) + - export CONTAINER_VERSION=($(echo -n "$ruby_container$TARGET_VERSION" | sha1sum)) - build_if_needed --build-arg "GITLAB_MONITOR_VERSION=$GITLAB_MONITOR_VERSION" --build-arg "FROM_IMAGE=$CI_REGISTRY_IMAGE/gitlab-ruby" --build-arg "TAG=$ruby_version" -- GitLab