Skip to content

Commit

Permalink
fix(dev): split to separate scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
bas-kirill committed Aug 26, 2024
1 parent e678ca7 commit 913c064
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 91 deletions.
12 changes: 6 additions & 6 deletions tools/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ services:

muse-server:
image: "${MUSE_SERVER_IMAGE:-muse-server}"
platforms:
- "linux/amd64"
- "linux/arm64"
# platforms:
# - "linux/amd64"
# - "linux/arm64"
container_name: muse-server
ports:
- ${SERVER_PORT}:8080
Expand All @@ -47,9 +47,9 @@ services:

muse-client:
image: "${MUSE_CLIENT_IMAGE:-muse-client}"
platforms:
- "linux/amd64"
- "linux/arm64"
# platforms:
# - "linux/amd64"
# - "linux/arm64"
container_name: muse-client
ports:
- ${CLIENT_PORT}:80
Expand Down
30 changes: 30 additions & 0 deletions tools/scripts/buildAndPush.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -e
currentDir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
rootDir="$currentDir/../../"

dockerRepository=$1

if [ -z "$1" ]
then
echo -e "\033[0;33mNo Docker Hub username provided. 'myshx' will be used.\033[0m"
dockerRepository="myshx"
fi

dockerTag=$2

if [ -z "$2" ]
then
echo -e "\033[0;33mNo Docker Tag provided. Latest will be used.\033[0m"
dockerTag="latest"
fi

(cd "$rootDir" && ./tools/scripts/openapi/regenerateOpenApi.sh)

(cd "$rootDir" && exec ./tools/scripts/server/buildJar.sh)
(cd "$rootDir" && exec ./tools/scripts/server/buildImage.sh "$dockerRepository" "$dockerTag")

(cd "$rootDir" && exec ./tools/scripts/client/build.sh)

(cd "$rootDir" && exec ./tools/scripts/client/buildDevImage.sh "$dockerRepository" "$dockerTag")
(cd "$rootDir" && exec ./tools/scripts/client/buildImage.sh "$dockerRepository" "$dockerTag")
10 changes: 3 additions & 7 deletions tools/scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ stage=$1

if [ -z "$1" ]
then
echo -e "\033[0;33mNo stage provided. 'LOCAL' stage will be used."
echo -e "\033[0;33mNo stage provided. 'local' stage will be used.\033[0m"
stage="local"
fi

(cd "$rootDir/server" && exec ./gradlew clean)
(cd "")
(cd "$rootDir" && exec docker compose \
-f ./tools/docker/docker-compose.yml \
--env-file ./tools/docker/env/$stage.env \
--project-name=muse-$stage \
down -v)
(cd "$rootDir" && exec docker compose \
-f ./tools/docker/docker-compose.yml \
--env-file ./tools/docker/env/$stage.env \
--project-name=muse-$stage \
rm -f)

echo -e "\033[0;32mResources has been cleaned.\033[0m"
4 changes: 2 additions & 2 deletions tools/scripts/client/buildDevImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ repository=$1

if [ -z "$1" ]
then
echo -e "\033[0;33mNo Docker Hub username provided. 'myshx' will be used."
echo -e "\033[0;33mNo Docker Hub username provided. 'myshx' will be used.\033[0m"
repository=myshx # my repository at DockerHub
fi

imageTag=$2

if [ -z "$2" ]
then
echo -e "\033[0;33mNo image tag provided. Latest will be used."
echo -e "\033[0;33mNo image tag provided. Latest will be used.\033[0m"
imageTag=latest
fi

Expand Down
4 changes: 2 additions & 2 deletions tools/scripts/client/buildImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ repository=$1

if [ -z "$1" ]
then
echo -e "\033[0;33mNo Docker Hub username provided. 'myshx' will be used."
echo -e "\033[0;33mNo Docker Hub username provided. 'myshx' will be used.\033[0m"
repository=myshx # my repository at DockerHub
fi

imageTag=$2

if [ -z "$2" ]
then
echo -e "\033[0;33mNo image tag provided. Latest will be used."
echo -e "\033[0;33mNo image tag provided. Latest will be used.\033[0m"
imageTag=latest
fi

Expand Down
4 changes: 2 additions & 2 deletions tools/scripts/client/pushImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ imageTag=$2

if [ -z "$1" ]
then
echo -e "\033[0;33mNo Docker Hub username provided. 'myshx' will be used."
echo -e "\033[0;33mNo Docker Hub username provided. 'myshx' will be used.\033[0m"
repository=myshx # my repository at DockerHub
fi

if [ -z "$2" ]
then
echo -e "\033[0;33mNo imageTag provided. Latest will be used."
echo -e "\033[0;33mNo imageTag provided. Latest will be used.\033[0m"
imageTag=latest
fi

Expand Down
75 changes: 16 additions & 59 deletions tools/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,47 @@
set -e
currentDir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
rootDir="$currentDir/../../"
gitCommitSha="$(git rev-parse --short HEAD)"

if [ -z "$SSH_HOST" ]; then
echo "Error: The required environment variable 'SSH_HOST' is not set."
echo -e "\033[0;31mError: The required environment variable 'SSH_HOST' is not set.\033[0m"
exit 1
fi

if [ -z "$SSH_PORT" ]; then
echo "Error: The required environment variable 'SSH_HOST' is not set."
echo -e "\033[0;31mError: The required environment variable 'SSH_HOST' is not set.\033[0m"
exit 1
fi

if [ -z "$SSH_USER" ]; then
echo "Error: The required environment variable 'SSH_USER' is not set."
echo -e "\033[0;31mError: The required environment variable 'SSH_USER' is not set.\033[0m"
exit 1
fi

if [ -z "$SSH_PASS" ]; then
echo "Error: The required environment variable 'SSH_PASS' is not set."
echo -e "\033[0;31mError: The required environment variable 'SSH_PASS' is not set.\033[0m"
exit 1
fi


dockerRepository=$1

if [ -z "$1" ]
then
echo -e "\033[0;33mNo Docker Hub username provided. 'myshx' will be used."
echo -e "\033[0;33mNo Docker Hub username provided. 'myshx' will be used.\033[0m"
dockerRepository="myshx"
fi

stage=$2

if [ -z "$2" ]
then
echo -e "\033[0;33mNo stage provided. 'DEV' stage will be used."
echo -e "\033[0;33mNo stage provided. 'DEV' stage will be used.\033[0m"
stage="dev"
fi

dockerTag="$stage-$gitCommitSha"

(cd "$rootDir" && exec ./tools/scripts/clean.sh local)

(cd "$rootDir" && ./tools/scripts/openapi/regenerateOpenApi.sh)

(cd "$rootDir" && exec ./tools/scripts/server/buildJar.sh)
(cd "$rootDir" && exec ./tools/scripts/server/buildImage.sh "$dockerRepository" "$dockerTag")

(cd "$rootDir" && exec ./tools/scripts/client/build.sh)

(cd "$rootDir" && exec ./tools/scripts/client/buildDevImage.sh "$dockerRepository" "$dockerTag")
(cd "$rootDir" && exec ./tools/scripts/client/buildImage.sh "$dockerRepository" "$dockerTag")
dockerTag="$stage-$(git rev-parse --short HEAD)"
(cd "$rootDir" && exec ./tools/scripts/stop.sh "$stage")
(cd "$rootDir" && exec ./tools/scripts/clean.sh "$stage")
(cd "$rootDir" && exec ./tools/scripts/buildAndPush.sh "$dockerRepository" "$dockerTag")

sshpass -p "$SSH_PASS" ssh -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" \
-o UserKnownHostsFile=/dev/null \
Expand All @@ -64,56 +53,24 @@ sshpass -p "$SSH_PASS" ssh -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" \
'bash -s' << 'EOF'
set -e
#export dockerRepository="$dockerRepository"
#export stage="$stage"
#export dockerTag="$dockerTag"
echo $dockerRepository
echo $stage
echo $dockerTag
echo $DOCKER_HUB_TOKEN
echo "one"
#docker login -u "$dockerRepository" -p "$DOCKER_HUB_TOKEN"
echo "two"
echo "four"
echo $RANDOM
random_number="$RANDOM"
echo "Debug: random_number is set to: '$random_number'"
echo "Random number: '$random_number'"
muse_project_path="/tmp/muse-project-$random_number"
echo "Project path: '$muse_project_path'"
git clone https://github.com/bas-kirill/muse-project.git "$muse_project_path"
echo "five"
cd "$muse_project_path"
echo "six"
./tools/scripts/clean.sh $stage
echo "seven"
export MUSE_SERVER_IMAGE="$dockerRepository/muse-server:$dockerTag"
export MUSE_CLIENT_IMAGE="$dockerRepository/muse-client:$dockerTag"
export MUSE_CLIENT_DEV_IMAGE="$dockerRepository/muse-client-dev:$dockerTag"
echo "one"
(cd ./tools/docker && docker compose config)
echo "two"
echo "eight"
docker compose \
-f ./tools/docker/docker-compose.yml \
--env-file ./tools/docker/env/$stage.env \
--project-name=muse-$stage \
up -d \
--remove-orphans
echo -e "\033[0;32mList of available ports:\n\033[0m"
cat ./tools/docker/env/$stage.env
./tools/scripts/stop.sh "$stage"
./tools/scripts/run.sh "$stage"
EOF

echo -e "\033[0;32mServices has been deployed to '$stage'.\033[0m"
echo -e "\033[0;32mList of available ports:\n\033[0m"
(cd "$rootDir" && exec cat ./tools/docker/env/local.env)
22 changes: 9 additions & 13 deletions tools/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@ set -e
currentDir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
rootDir="$currentDir/../../"

(cd "$rootDir" && exec ./tools/scripts/clean.sh)
stage=$1

(cd "$rootDir" && ./tools/scripts/openapi/regenerateOpenApi.sh)

(cd "$rootDir" && exec ./tools/scripts/server/buildJar.sh)
(cd "$rootDir" && exec ./tools/scripts/server/buildImage.sh)

(cd "$rootDir" && exec ./tools/scripts/client/build.sh)
(cd "$rootDir" && exec ./tools/scripts/client/buildDevImage.sh)
(cd "$rootDir" && exec ./tools/scripts/client/buildImage.sh)
if [ -z "$1" ]
then
echo -e "\033[0;33mNo stage provided. 'local' stage will be used.\033[0m"
stage="local"
fi

(cd "$rootDir" && exec docker compose \
-f ./tools/docker/docker-compose.yml \
--env-file ./tools/docker/env/local.env \
--project-name=muse-project \
--env-file ./tools/docker/env/$stage.env \
--project-name=muse-$stage \
up -d \
--remove-orphans)

echo -e "\033[0;32mList of available ports:\n\033[0m"
(cd "$rootDir" && exec cat ./tools/docker/env/local.env)
echo -e "\033[0;32mDocker Serviced has been started.\n\033[0m"
12 changes: 12 additions & 0 deletions tools/scripts/runLocal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e
currentDir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
rootDir="$currentDir/../../"

(cd "$rootDir" && exec ./tools/scripts/stop.sh)
(cd "$rootDir" && exec ./tools/scripts/clean.sh)
(cd "$rootDir" && exec ./tools/scripts/buildAndPush.sh)
(cd "$rootDir" && exec ./tools/scripts/run.sh)

echo -e "\033[0;32mList of available ports:\n\033[0m"
(cd "$rootDir" && exec cat ./tools/docker/env/local.env)
21 changes: 21 additions & 0 deletions tools/scripts/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -e
currentDir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
rootDir="$currentDir/../../"

stage=$1

if [ -z "$1" ]
then
echo -e "\033[0;33mNo stage provided. 'local' stage will be used.\033[0m"
stage="local"
fi


(cd "$rootDir" && exec docker compose \
-f ./tools/docker/docker-compose.yml \
--env-file ./tools/docker/env/$stage.env \
--project-name=muse-$stage \
rm -f)

echo -e "\033[0;32mDocker Service has been stopped.\033[0m"

0 comments on commit 913c064

Please sign in to comment.