Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
MACOSX Script that executes React App on local docker for testing.
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# include other scripts
# shellcheck disable=SC1090 source=./
source "$SCRIPT_DIR/"
# shellcheck disable=SC1090
source "$SCRIPT_DIR/"
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"
function cleanup() {
tput sgr0 # reset colors to default
# cleanup from local injections
#git checkout @ --
mv -f
# 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
# resolve CI variables to real values and store them in temporary file
envsubst < > && mv -f
[[ -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:
# -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment