Skip to content

Commit

Permalink
Merge pull request #123 from bas-kirill/bugfix/deploy-to-dev-error-wi…
Browse files Browse the repository at this point in the history
…th-docker

fix(dev):  deploy to dev
  • Loading branch information
bas-kirill authored Aug 26, 2024
2 parents ffb4237 + 890b7c9 commit 3c68b3e
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 97 deletions.
6 changes: 6 additions & 0 deletions tools/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ services:

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

muse-client:
image: "${MUSE_CLIENT_IMAGE:-muse-client}"
platform:
- "linux/amd64"
- "linux/arm64"
container_name: muse-client
ports:
- ${CLIENT_PORT}:80
Expand Down
1 change: 1 addition & 0 deletions tools/scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if [ -z "$1" ]
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 \
Expand Down
20 changes: 17 additions & 3 deletions tools/scripts/client/buildDevImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ set -e
currentDir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
rootDir="$currentDir/../../../"

imageTag=$1
repository=$1

if [ -z "$1" ]
then
echo -e "\033[0;33mNo Docker Hub username provided. 'myshx' will be used."
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."
imageTag=latest
fi

imageFullName=muse-client-dev:$imageTag
imageFullName=$repository/muse-client-dev:$imageTag

echo [MUSE CLIENT DEV STARTING] building "$imageFullName"...

Expand All @@ -24,6 +32,12 @@ if docker images -q "$imageFullName" &> /dev/null; then
fi

echo [MUSE CLIENT DEV] creating docker image "$imageFullName"...
(docker build -f "${rootDir}/client/Dockerfile.dev" -t "$imageFullName" "$rootDir")
(DOCKER_BUILDKIT=1 docker buildx build \
--platform linux/arm64,linux/amd64 \
-f "${rootDir}/client/Dockerfile.dev" \
-t "$imageFullName" \
"$rootDir" \
--push)

echo -e "\033[0;32m[MUSE CLIENT DEV FINISHED] image '$imageFullName' has been built.\033[0m"
# --platform linux/amd64,linux/arm64 \
22 changes: 18 additions & 4 deletions tools/scripts/client/buildImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@ set -e
currentDir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
rootDir="$currentDir/../../../"

imageTag=$1
repository=$1

if [ -z "$1" ]
then
echo -e "\033[0;33mNo Docker Hub username provided. 'myshx' will be used."
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."
imageTag=latest
fi

imageFullName=muse-client:$imageTag
imageFullName=$repository/muse-client:$imageTag

echo [MUSE CLIENT STARTING] building "$imageFullName"...
echo "[MUSE CLIENT STARTING] building '$imageFullName'..."

echo [MUSE CLIENT] remove old image "$imageFullName"...

Expand All @@ -24,6 +32,12 @@ if docker images -q "$imageFullName" &> /dev/null; then
fi

echo [MUSE CLIENT] creating docker image "$imageFullName"...
(docker build -f "${rootDir}/client/Dockerfile" -t "$imageFullName" "$rootDir")
(DOCKER_BUILDKIT=1 docker buildx build \
--platform linux/arm64,linux/amd64 \
-f "${rootDir}/client/Dockerfile" \
-t "$imageFullName" \
"$rootDir" \
--push)

echo -e "\033[0;32m[MUSE CLIENT FINISHED] image '$imageFullName' has been built\033[0m"
# --platform linux/amd64,linux/arm64 \
23 changes: 0 additions & 23 deletions tools/scripts/client/pushDevImage.sh

This file was deleted.

62 changes: 30 additions & 32 deletions tools/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ currentDir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
rootDir="$currentDir/../../"
gitCommitSha="$(git rev-parse --short HEAD)"

if [ -z "$DOCKER_HUB_TOKEN" ]; then
echo "Error: The required environment variable 'DOCKER_HUB_TOKEN' is not set."
exit 1
fi

if [ -z "$SSH_HOST" ]; then
echo "Error: The required environment variable 'SSH_HOST' is not set."
exit 1
Expand Down Expand Up @@ -46,53 +41,56 @@ if [ -z "$2" ]
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 "$dockerTag")
(cd "$rootDir" && exec ./tools/scripts/pushImage.sh "$dockerRepository" "muse-server" "$dockerTag")
(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 "$dockerTag")
(cd "$rootDir" && exec ./tools/scripts/pushImage.sh "$dockerRepository" "muse-client-dev" "$dockerTag")

(cd "$rootDir" && exec ./tools/scripts/client/buildImage.sh "$dockerTag")
(cd "$rootDir" && exec ./tools/scripts/pushImage.sh "$dockerRepository" "muse-client" "$dockerTag")

sshpass -p "$SSH_PASS" ssh -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" << EOF
(cd "$rootDir" && exec ./tools/scripts/client/buildDevImage.sh "$dockerRepository" "$dockerTag")
(cd "$rootDir" && exec ./tools/scripts/client/buildImage.sh "$dockerRepository" "$dockerTag")

sshpass -p "$SSH_PASS" ssh -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
-q \
env dockerRepository="$dockerRepository" \
env dockerTag="$dockerTag" \
env stage="$stage" \
'bash -s' << 'EOF'
set -e
#
#export dockerRepository="$dockerRepository"
#export stage="$stage"
#export dockerTag="$dockerTag"
export dockerRepository=$dockerRepository
echo \$dockerRepository
export stage=$stage
echo \$stage
export dockerTag=$dockerTag
echo \$dockerTag
export DOCKER_HUB_TOKEN=$DOCKER_HUB_TOKEN
echo \$DOCKER_HUB_TOKEN
echo $dockerRepository
echo $stage
echo $dockerTag
echo $DOCKER_HUB_TOKEN
echo "one"
#docker login -u $dockerRepository -p $DOCKER_HUB_TOKEN
#docker login -u "$dockerRepository" -p "$DOCKER_HUB_TOKEN"
echo "two"
cd /tmp
echo "three"
rm -rf /home/kiryuxa/github-deploy
mkdir -p /home/kiryuxa/github-deploy
echo "four"
cd /home/kiryuxa/github-deploy
git clone https://github.com/bas-kirill/muse-project.git
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
cd "$muse_project_path"
echo "six"
./tools/scripts/clean.sh $stage
Expand Down
30 changes: 0 additions & 30 deletions tools/scripts/pushImage.sh

This file was deleted.

23 changes: 18 additions & 5 deletions tools/scripts/server/buildImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ set -e
currentDir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
rootDir="$currentDir/../../../"

imageTag=$1
repository=$1

if [ -z "$1" ]
then
echo -e "\033[0;33mNo Docker Hub username provided. 'myshx' will be used."
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."
imageTag=latest
fi

imageFullName=muse-server:$imageTag
imageFullName=$repository/muse-server:$imageTag

echo [MUSE SERVER STARTING] building "$imageFullName"...

Expand All @@ -24,6 +32,11 @@ if docker images -q "$imageFullName" &> /dev/null; then
fi

echo [MUSE SERVER] creating docker image "$imageFullName"...
(docker build -f "${rootDir}/server/Dockerfile" -t "$imageFullName" "$rootDir")

echo -e "\033[0;32m[MUSE SERVER FINISHED] image '$imageFullName' has been built.\033[0m"
(DOCKER_BUILDKIT=1 docker buildx build \
--platform linux/arm64,linux/amd64 \
-f "${rootDir}/server/Dockerfile" \
-t "$imageFullName" \
"$rootDir" \
--push)

echo -e "\033[0;32m[MUSE SERVER FINISHED] image '$imageFullName' has been built.\033[0m"

0 comments on commit 3c68b3e

Please sign in to comment.