diff --git a/bash/build.sh b/bash/build.sh index 89d6c19..579d4fa 100644 --- a/bash/build.sh +++ b/bash/build.sh @@ -1,10 +1,11 @@ #!/usr/bin/env bash function buildImages { - NAME=$1 - VERSION=$2 - USERID=${3:-1000} - PHP=${4-:"all"} + DIR=$1 + NAME=$2 + VERSION=$3 + USERID=${4:-1000} + PHP=${5-:"all"} imageExists "${NAME}:${VERSION}-php56xdebug" @@ -29,9 +30,13 @@ function buildImages { } function runBuild { - export IMAGE_VERSION=$1 - cd "${__DIR}" + DIR=$1 + export IMAGE_VERSION=$2 + + cd "${DIR}" + BUILD_OUTPUT=$(docker-compose up php) + docker-compose kill > /dev/null 2>&1 docker-compose rm -f -v > /dev/null 2>&1 diff --git a/bash/run.sh b/bash/run.sh index 516031d..f65e087 100644 --- a/bash/run.sh +++ b/bash/run.sh @@ -1,14 +1,15 @@ #!/usr/bin/env bash function runInBackground { - export IMAGE_VERSION=$1 + DIR=$1 + export IMAGE_VERSION=$2 + DOCKER_COMPOSE_FILE="${DIR}/docker-compose.yml" + DOCKER_COMPOSE_LOCAL_FILE="${DIR}/docker-compose.local.yml" - cd "${__DIR}" - - docker-compose -f docker-compose.yml -f docker-compose.local.yml kill > /dev/null 2>&1 - docker-compose -f docker-compose.yml -f docker-compose.local.yml rm -f -v > /dev/null 2>&1 - docker-compose -f docker-compose.yml -f docker-compose.local.yml up -d nginx php mysql - docker-compose -f docker-compose.yml -f docker-compose.local.yml exec php bash - docker-compose -f docker-compose.yml -f docker-compose.local.yml kill > /dev/null 2>&1 - docker-compose -f docker-compose.yml -f docker-compose.local.yml rm -f -v > /dev/null 2>&1 + docker-compose -f "${DOCKER_COMPOSE_FILE}" -f "${DOCKER_COMPOSE_LOCAL_FILE}" kill > /dev/null 2>&1 + docker-compose -f "${DOCKER_COMPOSE_FILE}" -f "${DOCKER_COMPOSE_LOCAL_FILE}" rm -f -v > /dev/null 2>&1 + docker-compose -f "${DOCKER_COMPOSE_FILE}" -f "${DOCKER_COMPOSE_LOCAL_FILE}" up -d nginx php mysql + docker-compose -f "${DOCKER_COMPOSE_FILE}" -f "${DOCKER_COMPOSE_LOCAL_FILE}" exec php bash + docker-compose -f "${DOCKER_COMPOSE_FILE}" -f "${DOCKER_COMPOSE_LOCAL_FILE}" kill > /dev/null 2>&1 + docker-compose -f "${DOCKER_COMPOSE_FILE}" -f "${DOCKER_COMPOSE_LOCAL_FILE}" rm -f -v > /dev/null 2>&1 } diff --git a/bash/variable.sh b/bash/variable.sh index 164da6b..76a0cf7 100644 --- a/bash/variable.sh +++ b/bash/variable.sh @@ -1,15 +1,18 @@ #!/usr/bin/env bash -export PROJECT_NAME=$(cat "${__DIR}/.project_name") -export PROJECT_XDEBUG_ENABLED=false -export PROJECT_WEB_DIR=${PROJECT_WEB_DIR:="web"} -export PROJECT_INDEX_FILE=${PROJECT_INDEX_FILE:="index.php"} -export PROJECT_DEV_INDEX_FILE=${PROJECT_DEV_INDEX_FILE:="index_dev.php"} -export APP_NAME=$(echo $(cat "${__DIR}/composer.json" | grep name | head -1 | awk -F: '{ print $2 }' | sed 's/[",\r]//g' | tr -dc '[:alnum:]\n\r' | tr '[:upper:]' '[:lower:]')) -export APP_VERSION=$(echo $(cat "${__DIR}/composer.json" | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",\r]//g')) -export USERID=$(id -u); +function defineVariables +{ + DIR=$1 + export PROJECT_NAME=$(cat "${DIR}/.project_name") + export PROJECT_XDEBUG_ENABLED=false + export PROJECT_WEB_DIR=${PROJECT_WEB_DIR:="web"} + export PROJECT_INDEX_FILE=${PROJECT_INDEX_FILE:="index.php"} + export PROJECT_DEV_INDEX_FILE=${PROJECT_DEV_INDEX_FILE:="index_dev.php"} + export APP_NAME=$(echo $(cat "${DIR}/composer.json" | grep name | head -1 | awk -F: '{ print $2 }' | sed 's/[",\r]//g' | tr -dc '[:alnum:]\n\r' | tr '[:upper:]' '[:lower:]')) + export APP_VERSION=$(echo $(cat "${DIR}/composer.json" | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",\r]//g')) + export USERID=$(id -u); - -echo "User ID: $USERID"; -echo -e "\nIMAGE VERSION: $APP_NAME:$APP_VERSION\n"; -declare -i BUILD_STATUS=0; + echo "User ID: $USERID"; + echo -e "\nIMAGE VERSION: $APP_NAME:$APP_VERSION\n"; + declare -i BUILD_STATUS=0; +} diff --git a/docker-compose.local.yml b/docker-compose.local.yml index 13053cd..bafcbb8 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -13,7 +13,7 @@ mysql: - ./data:/var/lib/mysql nginx: - image: "${PROJECT_NAME}:${APP_VERSION}-nginx" + image: "${APP_NAME}:${APP_VERSION}-nginx" ports: - "8000:80" links: diff --git a/docker.sh b/docker.sh index d0717b6..b096e07 100755 --- a/docker.sh +++ b/docker.sh @@ -4,11 +4,12 @@ TASK_NAME=$1; __DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - for FILE in $(ls "${__DIR}/bash") ; do source "${__DIR}/bash/${FILE}" done +defineVariables "${__DIR}" + if [[ $TASK_NAME == '' ]]; then echo -e "Available commands:"; echo -e "'build-images' - building docker images"; @@ -28,44 +29,49 @@ fi case $TASK_NAME in 'build-images') - buildImages "${APP_NAME}" "${APP_VERSION}" "${USERID}" "all" + buildImages "${__DIR}" "${APP_NAME}" "${APP_VERSION}" "${USERID}" "all" ;; 'build-56') - buildImages "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php56xdebug" - runBuild "${APP_NAME}:${APP_VERSION}-php56xdebug" + buildImages "${__DIR}" "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php56xdebug" + runBuild "${__DIR}" "${APP_NAME}:${APP_VERSION}-php56xdebug" ;; 'build-56-coverage') export PROJECT_ENABLED_XDEBUG=true - buildImages "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php56xdebug" - runBuild "${APP_NAME}:${APP_VERSION}-php56xdebug" + buildImages "${__DIR}" "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php56xdebug" + runBuild "${__DIR}" "${APP_NAME}:${APP_VERSION}-php56xdebug" ;; 'run-56-coverage') export PROJECT_ENABLED_XDEBUG=true - buildImages "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php56xdebug" - runInBackground "${APP_NAME}:${APP_VERSION}-php56xdebug" + buildImages "${__DIR}" "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php56xdebug" + runInBackground "${__DIR}" "${APP_NAME}:${APP_VERSION}-php56xdebug" ;; 'build' | 'build-71') - buildImages "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php71xdebug" - runBuild "${APP_NAME}:${APP_VERSION}-php71xdebug" + buildImages "${__DIR}" "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php71xdebug" + runBuild "${__DIR}" "${APP_NAME}:${APP_VERSION}-php71xdebug" ;; 'build-coverage' | 'build-71-coverage') export PROJECT_ENABLED_XDEBUG=true - buildImages "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php71xdebug" - runBuild "${APP_NAME}:${APP_VERSION}-php71xdebug" + buildImages "${__DIR}" "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php71xdebug" + runBuild "${__DIR}" "${APP_NAME}:${APP_VERSION}-php71xdebug" ;; 'run-coverage' | 'run-71-coverage') export PROJECT_ENABLED_XDEBUG=true - buildImages "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php71xdebug" - runInBackground "${APP_NAME}:${APP_VERSION}-php71xdebug" + buildImages "${__DIR}" "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php71xdebug" + runInBackground "${__DIR}" "${APP_NAME}:${APP_VERSION}-php71xdebug" ;; 'build-7') - buildImages "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php7xdebug" - runBuild "${APP_NAME}:${APP_VERSION}-php7xdebug" + buildImages "${__DIR}" "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php7xdebug" + runBuild "${__DIR}" "${APP_NAME}:${APP_VERSION}-php7xdebug" ;; 'build-7-coverage') export PROJECT_ENABLED_XDEBUG=true - buildImages "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php7xdebug" - runBuild "${APP_NAME}:${APP_VERSION}-php7xdebug" + buildImages "${__DIR}" "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php7xdebug" + runBuild "${__DIR}" "${APP_NAME}:${APP_VERSION}-php7xdebug" + ;; + 'run-7-coverage') + export PROJECT_ENABLED_XDEBUG=true + buildImages "${__DIR}" "${APP_NAME}" "${APP_VERSION}" "${USERID}" "php7xdebug" + runInBackground "${__DIR}" "${APP_NAME}:${APP_VERSION}-php1xdebug" ;; esac