diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a8f48a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +post_start/* +!999_import_dump \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..1d1806a --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# HANA Docker (Compose) Template + +- I need HANA to develop +- I have a dump (`EXPORT ... AS CSV INTO ...`) that I want to import +- I want a turn-key solution + +## Prerequisites + +`docker pull` the latest [HANA Express Edition image][image] from the Docker Store + +[image]: https://hub.docker.com/_/sap-hana-express-edition/ + +> **Docker for Mac / Docker for Windows**\ +> Make sure to increase the RAM (at least **12GB**), the CPU (4 cores) and, depending on your dump, the disk size of the Docker VM! + +## Usage Instructions + +1. Download this repository as zip +1. Unpack +1. Rename the folder to something more descriptive +1. Dump the `post_start` hook scripts of the HANA image into this folder + ```bash + docker create --name hana_dummy store/saplabs/hanaexpress: + docker cp hana_dummy:/hana/hooks/post_start . + docker rm hana_dummy + ``` +1. Adapt the HANA image version in `docker-compose.yml` +1. Upack the dump into a sub-folder of `./dump`, e.g. `./dump/SOURCE_SCHEMA` +1. Adapt the env vars in `docker-compose.yml` as necessary (check `post_start/999_import_dump` to understand how they are + used during bootstrap) +1. Tweak `post_start/999_import_dump` as necessary +1. *(optional)* Add some more shell scripts to `post_start` if you need other things executed during the database bootstrap +1. `docker-compose up` +1. Grab a pint of :coffee: and wait until the database setup including dump import is done. + +## Notes + +- This setup modifies the tenant database +- The `SYSTEM` password for both the system and the tenant (HXE) database is `HXEHana1` + +``` +db.url=jdbc:sap://localhost:39041/?databaseName=HXE&reconnect=true&statementCacheSize=512 +db.driver=com.sap.db.jdbc.Driver +db.username=LOCALDEV +db.password=Localdev1 +hanadb.storage.columnbased=true +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a351321 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3' +services: + db: + image: "store/saplabs/hanaexpress:2.00.036.00.20190223.1" + restart: "unless-stopped" + ports: + - 39013:39013 + - 39017:39017 + - 39041-39045:39041-39045 + - 1128-1129:1128-1129 + - 59013-59014:59013-59014 + volumes: + - ./post_start:/hana/hooks/post_start/ + - ./dump:/hana/mounts/dump/ + environment: + - DUMP_FOLDER=DUMP + - SOURCE_SCHEMA=SOURCE + - SCHEMA_NAME=LOCALDEV + - SCHEMA_PWD=Localdev1 + command: + - --agree-to-sap-license + - --dont-check-system + - --dont-check-mount-points + - --master-password + - HXEHana1 diff --git a/dump/.gitkeep b/dump/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/post_start/999_import_dump b/post_start/999_import_dump new file mode 100755 index 0000000..d3d4d05 --- /dev/null +++ b/post_start/999_import_dump @@ -0,0 +1,24 @@ +#!/bin/bash + +set -euo pipefail + +#found in /run_hana.sh, hxe_optimize.sh +#durinng the 'initial' phase there is key for SYSTEM available +declare -r tenant_store_key=us_key_tenantdb + +# import dump +function main() { + case "$_HOOK_START_TYPE" in + initial) + # create user + /usr/sap/HXE/HDB90/exe/hdbsql -a -x -i 90 -d HXE -U ${tenant_store_key} -B UTF8 "CREATE USER $SCHEMA_NAME PASSWORD \"$SCHEMA_PWD\" NO FORCE_FIRST_PASSWORD_CHANGE" 2>&1 + /usr/sap/HXE/HDB90/exe/hdbsql -a -x -i 90 -d HXE -U ${tenant_store_key} -B UTF8 "ALTER USER $SCHEMA_NAME DISABLE PASSWORD LIFETIME" 2>&1 + # import dump + /usr/sap/HXE/HDB90/exe/hdbsql -a -x -i 90 -d HXE -U ${tenant_store_key} -B UTF8 "IMPORT \"$SOURCE_SCHEMA\".\"*\" from '/hana/mounts/dump/$DUMP_FOLDER' WITH RENAME SCHEMA \"$SOURCE_SCHEMA\" TO \"$SCHEMA_NAME\" REPLACE THREADS 4" 2>&1 + # reset SAP Commerce admin user + /usr/sap/HXE/HDB90/exe/hdbsql -a -x -i 90 -d HXE -U ${tenant_store_key} -B UTF8 "UPDATE \"$SCHEMA_NAME\".\"USERS\" SET PASSWD = 'nimda', P_PASSWORDENCODING = 'plain' WHERE P_UID = 'admin'" 2>&1 + ;; + esac +} + +main