-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add basic environment creation
- Loading branch information
Michele Mondelli
committed
Apr 29, 2023
1 parent
5f09000
commit 37ef02a
Showing
18 changed files
with
551 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
source "${SCRIPT_DIR}/../common/lib.sh" | ||
|
||
for var in "$@" | ||
do | ||
PARAMS="$PARAMS ${var}" | ||
done | ||
|
||
if [[ -t 1 ]] ; then OPTS=""; else OPTS="-T"; fi | ||
|
||
docker-compose ps ${CONTAINER} | grep -q Up | true | ||
ret=${PIPESTATUS[1]} | ||
if [ $ret -eq 1 ]; then | ||
echo -e "${CR}Error${CN} - It seems that the ${CONTAINER} container is not running" | ||
exit 1 | ||
fi | ||
|
||
docker-compose exec -u $(id -u):$(id -g) ${OPTS} ${CONTAINER} /bin/bash -c "${PARAMS}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
source "${SCRIPT_DIR}/../common/lib.sh" | ||
|
||
PWD=$(pwd) | ||
while [[ "$PWD" != "" && ! -e "$PWD/.bmeme" ]]; do | ||
PWD=${PWD%/*} | ||
done | ||
|
||
FOUND=$PWD | ||
|
||
if [[ "${FOUND}" = "" ]]; then | ||
echo -e "${CR}Error${CN} - Unable to find parent bmeme project!" | ||
exit -1 | ||
fi | ||
|
||
ORIG_DIR=$(pwd) | ||
REL_DIR=${ORIG_DIR#"$FOUND"} | ||
|
||
set -e | ||
QUOTEDCMD=() | ||
for token in "$@"; do | ||
QUOTEDCMD+=($(printf "%q" "$token")) | ||
done | ||
CMD="${QUOTEDCMD[*]}" | ||
|
||
pushd ${FOUND} > /dev/null | ||
${APP_BIN} cd ".${REL_DIR}" \; ${CMD} | ||
popd > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
source "${SCRIPT_DIR}/../../common/lib.sh" | ||
|
||
if [[ "$1" == "descr" ]]; then | ||
echo -n "Create and start docker environment" | ||
exit 0 | ||
fi | ||
|
||
if [[ "$1" == "run" ]]; then | ||
echo -e "============ ${CB}Creating${CN} docker environment ..." | ||
echo "${LOGPREFIX} CMD docker-compose build --pull --build-arg FIX_UID=\"\$(id -u)\" --build-arg FIX_GID=\"\$(id -g)\"" >> ${LOGFILE} | ||
docker-compose build --pull --build-arg FIX_UID="$(id -u)" --build-arg FIX_GID="$(id -g)" | ||
echo "" | ||
echo -e "============ ${CB}Starting${CN} docker environment ..." | ||
echo "${LOGPREFIX} CMD docker-compose up -d" >> ${LOGFILE} | ||
docker-compose up -d | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
source "${SCRIPT_DIR}/../../common/lib.sh" | ||
|
||
if [[ "$1" == "descr" ]]; then | ||
echo -n "Clean docker environment" | ||
exit 0 | ||
fi | ||
|
||
if [[ "$1" == "run" ]]; then | ||
echo -e "============ ${CB}Cleaning${CN} docker environment ..." | ||
docker-compose down -v | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
source "${SCRIPT_DIR}/../../common/lib.sh" | ||
|
||
if [[ "$1" == "descr" ]]; then | ||
echo -n "Show docker container logs" | ||
exit 0 | ||
fi | ||
|
||
if [[ "$1" == "run" ]]; then | ||
echo -e "============ ${CB}Showing${CN} docker container logs ..." | ||
docker-compose logs -f | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
source "${SCRIPT_DIR}/../../common/lib.sh" | ||
|
||
if [[ "$1" == "descr" ]]; then | ||
echo -n "Run a shell inside the docker container" | ||
exit 0 | ||
fi | ||
|
||
if [[ "$1" == "run" ]]; then | ||
echo -e "============ ${CB}Running${CN} a shell inside the docker container ..." | ||
echo "${LOGPREFIX} CMD ${C_BIN} bash" >> ${LOGFILE} | ||
${C_BIN} bash | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
source "${SCRIPT_DIR}/../../common/lib.sh" | ||
|
||
if [[ "$1" == "descr" ]]; then | ||
echo -n "Start docker environment" | ||
exit 0 | ||
fi | ||
|
||
if [[ "$1" == "run" ]]; then | ||
echo -e "============ ${CB}Starting${CN} docker environment ..." | ||
docker-compose start | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
source "${SCRIPT_DIR}/../../common/lib.sh" | ||
|
||
if [[ "$1" == "descr" ]]; then | ||
echo -n "Check docker environment status" | ||
exit 0 | ||
fi | ||
|
||
if [[ "$1" == "run" ]]; then | ||
echo -e "============ ${CB}Checking${CN} docker environment status ..." | ||
docker-compose ps | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
source "${SCRIPT_DIR}/../../common/lib.sh" | ||
|
||
if [[ "$1" == "descr" ]]; then | ||
echo -n "Stop docker environment" | ||
exit 0 | ||
fi | ||
|
||
if [[ "$1" == "run" ]]; then | ||
echo -e "============ ${CB}Stopping${CN} docker environment ..." | ||
docker-compose stop | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
source "${SCRIPT_DIR}/../common/lib.sh" | ||
|
||
if [[ "$1" == "descr" ]]; then | ||
echo -n "Check system requirements" | ||
exit 0 | ||
fi | ||
|
||
if [[ "$1" == "run" ]]; then | ||
echo "" | ||
echo -e "Checking ${CG}system requirements${CN} ..." | ||
echo "" | ||
echo "${LOGPREFIX} CMD docker --version" >> ${LOGFILE} | ||
docker --version 2>&1 >> ${LOGFILE} | ||
echo "${LOGPREFIX} CMD docker-compose --version" >> ${LOGFILE} | ||
docker-compose --version 2>&1 >> ${LOGFILE} | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
CN="\\033[0m" | ||
CR="\\033[91m" | ||
CG="\\033[92m" | ||
CY="\\033[93m" | ||
CB="\\033[94m" | ||
CT="\\033[37m" | ||
TB="\\033[1m" | ||
|
||
LIB_SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
BASE_PRJ_DIR=$(realpath "${LIB_SCRIPT_DIR}/../../..") | ||
if test -f "${BASE_PRJ_DIR}/.env"; then | ||
source "${BASE_PRJ_DIR}/.env" | ||
fi | ||
APP_DIR="${BASE_PRJ_DIR}/app" | ||
|
||
CONTAINER="app" | ||
|
||
BUILD_DIR="${BASE_PRJ_DIR}/.bmeme/build" | ||
LOCAL_PATH="${BUILD_DIR}/bin" | ||
C_BIN="${LOCAL_PATH}/c" | ||
APP_BIN="${LOCAL_PATH}/app" | ||
|
||
LOGDIR="${BASE_PRJ_DIR}/.bmeme/build/log" | ||
LOGFILE="${LOGDIR}/configure.log" | ||
LOGPREFIX=">>>> " | ||
|
||
# Load custom configuration | ||
if test -f "${BUILD_DIR}/config"; then | ||
source "${BUILD_DIR}/config" | ||
fi | ||
|
||
log_begin() { | ||
echo "" >>${LOGFILE} | ||
echo "${LOGPREFIX} SCRIPT EXECUTED" >>${LOGFILE} | ||
echo "${LOGPREFIX} Bin: ${0}" >>${LOGFILE} | ||
echo "${LOGPREFIX} Params: ${@}" >>${LOGFILE} | ||
echo "${LOGPREFIX} Time: $(date +'%Y-%m-%d %H:%M:%S')" >>${LOGFILE} | ||
echo "" >>${LOGFILE} | ||
} | ||
|
||
log_end() { | ||
echo "" >>${LOGFILE} | ||
echo "${LOGPREFIX} SCRIPT TERMINATED" >>${LOGFILE} | ||
echo "${LOGPREFIX} Time: $(date +'%Y-%m-%d %H:%M:%S')" >>${LOGFILE} | ||
echo "" >>${LOGFILE} | ||
} | ||
|
||
show_cmd_error() { | ||
echo -e "${TB}${CR}ERROR${CN}" | ||
echo "" | ||
echo -e "See ${CB}logfile${CN} for details: " | ||
echo -e "\t${CY}tail -f ${LOGFILE}${CN}" | ||
echo "" | ||
exit 1 | ||
} |
Oops, something went wrong.