From bd3ce3e4b23b750ff0344ca7278d63533d1103a1 Mon Sep 17 00:00:00 2001 From: Dylan Hardison Date: Mon, 7 Sep 2020 14:27:36 -0400 Subject: [PATCH 1/3] simplify dockerfile as much as possible --- Bugzilla/WebService/Bug.pm | 34 +++++++++++++------ Dockerfile | 68 ++++++++++++++++++++++++-------------- 2 files changed, 67 insertions(+), 35 deletions(-) diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index 5309f8bb14..2ca88cf850 100644 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -110,15 +110,27 @@ use constant ATTACHMENT_MAPPED_RETURNS => { mimetype => 'content_type', }; -our %api_field_types = ( - %{{map { $_ => 'double' } Bugzilla::Bug::NUMERIC_COLUMNS()}}, - %{{map { $_ => 'dateTime' } Bugzilla::Bug::DATE_COLUMNS()}}, -); +sub api_field_types { + state $api_field_types = { + %{{map { $_ => 'double' } Bugzilla::Bug::NUMERIC_COLUMNS()}}, + %{{map { $_ => 'dateTime' } Bugzilla::Bug::DATE_COLUMNS()}}, + }; + return $api_field_types; +} + -our %api_field_names = reverse %{Bugzilla::Bug::FIELD_MAP()}; -# This doesn't normally belong in FIELD_MAP, but we do want to translate -# "bug_group" back into "groups". -$api_field_names{'bug_group'} = 'groups'; +sub api_field_names { + state $api_field_names; + + return $api_field_names if $api_field_names; + $api_field_names = {reverse %{Bugzilla::Bug::FIELD_MAP()}}; + + # This doesn't normally belong in FIELD_MAP, but we do want to translate + # "bug_group" back into "groups". + $api_field_names->{'bug_group'} = 'groups'; + + return $api_field_names; +} ###################################################### # Add aliases here for old method name compatibility # @@ -838,7 +850,7 @@ sub update { my %changes = %{$all_changes{$bug->id}}; foreach my $field (keys %changes) { my $change = $changes{$field}; - my $api_field = $api_field_names{$field} || $field; + my $api_field = api_field_names->{$field} || $field; # We normalize undef to an empty string, so that the API # stays consistent for things like Deadline that can become @@ -1755,8 +1767,8 @@ sub _changeset_to_hash { foreach my $change (@{$changeset->{changes}}) { my $field_name = delete $change->{fieldname}; - my $api_field_type = $api_field_types{$field_name} || 'string'; - my $api_field_name = $api_field_names{$field_name} || $field_name; + my $api_field_type = api_field_types->{$field_name} || 'string'; + my $api_field_name = api_field_names->{$field_name} || $field_name; my $attach_id = delete $change->{attachid}; my $comment = delete $change->{comment}; diff --git a/Dockerfile b/Dockerfile index 653c48fe5a..e6ce8dbcbb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,39 +1,59 @@ -FROM mozillabteam/bmo-perl-slim:20200505.1 +FROM perl:5.32-slim AS builder ENV DEBIAN_FRONTEND noninteractive - -ARG CI -ARG CIRCLE_SHA1 -ARG CIRCLE_BUILD_URL - -ENV CI=${CI} -ENV CIRCLE_BUILD_URL=${CIRCLE_BUILD_URL} -ENV CIRCLE_SHA1=${CIRCLE_SHA1} - ENV LOG4PERL_CONFIG_FILE=log4perl-json.conf -RUN apt-get install -y rsync +RUN apt-get update +RUN apt-get install -y \ + apt-file \ + build-essential \ + cmake \ + curl \ + default-libmysqlclient-dev \ + git \ + libcairo-dev \ + libexpat-dev \ + libgd-dev \ + libssl-dev \ + openssl \ + zlib1g-dev + +RUN cpanm --notest --quiet App::cpm Module::CPANfile Carton::Snapshot # we run a loopback logging server on this TCP port. ENV LOGGING_PORT=5880 -ENV LOCALCONFIG_ENV=1 +WORKDIR /opt/bugzilla +COPY cpanfile cpanfile.snapshot /opt/bugzilla/ +RUN cpm install -WORKDIR /app -COPY . /app +RUN apt-file update +RUN find local -name '*.so' -exec ldd {} \; \ + | egrep -v 'not.found|not.a.dynamic.executable' \ + | awk '$3 {print $3}' \ + | sort -u \ + | xargs -IFILE apt-file search -l FILE \ + | sort -u > PACKAGES -RUN chown -R app.app /app && \ - perl -I/app -I/app/local/lib/perl5 -c -E 'use Bugzilla; BEGIN { Bugzilla->extensions }' && \ - perl -c /app/scripts/entrypoint.pl +FROM perl:5.32-slim -USER app +WORKDIR /opt/bugzilla +COPY --from=builder /opt/bugzilla/PACKAGES /PACKAGES +RUN apt-get update \ + && apt-get install -y \ + curl \ + git \ + graphviz \ + libcap2-bin \ + rsync \ + $(cat /PACKAGES) \ + && rm -rf /var/cache/apt/* /var/lib/apt/lists/* /PACKAGES -RUN perl checksetup.pl --no-database --default-localconfig && \ - rm -rf /app/data /app/localconfig && \ - mkdir /app/data +COPY . /opt/bugzilla +COPY --from=builder /opt/bugzilla/local /opt/bugzilla/local +RUN perl checksetup.pl --no-database --default-localconfig --no-templates -EXPOSE 8000 +VOLUME ["/opt/bugzilla/data", "/opt/bugzilla/graphs"] -ENTRYPOINT ["/app/scripts/entrypoint.pl"] -CMD ["httpd"] +ENTRYPOINT ["/opt/bugzilla/bugzilla.pl"] From 853bfdb7508544cfb6b14d3e79c304e495987cfb Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Sat, 2 Apr 2022 15:55:35 +0000 Subject: [PATCH 2/3] Dockerfile: Run with database Set up a minimal configuration to get web functionality. This involves specifying a dummy urlbase, an SQLite database, and credentials for the admin user. The initial admin password is randomly generated and printed during the build, or can be retrieved from the Dockerfile by printing the admin-password.txt file. --- Dockerfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e6ce8dbcbb..17269767c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,7 +52,13 @@ RUN apt-get update \ COPY . /opt/bugzilla COPY --from=builder /opt/bugzilla/local /opt/bugzilla/local -RUN perl checksetup.pl --no-database --default-localconfig --no-templates +RUN dd if=/dev/urandom bs=12 count=1 | base64 > admin-password.txt && echo "Generated admin password: $(cat admin-password.txt)" +RUN { \ + printf '$answer{"urlbase"} = "http://localhost/";\n' ; \ + printf '$answer{"db_driver"} = "sqlite";\n' ; \ + printf '$answer{"ADMIN_EMAIL"} = "bugzilla-admin\\@bugzilla.local";\n' ; \ + printf '$answer{"ADMIN_PASSWORD"} = "%s";\n' "$(cat admin-password.txt)" ; \ + } | perl checksetup.pl --default-localconfig --no-templates /dev/stdin VOLUME ["/opt/bugzilla/data", "/opt/bugzilla/graphs"] From eb5c739911ee58db3b66b898c82afe78a67e132a Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Tue, 3 May 2022 13:43:37 +0000 Subject: [PATCH 3/3] Dockerfile: Also set ADMIN_REALNAME --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 17269767c8..ef958dba9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,6 +57,7 @@ RUN { \ printf '$answer{"urlbase"} = "http://localhost/";\n' ; \ printf '$answer{"db_driver"} = "sqlite";\n' ; \ printf '$answer{"ADMIN_EMAIL"} = "bugzilla-admin\\@bugzilla.local";\n' ; \ + printf '$answer{"ADMIN_REALNAME"} = "Administrator";\n' ; \ printf '$answer{"ADMIN_PASSWORD"} = "%s";\n' "$(cat admin-password.txt)" ; \ } | perl checksetup.pl --default-localconfig --no-templates /dev/stdin