diff options
author | Dylan William Hardison <dylan@hardison.net> | 2017-07-03 21:09:44 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2017-07-07 00:19:20 +0200 |
commit | e3e2c7c0273499f832ee692ca63620cd8aa8bda1 (patch) | |
tree | eda6812f189ae6a6e682ceb30181d902a9ddc2b1 /docker_files/init.pl | |
parent | 5eab2f4864c28ab945f92800c3294e968dd01428 (diff) | |
download | bugzilla-e3e2c7c0273499f832ee692ca63620cd8aa8bda1.tar.gz bugzilla-e3e2c7c0273499f832ee692ca63620cd8aa8bda1.tar.xz |
Bug 1361439 - Create dockerflow-compliant container that runs a BMO web head
Diffstat (limited to 'docker_files/init.pl')
-rwxr-xr-x | docker_files/init.pl | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/docker_files/init.pl b/docker_files/init.pl new file mode 100755 index 000000000..6e7a8920b --- /dev/null +++ b/docker_files/init.pl @@ -0,0 +1,81 @@ +#!/usr/bin/perl +use strict; +use warnings; +use lib qw(/app /opt/bmo/local/lib/perl5); +use Getopt::Long qw(:config gnu_getopt); +use Data::Dumper; +use Bugzilla::Install::Localconfig (); +use Bugzilla::Install::Util qw(install_string); + +my %localconfig = (webservergroup => 'app'); + +my %override = ( + 'inbound_proxies' => 1, + 'memcached_namespace' => 1, + 'memcached_servers' => 1, + 'shadowdb' => 1, + 'shadowdbhost' => 1, + 'shadowdbport' => 1, + 'shadowdbsock' => 1 +); + +# clean env. +foreach my $key (keys %ENV) { + if ($key =~ /^BMO_(.+)$/) { + my $name = $1; + if ($override{$name}) { + $localconfig{param_override}{$name} = delete $ENV{$key}; + } + else { + $localconfig{$name} = delete $ENV{$key}; + } + } +} + +write_localconfig(\%localconfig); +system("perl", "checksetup.pl", "--no-templates", "--no-permissions", '--no-assets'); + +my $cmd = shift @ARGV or die "usage: init.pl CMD"; +my $method = "run_$cmd"; +__PACKAGE__->$method(); + +sub run_httpd { + exec("/usr/sbin/httpd", "-DFOREGROUND", "-f", "/opt/bmo/httpd/httpd.conf"); +} + +sub run_shell { + exec("/bin/bash", "-l"); +} + +sub write_localconfig { + my ($localconfig) = @_; + no warnings 'once'; + + foreach my $var (Bugzilla::Install::Localconfig::LOCALCONFIG_VARS) { + my $name = $var->{name}; + my $value = $localconfig->{$name}; + if (!defined $value) { + $var->{default} = &{$var->{default}} if ref($var->{default}) eq 'CODE'; + $localconfig->{$name} = $var->{default}; + } + } + + my $filename = "/app/localconfig"; + + # Ensure output is sorted and deterministic + local $Data::Dumper::Sortkeys = 1; + + # Re-write localconfig + open my $fh, ">:utf8", $filename or die "$filename: $!"; + foreach my $var (Bugzilla::Install::Localconfig::LOCALCONFIG_VARS) { + my $name = $var->{name}; + my $desc = install_string("localconfig_$name", { root => Bugzilla::Install::Localconfig::ROOT_USER }); + chomp($desc); + # Make the description into a comment. + $desc =~ s/^/# /mg; + print $fh $desc, "\n", + Data::Dumper->Dump([$localconfig->{$name}], + ["*$name"]), "\n"; + } + close $fh; +} |