From e4a5a12ec9ad7dbd5cd574d172101ddf3805b9ef Mon Sep 17 00:00:00 2001 From: Mustapha Zorgati <15628173+mustaphazorgati@users.noreply.github.com> Date: Wed, 14 Apr 2021 16:44:38 +0200 Subject: [PATCH] TSK-1619: added Dockerfile for our db2 image --- .github/workflows/continuous-integration.yml | 4 +- .gitignore | 3 + docker-databases/db2_11-1/Dockerfile | 74 ++++++++++++ docker-databases/db2_11-1/README.md | 5 + docker-databases/db2_11-1/entrypoint.sh | 105 ++++++++++++++++++ {ci => docker-databases}/docker-compose.yml | 4 +- .../postgres_10}/Dockerfile | 0 {ci => docker-databases}/prepare_db.bat | 0 {ci => docker-databases}/prepare_db.sh | 11 +- 9 files changed, 200 insertions(+), 6 deletions(-) create mode 100644 docker-databases/db2_11-1/Dockerfile create mode 100644 docker-databases/db2_11-1/README.md create mode 100755 docker-databases/db2_11-1/entrypoint.sh rename {ci => docker-databases}/docker-compose.yml (69%) rename {ci => docker-databases/postgres_10}/Dockerfile (100%) rename {ci => docker-databases}/prepare_db.bat (100%) rename {ci => docker-databases}/prepare_db.sh (86%) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 3253a7ad4..bcc55e6a4 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -270,7 +270,7 @@ jobs: name: ${{ env.ARTIFACTS_TASKANA_JARS_NAME }} path: ${{ env.ARTIFACTS_TASKANA_JARS_PATH }} - name: Prepare database - run: ci/prepare_db.sh ${{ matrix.database }} + run: docker-databases/prepare_db.sh ${{ matrix.database }} - name: Generate JavaDoc for Rest Documentation if: matrix.module == 'taskana-simplehistory-rest-spring' run: ./mvnw -B validate -pl :taskana-rest-spring @@ -312,7 +312,7 @@ jobs: name: ${{ env.ARTIFACTS_TASKANA_JARS_NAME }} path: ${{ env.ARTIFACTS_TASKANA_JARS_PATH }} - name: Start database - run: ci/prepare_db.sh POSTGRES_10 + run: docker-databases/prepare_db.sh POSTGRES_10 - name: Test run: ./mvnw -B verify -f rest/taskana-rest-spring-example-wildfly - name: Cancel workflow diff --git a/.gitignore b/.gitignore index a1ea94c35..f416e1cbe 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,6 @@ Thumbs.db # java-format .java-format-cache + +# DB2 database +db.tar.gz diff --git a/docker-databases/db2_11-1/Dockerfile b/docker-databases/db2_11-1/Dockerfile new file mode 100644 index 000000000..e5b70d8a0 --- /dev/null +++ b/docker-databases/db2_11-1/Dockerfile @@ -0,0 +1,74 @@ +# Build docker image of db2 express-C v10.5 FP5 (64bit) +# +# # Authors: +# * Leo (Zhong Yu) Wu +# +# Copyright 2015, IBM Corporation +# +# 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. + +FROM centos:7 + +############################################################### +# +# System preparation for DB2 +# +############################################################### + +RUN groupadd db2iadm1 && useradd -G db2iadm1 db2inst1 + +# Required packages +RUN yum install -y \ + vi \ + sudo \ + passwd \ + pam \ + pam.i686 \ + ncurses-libs.i686 \ + file \ + libaio \ + libstdc++-devel.i686 \ + numactl-libs \ + which \ + glibc-locale-source \ + glibc-langpack-de \ + && yum clean all + +RUN localedef -i de_DE -c -f UTF-8 \ + -A /usr/share/locale/locale.alias de_DE.UTF-8 && echo "LANG=de_DE.UTF-8" > /etc/locale.conf +RUN echo "export LANG=de_DE.UTF-8" >> /etc/profile + +COPY ./db.tar.gz /tmp/expc.tar.gz + +RUN cd /tmp && tar xf expc.tar.gz \ + && su - db2inst1 -c "/tmp/expc/db2_install -y -b /home/db2inst1/sqllib" \ + && echo '. /home/db2inst1/sqllib/db2profile' >> /home/db2inst1/.bash_profile \ + && rm -rf /tmp/db2* && rm -rf /tmp/expc* \ + && sed -ri 's/(ENABLE_OS_AUTHENTICATION=).*/\1YES/g' /home/db2inst1/sqllib/instance/db2rfe.cfg \ + && sed -ri 's/(RESERVE_REMOTE_CONNECTION=).*/\1YES/g' /home/db2inst1/sqllib/instance/db2rfe.cfg \ + && sed -ri 's/^\*(SVCENAME=db2c_db2inst1)/\1/g' /home/db2inst1/sqllib/instance/db2rfe.cfg \ + && sed -ri 's/^\*(SVCEPORT)=48000/\1=50000/g' /home/db2inst1/sqllib/instance/db2rfe.cfg + +RUN su - db2inst1 -c "db2start && db2set DB2COMM=TCPIP \ + && db2set -g -null DB2_COMPATIBILITY_VECTOR \ + && db2 create database TSKDB using codeset utf-8 territory en-us \ + collate using 'CLDR181_LDE_AS_CX_EX_FX_HX_NX_S3' PAGESIZE 32 K" \ + && su - db2inst1 -c "db2stop force" \ + && cd /home/db2inst1/sqllib/instance \ + && ./db2rfe -f ./db2rfe.cfg + +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] +CMD ["start"] + +EXPOSE 50000 diff --git a/docker-databases/db2_11-1/README.md b/docker-databases/db2_11-1/README.md new file mode 100644 index 000000000..56b8d4ec8 --- /dev/null +++ b/docker-databases/db2_11-1/README.md @@ -0,0 +1,5 @@ +# How to build the IBM DB2 Express-C docker image + +1. Download the database from either [IBM directly](https://www-01.ibm.com/marketing/iwm/iwm/web/pickUrxNew.do?source=swg-db2expressc) or from our [NT Onedrive](https://msnovatec-my.sharepoint.com/:f:/g/personal/mzo_novatec-gmbh_de/EuxS9esUxppHn-1Mobq7UT4BVWbwXga585q7o3h6hzAC6g?e=PK3KdM) (NT employees only) +2. Name that tar file `db.tar.gz` and place it in this folder +3. Execute a docker build command diff --git a/docker-databases/db2_11-1/entrypoint.sh b/docker-databases/db2_11-1/entrypoint.sh new file mode 100755 index 000000000..337f876b7 --- /dev/null +++ b/docker-databases/db2_11-1/entrypoint.sh @@ -0,0 +1,105 @@ +#!/bin/bash +# +# Initialize DB2 instance in a Docker container +# +# # Authors: +# * Leo (Zhong Yu) Wu +# * Boris Manojlovic +# +# Copyright 2015, IBM Corporation +# +# 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. + +pid=0 + +function log_info { + echo -e $(date '+%Y-%m-%d %T')"\e[1;32m $@\e[0m" +} + +function log_error { + echo -e >&2 $(date +"%Y-%m-%d %T")"\e[1;31m $@\e[0m" +} + +function stop_db2 { + log_info "stopping database engine" + su - db2inst1 -c "db2stop force" +} + +function start_db2 { + log_info "starting database engine" + su - db2inst1 -c "db2start" +} + +function restart_db2 { + # if you just need to restart db2 and not to kill this container + # use docker kill -s USR1 + kill ${spid} + log_info "Asked for instance restart doing it..." + stop_db2 + start_db2 + log_info "database instance restarted on request" +} + +function terminate_db2 { + kill ${spid} + stop_db2 + if [ $pid -ne 0 ]; then + kill -SIGTERM "$pid" + wait "$pid" + fi + log_info "database engine stopped" + exit 0 # finally exit main handler script +} + +trap "terminate_db2" SIGTERM +trap "restart_db2" SIGUSR1 + +if [ ! -f ~/db2inst1_pw_set ]; then + (echo "db2inst1-pwd"; echo "db2inst1-pwd") | passwd db2inst1 > /dev/null 2>&1 + if [ $? != 0 ];then + log_error "Changing password for db2inst1 failed" + exit 1 + fi + touch ~/db2inst1_pw_set +fi + +if [ ! -f ~/db2_license_accepted ];then + if [ -z "$LICENSE" ];then + log_error "error: LICENSE not set" + log_error "Did you forget to add '-e LICENSE=accept' ?" + exit 1 + fi + + if [ "${LICENSE}" != "accept" ];then + log_error "error: LICENSE not set to 'accept'" + log_error "Please set '-e LICENSE=accept' to accept License before use the DB2 software contained in this image." + exit 1 + fi + touch ~/db2_license_accepted +fi + +if [[ $1 = "start" ]]; then + log_info "Initializing container" + start_db2 + log_info "Database db2diag log following" + tail -f ~db2inst1/sqllib/db2dump/db2diag.log & + export pid=${!} + while true + do + sleep 10000 & + export spid=${!} + wait $spid + done +else + exec "$1" +fi diff --git a/ci/docker-compose.yml b/docker-databases/docker-compose.yml similarity index 69% rename from ci/docker-compose.yml rename to docker-databases/docker-compose.yml index b15f6b426..9bb278f80 100644 --- a/ci/docker-compose.yml +++ b/docker-databases/docker-compose.yml @@ -1,12 +1,14 @@ version: '3' services: taskana-postgres_10: - build: . + build: postgres_10 ports: - 5102:5432 environment: - POSTGRES_PASSWORD=postgres taskana-db2_11-1: image: taskana/db2:11.1 + environment: + - LICENSE=accept ports: - 5101:50000 \ No newline at end of file diff --git a/ci/Dockerfile b/docker-databases/postgres_10/Dockerfile similarity index 100% rename from ci/Dockerfile rename to docker-databases/postgres_10/Dockerfile diff --git a/ci/prepare_db.bat b/docker-databases/prepare_db.bat similarity index 100% rename from ci/prepare_db.bat rename to docker-databases/prepare_db.bat diff --git a/ci/prepare_db.sh b/docker-databases/prepare_db.sh similarity index 86% rename from ci/prepare_db.sh rename to docker-databases/prepare_db.sh index 178ffbc82..a6d6068a3 100755 --- a/ci/prepare_db.sh +++ b/docker-databases/prepare_db.sh @@ -1,5 +1,7 @@ #!/bin/bash set -e #fail fast +trap "exit 1" TERM +export TOP_PID=$$ #H Usage: #H %FILE% -h | %FILE% --help @@ -39,7 +41,7 @@ function mapDBToDockerComposeServiceName() { echo "taskana-postgres_10" ;; *) - echo "unknown database '$1'" >&2 && exit 1 + echo "unknown database '$1'" >&2 && kill -s TERM $TOP_PID esac } @@ -71,8 +73,11 @@ function main() { echo 'schemaName=taskana' >> $propFile ;; stop) - docker-compose -f $scriptDir/docker-compose.yml rm -f -s -v "$(mapDBToDockerComposeServiceName "$2")" - + # this variable is necessary, so that the script can terminate properly + # when the provided database name does not match. PLEASE DO NOT INLINE! + local composeServiceName="$(mapDBToDockerComposeServiceName "$2")" + docker-compose -f $scriptDir/docker-compose.yml rm -f -s -v $composeServiceName + [[ -f "$propFile" ]] && rm "$propFile" ;; *)