Created
August 30, 2022 10:25
-
-
Save OleksandrKucherenko/ac9905bbd3111ae911efe487333dbd64 to your computer and use it in GitHub Desktop.
MACOSX Script that executes React App on local docker for testing.
This file contains hidden or 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
#!/usr/bin/env bash | |
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
container_name=${CI_CONTAINER_NAME:="hvc-csp"} | |
container_port=${CI_CONTAINER_PORT:=8081} | |
# include other scripts | |
# shellcheck disable=SC1090 source=./dependencies.sh | |
source "$SCRIPT_DIR/dependencies.sh" | |
# shellcheck disable=SC1090 source=commons.sh | |
source "$SCRIPT_DIR/commons.sh" | |
dependency docker "20.*.*" "brew install docker" | |
docker_status=$(docker ps -q)$? | |
if [[ $docker_status -ne 0 ]]; then | |
open --background -a Docker && | |
while ! docker system info >/dev/null 2>&1; do sleep 1; done && | |
echo "Docker is ready for running the commands" | |
fi | |
function cleanup() { | |
tput sgr0 # reset colors to default | |
# cleanup from local injections | |
#git checkout @ -- .env.ci | |
mv -f .env.ci.old .env.ci | |
# cleanup | |
docker kill "$container_name" | |
docker container rm "$container_name" | |
docker image rm "$container_name" | |
exit 0 # force exit code 0, not breaks CI/CD pipeline | |
} | |
# call cleanup on Interrupt, Termination, or Exit | |
trap cleanup INT TERM EXIT | |
# create a copy | |
cp -f .env.ci .env.ci.old | |
# resolve CI variables to real values and store them in temporary file | |
envsubst <.env.ci >.env.ci.local && mv -f .env.ci.local .env.ci | |
[[ -n $CI ]] && docker build --progress=plain --tag "$container_name" . | |
[[ -z $CI ]] && docker build --tag "$container_name" . | |
# shellcheck disable=SC2034 | |
container=$(docker run --detach --publish $container_port:8080 --name "$container_name" "$container_name") | |
echo "" | |
echo "${cl_green}Web: ${cl_yellow}http://localhost:${container_port}${PUBLIC_URL}/ ${cl_reset}" | |
echo "" | |
open "http://localhost:${container_port}${PUBLIC_URL}/" | |
validate_yn_input close "Y" "Do you want to stop execution [Yn]: " | |
# | |
# Refs: | |
# - https://stackoverflow.com/questions/19537645/get-environment-variable-value-in-dockerfile | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment