|
| 1 | +# Copyright (c) 2021 Oracle and/or its affiliates. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | + |
| 16 | +############################################################################### |
| 17 | +# Local environment setup # |
| 18 | +############################################################################### |
| 19 | +# Shell variables: WS_DIR |
| 20 | +# Arguments: $1 - Script path |
| 21 | +# $2 - cd to Helidon root directory from script path |
| 22 | +# |
| 23 | +# Atleast WS_DIR or both arguments must be passed. |
| 24 | + |
| 25 | +# WS_DIR variable verification. |
| 26 | +if [ -z "${WS_DIR}" ]; then |
| 27 | + |
| 28 | + if [ -z "${1}" ]; then |
| 29 | + echo "ERROR: Missing required script path, exitting" |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | + |
| 33 | + if [ -z "${2}" ]; then |
| 34 | + echo "ERROR: Missing required cd to Helidon root directory from script path, exitting" |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | + |
| 38 | + readonly WS_DIR=$(cd $(dirname -- "${1}") ; cd ${2} ; pwd -P) |
| 39 | + |
| 40 | +fi |
| 41 | + |
| 42 | +# Multiple definition protection. |
| 43 | +if [ -z "${__LOCAL_ENV_INCLUDED__}" ]; then |
| 44 | + readonly __LOCAL_ENV_INCLUDED__='true' |
| 45 | + |
| 46 | + . ${WS_DIR}/etc/scripts/includes/error_handlers.sh |
| 47 | + |
| 48 | + # Docker helper functions |
| 49 | + |
| 50 | + # Docker container start. |
| 51 | + # Database containers require listening TCP port to be mapped to specific host:port. |
| 52 | + # Arguments: $1 - name:version of the image |
| 53 | + # $2 - name of the container (--name ${2}) |
| 54 | + # $3 - container port publishing (--publish ${3}) |
| 55 | + # $4 - additional docker run command arguments |
| 56 | + # $5 - name of variable with container running status |
| 57 | + # $6 - container start trigger variable name (optional, default true) |
| 58 | + docker_start() { |
| 59 | + if [ -z "${6}" ] || [ -n "${6}" -a -n "${!6}" ]; then |
| 60 | + echo -n 'Starting Docker container: ' |
| 61 | + docker run -d \ |
| 62 | + --name "${2}" \ |
| 63 | + --publish "${3}" \ |
| 64 | + ${4} \ |
| 65 | + --rm ${1} && \ |
| 66 | + [ -n "${5}" ] && eval "${5}='1'" |
| 67 | + fi |
| 68 | + } |
| 69 | + |
| 70 | + # Docker container stop. |
| 71 | + # Arguments: $1 - name of the container |
| 72 | + # $2 - docker trigger variable name (optional, default true) |
| 73 | + docker_stop() { |
| 74 | + if [ -z "${2}" ] || [ -n "${2}" -a -n "${!2}" ]; then |
| 75 | + echo -n 'Stopping Docker container: ' |
| 76 | + docker stop "${1}" |
| 77 | + fi |
| 78 | + } |
| 79 | + |
| 80 | +else |
| 81 | + echo "WARNING: ${WS_DIR}/etc/scripts/includes/docker-env.sh included multiple times." |
| 82 | +fi |
0 commit comments