81 lines
2.7 KiB
Docker
Raw Normal View History

# Copyright (c) 2019 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Mon Mar 27 15:13:11 UTC 2023 - trigger rebuild
FROM docker.io/opendevorg/python-builder:3.9-bullseye as builder
COPY . /tmp/src
RUN assemble
FROM docker.io/opendevorg/python-base:3.9-bullseye as gerrit-base
RUN echo 'APT::Install-Recommends "0";' > /etc/apt/apt.conf.d/95disable-recommends
RUN apt-get update \
&& apt-get install -y dumb-init git openssh-client openjdk-11-jdk-headless unzip \
# This next set of installs helps align us with the old openjdk image \
# but they may not all be necessary \
&& apt-get install -y xz-utils bzip2 wget curl gnupg \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /output/ /output
RUN /output/install-from-bindep
# 3000 is what the existing opendev gerrit2 uid is
RUN addgroup gerrit --gid 3000 --system \
&& adduser \
--system \
--uid 3000 \
--home /var/gerrit \
--shell /bin/bash \
--ingroup gerrit \
gerrit
gerrit: add mariadb_container option This adds a local mariadb container to the gerrit host to hold the accountPatchReviewDb database. This is inspired by a few things - since migration to NoteDB, there is only one table left where Gerrit records what files have been reviewed for a change. This logically scales with the number of reviews users are doing. Pulling the stats on this, we can see since the NoteDB upgrade this went from a very busy database (~300 queries/70 commits per second) to barely registering one hit per second : https://imgur.com/a/QGJV7Fw Thus separating the db to an external host for performance reasons is not a large concern any more. - emperically we've done a bad job in keeping the existing hosted db up-to-date; it's still running mysql 5.1 and we have been hit by bugs such as the one referenced in-line which silently drops backups. - The other gerrit option is to use an on-disk H2 database. This is certainly an option, however you need special tools to interact with it for migration, etc. and it's not safe to backup from files on disk (as opposed to mysqldump). Upstream advice is unclear, and varies between H2 being a performance bottleneck to this being ephemeral data that users don't care about. We know how to admin mariadb/mysql and this allows us to migrate and backup data, so seems like the best choice. - we have a pressing need to update the server to a new operating system. Running the db alongside the gerrit instance minimises fiddling we have to do manging connections to and migrating the hosted db systems. - related to that, we are tending towards more provider independence for control-plane servers. A hosted database product is not always provided, so this gives us more flexibility in moving things around. - the main concern here is memory usage. "docker stats" reports a quiescent container, freshly started on a 8GB host: gerrit-compose_mariadb_1 67.32MiB After loading a copy of the production table, and then dumping it back to a file the same container reports: gerrit-compose_mariadb_1 462.6MiB The existing remote mysql configuration path remains mostly the same. We move the gerrit startup into a script rather than a CMD so we can call it after a "wait for db" script in the mariadb_container case (this is the reccommeded way to enforce ordering [1]). Backups of the local container need different dump commands; backups are relocated to a new file and updated. Testing is converted to use this rather than a local H2 database. [1] https://docs.docker.com/compose/startup-order/ Change-Id: Iec981ef3c2e38889f91e9759e66295dbfb499c2e
2021-02-17 15:23:19 +11:00
# Startup scripts
COPY wait-for-it.sh /wait-for-it.sh
RUN chmod +x /wait-for-it.sh
COPY run-gerrit.sh /run-gerrit.sh
RUN chmod +x /run-gerrit.sh
USER gerrit
RUN mkdir /var/gerrit/bin \
&& mkdir /var/gerrit/hooks \
&& mkdir /var/gerrit/static
# Download mariadb java client.
# Modern gerrit stopped downloading missing libs during init which means we
# need to do the downland and install ourselves.
# Note the perms on this are 0600 hence the need for the chown otherwise
# they are root owned and Gerrit can't use the jdbc driver.
ADD --chown=gerrit:gerrit https://repo1.maven.org/maven2/org/mariadb/jdbc/mariadb-java-client/2.7.2/mariadb-java-client-2.7.2.jar /var/gerrit/lib/mariadb-java-client.jar
Base 2.13 image on gerrit-base We install jeepyb and launchpadlib in gerrit-base. Those are important. We also need to add cgi for gitweb. The gerrit init command does two things that we don't actually want it to do at runtime. It extracts the plugins into the plugins dir, and it downloads the right database library. We can extract the plugins for it during image creation, and then we can also download the plugin it would have downloaded. We can also download the mysql library for it: https://gerrit.googlesource.com/gerrit/+/refs/heads/stable-2.13/gerrit-pgm/src/main/resources/com/google/gerrit/pgm/init/libraries.config Finally, we tell it to not download or expand anything during init, because we're running in a container and next time we run the process that dir isn't going to be there. Our gerrit integration tests don't depend on our gerrit image builds. Put in image depends between run-review and gerrit builds. We also need to depend directly on opendev-buildset-registry. Add java.security.egd setting to java invocation This tells java to be secure. https://stackoverflow.com/questions/58991966/what-java-security-egd-option-is-for Add support for setting heap limit properly The gerrit init script does this based on the value in container.javaOptions. We could, but then we'd have to run an entrypoint script. Instead, set the value via the JAVA_OPTIONS env var setting based on a value from ansible. Finally, make gerrit-master image build non-voting It looks like there might be a real issue, but debugging that is not important for us at this moment. Depends-On: https://review.opendev.org/714216 Change-Id: I01e94c10f470fb3c8ddfce7b0e201357e5050679
2020-03-20 09:41:23 -05:00
# Allow incoming traffic
# OpenDev Gerrit listens on 8081 not default of 8080
EXPOSE 29418 8081
VOLUME /var/gerrit/git /var/gerrit/index /var/gerrit/cache /var/gerrit/db /var/gerrit/etc /var/log/gerrit /var/gerrit/tmp /var/gerrit/data
RUN ln -s /var/log/gerrit /var/gerrit/logs
# container.javaOptions
# Also include container.heapLimit - but with -Xmx prefixing it
ENV JAVA_OPTIONS ""
# Ulimits should be set on command line or in docker-compose.yaml
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
gerrit: add mariadb_container option This adds a local mariadb container to the gerrit host to hold the accountPatchReviewDb database. This is inspired by a few things - since migration to NoteDB, there is only one table left where Gerrit records what files have been reviewed for a change. This logically scales with the number of reviews users are doing. Pulling the stats on this, we can see since the NoteDB upgrade this went from a very busy database (~300 queries/70 commits per second) to barely registering one hit per second : https://imgur.com/a/QGJV7Fw Thus separating the db to an external host for performance reasons is not a large concern any more. - emperically we've done a bad job in keeping the existing hosted db up-to-date; it's still running mysql 5.1 and we have been hit by bugs such as the one referenced in-line which silently drops backups. - The other gerrit option is to use an on-disk H2 database. This is certainly an option, however you need special tools to interact with it for migration, etc. and it's not safe to backup from files on disk (as opposed to mysqldump). Upstream advice is unclear, and varies between H2 being a performance bottleneck to this being ephemeral data that users don't care about. We know how to admin mariadb/mysql and this allows us to migrate and backup data, so seems like the best choice. - we have a pressing need to update the server to a new operating system. Running the db alongside the gerrit instance minimises fiddling we have to do manging connections to and migrating the hosted db systems. - related to that, we are tending towards more provider independence for control-plane servers. A hosted database product is not always provided, so this gives us more flexibility in moving things around. - the main concern here is memory usage. "docker stats" reports a quiescent container, freshly started on a 8GB host: gerrit-compose_mariadb_1 67.32MiB After loading a copy of the production table, and then dumping it back to a file the same container reports: gerrit-compose_mariadb_1 462.6MiB The existing remote mysql configuration path remains mostly the same. We move the gerrit startup into a script rather than a CMD so we can call it after a "wait for db" script in the mariadb_container case (this is the reccommeded way to enforce ordering [1]). Backups of the local container need different dump commands; backups are relocated to a new file and updated. Testing is converted to use this rather than a local H2 database. [1] https://docs.docker.com/compose/startup-order/ Change-Id: Iec981ef3c2e38889f91e9759e66295dbfb499c2e
2021-02-17 15:23:19 +11:00
CMD "/run-gerrit.sh"