Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mpern-sap committed Mar 22, 2019
0 parents commit b52bb11
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
post_start/*
!999_import_dump
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:<version>
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
```
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Empty file added dump/.gitkeep
Empty file.
24 changes: 24 additions & 0 deletions post_start/999_import_dump
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b52bb11

Please sign in to comment.