Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #80 from bosch-io/oheger-bosch/#79_feat_docker_net…
Browse files Browse the repository at this point in the history
…work_host

Improve proxy support
  • Loading branch information
mcjaeger committed Sep 28, 2020
2 parents 987d841 + 2b7e8a2 commit 4b1e37a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ _*
.idea
*.war
/miscellaneous/prepare-liferay/downloads
/configuration/proxy.env
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ configuration
│   ├── nginx.pem
│   └── regenerateCerts.sh
├── POSTGRES_PASSWORD
├── proxy.env
├── proxy.env.template
└── sw360
├── sw360.env
├── fossology
Expand Down Expand Up @@ -97,8 +97,11 @@ There is also the file `./configuration/nginx/regenerateCerts.sh`, which is used
#### The file `./configuration/POSTGRES_PASSWORD`
This file just contains the password for postgres and it is added as secret to the containers.

#### The file `./configuration/proxy.env`
Here one can add proxy settings, which are passed to all docker-compose calls and into the containers, which need to connect to the internet.
#### The file `./configuration/proxy.env.template`
This is a template file for configuring proxy settings. To enable support for a proxy, copy this file to a file named `proxy.env` (in
the same folder). In `proxy.env` one can add proxy settings, which are passed to all docker-compose calls and into the containers, which need to connect to the internet.

_Note:_ The file `proxy.env` is excluded from source control; so it is not shown as outgoing changes.

#### The folder `./configuration/sw360/`

Expand Down
7 changes: 6 additions & 1 deletion configuration/proxy.env → configuration/proxy.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html

# Template for a proxy configuration file. This file provides a
# common environment for adding proxy settings, sourced by containers which need
# to talk to the outside while running
# to talk to the outside while running.
# In order to activate proxy settings, create a copy of this template under the
# name 'proxy.env' and adapt the properties according to your needs.
# (The file proxy.env is excluded from version control; so a 'git status'
# command will show no modifications.)

#proxy_host=myproxy.example.invalid
#proxy_port=8080
Expand Down
29 changes: 26 additions & 3 deletions docker-images/couchdb-lucene/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,22 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
BRANCH="v2.1.0"
TARGET="couchdb-lucene-2.1.0-dist.zip"

if [[ $1 == "--cleanup" ]]; then
CLEANUP=false
NO_DOCKER=false
NET_HOST=false

for arg in "$@"
do
if [[ $arg == "--cleanup" ]]; then
CLEANUP=true
elif [[ $arg == "build-without-docker" ]]; then
NO_DOCKER=true
elif [[ $arg == "--net-host" ]]; then
NET_HOST=true
fi
done

if [[ "$CLEANUP" == true ]]; then
if [ -f "$TARGET" ]; then
rm "$TARGET"
fi
Expand All @@ -31,9 +46,12 @@ if [ ! -f "$DIR/$TARGET" ]; then
TMP=$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXX)
git clone --branch $BRANCH --depth 1 https://github.com/rnewson/couchdb-lucene "$TMP/couchdb-lucene.git"

cmdMvn="mvn -DskipTests -Dhttp.proxyHost=$proxy_host -Dhttp.proxyPort=$proxy_port -Dhttps.proxyHost=$proxy_host -Dhttps.proxyPort=$proxy_port -Dhttp.nonProxyHosts=localhost"
cmdMvn="mvn -DskipTests "
if [ "$NET_HOST" -eq false ] || [ "$NO_DOCKER" -eq true ]; then
cmdMvn="$cmdMvn -Dhttp.proxyHost=$proxy_host -Dhttp.proxyPort=$proxy_port -Dhttps.proxyHost=$proxy_host -Dhttps.proxyPort=$proxy_port -Dhttp.nonProxyHosts=localhost"
fi
echo "DEBUG: $cmdMvn"
if [[ $1 == "build-without-docker" ]]; then
if [[ "$NO_DOCKER" == true ]]; then
(
cd "$TMP/couchdb-lucene.git"
$cmdMvn
Expand All @@ -45,13 +63,18 @@ if [ ! -f "$DIR/$TARGET" ]; then
}
}

paramHost=""
if [ "$NET_HOST" == true ]; then
paramHost="--net=host"
fi
cmdDocker="$(addSudoIfNeeded) docker"
$cmdDocker pull maven:3-jdk-8-alpine
$cmdDocker run -i \
--cap-drop=all --user "${UID}" \
-v "$TMP/couchdb-lucene.git:/couchdb-lucene" \
--env MAVEN_CONFIG=/tmp/ \
-w /couchdb-lucene \
$paramHost \
maven:3-jdk-8-alpine \
$cmdMvn -Dmaven.repo.local=/tmp/m2/repository
fi
Expand Down
22 changes: 20 additions & 2 deletions sw360chores.pl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ =head1 SYNOPSIS
./sw360chores.pl --prod [options] [-- arguments for docker-compose]
## enable cve-search server
./sw360chores.pl --cve-search [options] [-- arguments for docker-compose]
## enable network=host when building docker images:
./sw360chores.pl --net-host [options] [-- arguments for docker-compose]
# evironmental variables
$SW360CHORES_VERSION
Expand Down Expand Up @@ -86,6 +88,7 @@ =head1 SYNOPSIS
my $backupDir = '';
my $restoreDir = '';
my $debug = '';
my $netHost = '';

{ # parse config and read command line arguments
my $configFile = "./configuration/configuration.pl";
Expand Down Expand Up @@ -135,7 +138,8 @@ =head1 SYNOPSIS
},
# misc
'help' => sub {pod2usage();},
'debug' => \$debug
'debug' => \$debug,
'net-host' => \$netHost
) or pod2usage();
}
$ENV{COMPOSE_PROJECT_NAME} = $projectName;
Expand All @@ -155,6 +159,7 @@ =head1 SYNOPSIS
say STDERR " \$cpDeployDir = " . ($cpDeployDir // "<undefined>");
say STDERR " \$backupDir = $backupDir";
say STDERR " \$restoreDir = $restoreDir";
say STDERR " \$netHost = $netHost";
say STDERR " \$debug = $debug";
say STDERR " environmental variables:";
say STDERR " SW360CHORES_VERSION = $ENV{SW360CHORES_VERSION}" if defined($ENV{SW360CHORES_VERSION});
Expand All @@ -164,6 +169,12 @@ =head1 SYNOPSIS
say STDERR " \@ARGV = @ARGV";
}

# create proxy.env file from template if it does not exist yet
if (not -e "configuration/proxy.env") {
say "INFO: creating proxy.env from template.";
copy ("configuration/proxy.env.template", "configuration/proxy.env");
}

################################################################################
my $imagesSrcDir = "./docker-images";
my $saveDir = "./_images";
Expand Down Expand Up @@ -305,6 +316,9 @@ =head1 SYNOPSIS
unshift(@args, ("--build-arg", "https_proxy=$ENV{'https_proxy'}")) if (defined $ENV{"https_proxy"});
unshift(@args, ("--build-arg", "no_proxy=$ENV{'no_proxy'}")) if (defined $ENV{"no_proxy"});

if($netHost) {
unshift(@args, "--network=host")
}
unshift(@args, ("build", "-t", "sw360/$name", "--rm=true", "--force-rm=true"));
push @args, "$imagesSrcDir/$name/";

Expand Down Expand Up @@ -377,7 +391,11 @@ sub prepareImage {
if (-x $prepareScriptPl) {
do $prepareScriptPl;
} elsif (-x $prepareScriptSh) {
0 == system($prepareScriptSh)
my @cmd = ($prepareScriptSh);
if($netHost) {
push @cmd, ("--net-host");
}
0 == system(@cmd)
or die "failed to prepare $name";
}
}
Expand Down

0 comments on commit 4b1e37a

Please sign in to comment.