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 #60 from bosch-io/bs-matil/docker-images-backend
Browse files Browse the repository at this point in the history
chores(dockerfiles): New lightweight and improved docker images
  • Loading branch information
mcjaeger authored Sep 28, 2020
2 parents dc81966 + a9d5feb commit 987d841
Show file tree
Hide file tree
Showing 16 changed files with 537 additions and 0 deletions.
57 changes: 57 additions & 0 deletions v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Docker Images for SW360 Project

**This is work in progress**

The goal of the content in this folder is to develop a new and more lightweight deployment, where the SW360 backend is separated from the frontends.
This allows the containers to have a fast startup time and be small.

The long term goal is to merge this with the top level deployment.

This folder is not used by the `../sw360chores.pl` script, but it uses parts of the top level folder `../configuration`.

## Installation
To build all images just run `docker-compose build` in the corresponding directories

alternativly you can run docker build . within any of the folders to build the image manually

### Proxy options

If you need to build the image behind an HTTP proxy you can set the proxy with

```
docker-compose build \
--build-arg http_proxy=http://127.0.0.1:3128 \
--build-arg https_proxy=http://127.0.0.1:3128
or in case of docker native build
docker build \
--build-arg http_proxy=http://127.0.0.1:3128 \
--build-arg https_proxy=http://127.0.0.1:3128 .
```

## Images

### backend

This image will build all componentes in the backend module of sw360 and deploy them into an tomcat (9). If the container is started and the couch db connection was correct the thrift API will be available on port 8080.

### couchdb

A simple couchdb container which has some specific configuration options for sw360 regards the integration with lucene

### couchdb-lucene

A container for the couchdb-lucene project

### maven-thrift

A maven container which has added thrift support. This container is also used to build all sw360 application containers.

## Testing with the "old" image with the liferay frontend
```
$ ( cd /PATH/TO/SW360; mvn package -DskipTests )
$ find /PATH/TO/SW360/frontend -name '*.war' -exec cp -v {} ../_deploy \;
$ docker-compose -f docker-images-backend/docker-compose.yaml -f docker-images-frontend/docker-compose.yaml up
```
After that SW360 can be accessed on `https://localhost:8443`.
2 changes: 2 additions & 0 deletions v2/docker-images-backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Docker Backend Images for SW360 Project

49 changes: 49 additions & 0 deletions v2/docker-images-backend/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright Bosch Software Innovations GmbH, 2017.
# Part of the SW360 Portal Project.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html

ARG REPOSITORY

FROM ${REPOSITORY}sw360/maven-thrift

RUN apk update && apk add git zip
RUN git clone https://github.com/eclipse/sw360.git

#Workaround for MVN_PROXY
ARG MVN_FLAGS="-Dhttp.proxyHost=$(basename $http_proxy | cut -d':' -f1) -Dhttp.proxyPort=$(basename $http_proxy | cut -d':' -f2) -Dhttps.proxyHost=$(basename $http_proxy | cut -d':' -f1) -Dhttps.proxyPort=$(basename $http_proxy | cut -d':' -f2) -Dhttp.nonProxyHosts=localhost"
RUN cd sw360 && \
mvn $(eval echo "${MVN_FLAGS}" ) install -P deploy -Ddeploy.dir=/sw360chores -DskipTests \
-pl '!rest,!rest/rest-common,!rest/authorization-server,!rest/resource-server,!frontend,!frontend/layouttpl,!frontend/sw360-portlet,!frontend/sw360-theme,!libraries/importers/component-importer,!libraries/importers/license-importer'

WORKDIR /sw360chores

COPY create-slim-war-files.sh create-slim-war-files.sh
RUN bash create-slim-war-files.sh

FROM tomcat:9
RUN apt-get update && apt-get install -y gettext patch && rm -rf /var/lib/apt/lists/*

# TOMCAT SETTINGS
COPY catalina.properties.patch /usr/local/tomcat/conf/catalina.properties.patch
RUN cd /usr/local/tomcat/conf/ && patch -b < catalina.properties.patch
RUN sed -i -e 's/<Engine/<Engine startStopThreads="0" /g' -e 's/<Host/<Host startStopThreads="0" /g' /usr/local/tomcat/conf/server.xml
RUN rm -rf /usr/local/tomcat/webapps/*
COPY --from=0 /sw360chores/slim-wars/*.war /usr/local/tomcat/webapps/
COPY --from=0 /sw360chores/libs/*.jar /usr/local/tomcat/shared/

# COUCH DB SETTINGS
ENV COUCHDB_URL="http://172.17.0.1:5984"
ENV COUCHDB_USER=""
ENV COUCHDB_PASSWORD=""
ENV COUCHDB_DBNAME_SW360="sw360db"
ENV COUCHDB_DBNAME_USERDB="sw360users"
ENV COUCHDB_DBNAME_ATTACHMENTS="sw360attachments"
ENV COUCHDB_DBNAME_FOSSOLOGYKEYS="sw360fossologykeys"
ENV COUCHDB_DBNAME_VULNERABILITY_MANAGEMENT="sw360vm"
COPY couchdb.template.properties /etc/sw360/couchdb.properties.template
COPY entrypoint.sh entrypoint.sh
CMD ["bash","entrypoint.sh"]
13 changes: 13 additions & 0 deletions v2/docker-images-backend/backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# thrift based backend
This container contains the thrift http api

## Files
### catalina.properties.patch
patch which mainly contains a list of dependenies which was manully created by combining all *.war files of the backend.

### create-slim-war-files.sh
A script that unpacks all wars and repackes them without lib folders. All libs are collected in one shared lib folder.

### couchdb.template.properties
a couchdb.properties file where all values will be replaced with envorinment variables on startup of the container

100 changes: 100 additions & 0 deletions v2/docker-images-backend/backend/catalina.properties.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright Bosch Software Innovations GmbH, 2019.
# Part of the SW360 Portal Project.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html

--- catalina.properties 2019-02-27 21:38:55.297749700 +0100
+++ catalina.properties 2019-02-27 21:35:55.043246200 +0100
@@ -87,7 +87,7 @@
# ${catalina.base} path or the ${catalina.home} path contains a comma.
# Because double quotes are used for quoting, the double quote character
# may not appear in a path.
-shared.loader=
+shared.loader=shared/*.jar

# Default list of JAR files that should not be scanned using the JarScanner
# functionality. This is typically used to scan JARs for configuration
@@ -191,7 +191,79 @@
xml-apis.jar,\
xmlParserAPIs-*.jar,\
xmlParserAPIs.jar,\
-xom-*.jar
+xom-*.jar,\
+activation-*.jar, \
+annotations-*.jar, \
+antlr-*.jar, \
+antlr-*.jar, \
+antlr-runtime-*.jar, \
+arq-*.jar, \
+asm-*.jar, \
+cglib-*.jar, \
+commons-beanutils-*.jar, \
+commons-codec-*.jar, \
+commons-collections-*.jar, \
+commons-collections*.jar, \
+commons-csv-*.jar, \
+commons-digester*.jar, \
+commons-io-*.jar, \
+commons-lang-*.jar, \
+commons-lang3-*.jar, \
+commons-logging-*.jar, \
+compiler*.jar, \
+curvesapi-*.jar, \
+ektorplucene-*.jar, \
+findbugs-annotations-*.jar, \
+gson-*.jar, \
+guava-*.jar, \
+htmlparser-*.jar, \
+httpclient-*.jar, \
+httpclient-cache-*.jar, \
+httpcore-*.jar, \
+icu4j-*.jar, \
+iri-*.jar, \
+jackson-annotations-*.jar, \
+jackson-core-*.jar, \
+jackson-databind-*.jar, \
+JavaEWAH-*.jar, \
+java-rdfa-*.jar, \
+jcl-over-slf4j-*.jar, \
+jena-*.jar, \
+joda-time-*.jar, \
+jsch-*.jar, \
++json-simple-*.jar, \
+jsoup-*.jar, \
+libthrift-*.jar, \
+log4j-*.jar, \
+lucene-core-*.jar, \
+mail-*.jar, \
+opencsv-*.jar, \
+org.eclipse.jgit-*.jar, \
+org.ektorp-*.jar, \
+poi-*.jar, \
+poi-*.jar, \
+poi-ooxml-*.jar, \
+poi-ooxml-schemas-*.jar, \
+saxon-*.jar, \
+saxon-dom-*.jar, \
+slf4j-api-*.jar, \
+slf4j-log4j12-*.jar, \
+spdx-tools-*.jar, \
+spring-aop-*.RELEASE.jar, \
+spring-beans-*.RELEASE.jar, \
+spring-context-*.RELEASE.jar, \
+spring-core-*.RELEASE.jar, \
+spring-expression-*.RELEASE.jar, \
+spring-web-*.RELEASE.jar, \
+spring-webmvc-*.RELEASE.jar, \
+ST4-*.jar, \
+stax-api-*.jar, \
+stringtemplate-*.jar, \
+velocity-engine-core-*.jar, \
+velocity-tools-generic-*.jar, \
+wstx-asl-*.jar, \
+xercesImpl-*.jar, \
+xmlbeans-*.jar

# Default list of JAR files that should be scanned that overrides the default
# jarsToSkip list above. This is typically used to include a specific JAR that
18 changes: 18 additions & 0 deletions v2/docker-images-backend/backend/couchdb.template.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright Bosch Software Innovations GmbH, 2019.
# Part of the SW360 Portal Project.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html

couchdb.url = $COUCHDB_URL
couchdb.user = $COUCHDB_USER
couchdb.password = $COUCHDB_PASSWORD
couchdb.database = $COUCHDB_DBNAME_SW360
couchdb.usersdb = $COUCHDB_DBNAME_USERDB
couchdb.attachments = $COUCHDB_DBNAME_ATTACHMENTS
couchdb.fossologyKeys = $COUCHDB_DBNAME_FOSSOLOGYKEYS
couchdb.vulnerability_management = $COUCHDB_DBNAME_VULNERABILITY_MANAGEMENT


30 changes: 30 additions & 0 deletions v2/docker-images-backend/backend/create-slim-war-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Copyright Bosch Software Innovations GmbH, 2019.
# Part of the SW360 Portal Project.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html

set -e

rm -rf libs
mkdir libs
rm -rf slim-wars
mkdir slim-wars
for i in $(ls *.war)
do
i=${i%.war}
echo repacking $i ...
rm -rf $i
mkdir $i
cd $i
unzip -q ../$i.war
find WEB-INF/lib ! \( -name "*${i}*" -o -name "*commonIO-*" -o -name "*datahandler-*" -o -name "*src-vulnerabilities-*" -o -name "*src-attachments-*" -o -name "*exporters-*" -o -name "*licenses-*" -o -name "*-common-*" -o -name "*build-configuration-*" \) -type f -exec mv {} ../libs/ \;
zip -q -r ../slim-wars/$i.war .
cd ..
rm -rf $i
echo done
done
12 changes: 12 additions & 0 deletions v2/docker-images-backend/backend/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# Copyright Bosch Software Innovations GmbH, 2019.
# Part of the SW360 Portal Project.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html

envsubst < /etc/sw360/couchdb.properties.template > /etc/sw360/couchdb.properties

exec catalina.sh run
37 changes: 37 additions & 0 deletions v2/docker-images-backend/couchdb-lucene/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright Bosch Software Innovations GmbH, 2016.
# Part of the SW360 Portal Project.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html


FROM maven:3-jdk-8-alpine
ENV BRANCH="v2.1.0"
RUN apk update && apk add git
RUN git clone --branch $BRANCH --depth 1 https://github.com/rnewson/couchdb-lucene

#Workaround for MVN_PROXY
ARG MVN_FLAGS="-Dhttp.proxyHost=$(basename $http_proxy | cut -d':' -f1) -Dhttp.proxyPort=$(basename $http_proxy | cut -d':' -f2) -Dhttps.proxyHost=$(basename $http_proxy | cut -d':' -f1) -Dhttps.proxyPort=$(basename $http_proxy | cut -d':' -f2) -Dhttp.nonProxyHosts=localhost"
RUN cd couchdb-lucene && mvn $(eval echo "${MVN_FLAGS}" )


FROM java:openjdk-8-jre-alpine

ARG TARGET="couchdb-lucene-2.1.0-dist.zip"
MAINTAINER [email protected]

WORKDIR /
COPY --from=0 /couchdb-lucene/target/${TARGET} /
RUN set -ex \
&& apk add --update unzip \
&& unzip /${TARGET} \
&& apk del unzip \
&& mv /couchdb-lucene-2.1.0 /couchdb-lucene

EXPOSE 5985
COPY docker-entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["/couchdb-lucene/bin/run"]
33 changes: 33 additions & 0 deletions v2/docker-images-backend/couchdb-lucene/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh

# Copyright Bosch Software Innovations GmbH, 2016.
# Part of the SW360 Portal Project.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html

set -e

if [ ! "$COUCHDB_HOST" ]; then
echo "the environmental variable \$COUCHDB_HOST must be set"
exit 1
fi

if [ ! "$COUCHDB_USER" ]; then
echo "the environmental variable \$COUCHDB_USER must be set"
exit 1
fi

if [ ! "$COUCHDB_PASSWORD" ]; then
echo "the environmental variable \$COUCHDB_PASSWORD must be set"
exit 1
fi

COUCHDB_HOST="${COUCHDB_USER}:${COUCHDB_PASSWORD}@${COUCHDB_HOST:-couchdb}";

sed -i -r 's/^url.*=.*/url = http:\/\/'"$COUCHDB_HOST:${COUCHDB_PORT:-5984}"'/' "/couchdb-lucene/conf/couchdb-lucene.ini";
sed -i -r 's/^host.*=.*/host = 0.0.0.0/' "/couchdb-lucene/conf/couchdb-lucene.ini";
exec /couchdb-lucene/bin/run;
exec "$@"
18 changes: 18 additions & 0 deletions v2/docker-images-backend/couchdb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright Bosch Software Innovations GmbH, 2019.
# Part of the SW360 Portal Project.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html

FROM couchdb:1.7.1
MAINTAINER [email protected]

RUN mkdir /initial-data

COPY docker-entrypoint.overlay.sh /docker-entrypoint.overlay.sh
run chmod +x /docker-entrypoint.overlay.sh \
&& mkdir -p /usr/local/etc/couchdb/
ENTRYPOINT ["tini", "--", "/docker-entrypoint.overlay.sh"]
CMD ["couchdb"]
Loading

0 comments on commit 987d841

Please sign in to comment.