Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dev): update deploy to dev script #127

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions tools/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ services:
interval: 5s
timeout: 5s
retries: 5
profiles:
- dev
- prod

muse-server:
image: "${MUSE_SERVER_IMAGE:-muse-server}"
# platforms:
# - "linux/amd64"
# - "linux/arm64"
container_name: "${MUSE_SERVER_IMAGE:-muse-server}"
container_name: muse-server
ports:
- ${SERVER_PORT}:8080
- ${SERVER_DEBUG_PORT}:5005
Expand All @@ -44,28 +47,36 @@ services:
depends_on:
postgres:
condition: service_healthy
profiles:
- dev
- prod

# muse-client:
# image: "${MUSE_CLIENT_IMAGE:-muse-client}"
## platforms:
## - "linux/amd64"
## - "linux/arm64"
# container_name: "${MUSE_CLIENT_IMAGE:-muse-client}"
# ports:
# - ${CLIENT_PORT}:80
# networks:
# - muse
muse-client:
image: "${MUSE_CLIENT_IMAGE:-muse-client}"
# platforms:
# - "linux/amd64"
# - "linux/arm64"
container_name: "${MUSE_CLIENT_IMAGE:-muse-client}"
ports:
- ${CLIENT_PORT}:80
networks:
- muse
profiles:
- dev
- prod

# muse-client-dev:
# image: "${MUSE_CLIENT_DEV_IMAGE:-muse-client-dev}"
# container_name: muse-client-dev
# ports:
# - ${CLIENT_DEV_PORT}:3000
# volumes:
# - ./../../client:/muse-client-dev
# - ./node-modules:/muse-client-dev/node-modules
# networks:
# - muse
muse-client-dev:
image: "${MUSE_CLIENT_DEV_IMAGE:-muse-client-dev}"
container_name: muse-client-dev
ports:
- ${CLIENT_DEV_PORT}:3000
volumes:
- ./../../client:/muse-client-dev
- ./node-modules:/muse-client-dev/node-modules
networks:
- muse
profiles:
- dev

# portainer:
# image: portainer/portainer-ce:linux-amd64-2.20.3-alpine
Expand Down
2 changes: 1 addition & 1 deletion tools/docker/env/dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ POSTGRES_PORT=5555
POSTGRES_USER=muse
POSTGRES_PASSWORD=muse
POSTGRES_DB=muse
POSTGRES_DSN=jdbc:postgresql://muse-postgres:5555/muse
POSTGRES_DSN=jdbc:postgresql://muse-postgres:5432/muse
72 changes: 48 additions & 24 deletions tools/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ if [ -z "$SSH_PASS" ]; then
exit 1
fi

function finish {
echo "Script finished. Executing final command."
docker context use default
}

trap 'finish' EXIT


stage=$1

if [ -z "$1" ]
Expand All @@ -44,33 +52,49 @@ dockerTag="$stage-$(git rev-parse --short HEAD)"
(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 \
-o StrictHostKeyChecking=no \
env dockerRepository="$dockerRepository" \
env dockerTag="$dockerTag" \
env stage="$stage" \
'bash -s' << 'EOF'
set -e

random_number="$RANDOM"
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"
cd "$muse_project_path"
context_name=muse-deploy-server
if ! docker context ls --format '{{.Name}}' | grep -q "^${context_name}$"; then
docker context create "${context_name}" --description "[MUSE] Deploy Server" --docker "host=ssh://[email protected]"
fi

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"
#if ! docker context inspect "$context_name" &>/dev/null; then
#
#fi

echo "one"
(cd ./tools/docker && docker compose config)
echo "two"
docker context use muse-deploy-server

./tools/scripts/stop.sh "$stage"
./tools/scripts/run.sh "$stage"
EOF
(cd "$rootDir" && exec ./tools/scripts/run.sh "$stage" "prod")

echo -e "\033[0;32mList of available ports:\n\033[0m"
(cd "$rootDir" && exec cat ./tools/docker/env/local.env)


#sshpass -p "$SSH_PASS" ssh -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" \
# -o UserKnownHostsFile=/dev/null \
# -o StrictHostKeyChecking=no \
# env dockerRepository="$dockerRepository" \
# env dockerTag="$dockerTag" \
# env stage="$stage" \
# env MUSE_JWT_SECRET_KEY="$MUSE_JWT_SECRET_KEY" \
# 'bash -s' << 'EOF'
#set -e
#
#random_number="$RANDOM"
#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"
#cd "$muse_project_path"
#
#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"
#
#./tools/scripts/stop.sh "$stage"
#./tools/scripts/run.sh "$stage"
#EOF
#
9 changes: 9 additions & 0 deletions tools/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ if [ -z "$1" ]
stage="local"
fi

profile=$2

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

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

Expand Down
13 changes: 7 additions & 6 deletions tools/scripts/runLocal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ rootDir="$currentDir/../../"

stage=$1

dockerTag="latest"
if [ -z "$1" ]
then
echo -e "\033[0;33mNo stage provided. 'local' stage will be used.\033[0m"
stage="local"
dockerTag="$stage-$(git rev-parse --short HEAD)"
fi

dockerRepository=$2
Expand All @@ -23,12 +21,15 @@ fi

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

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

MUSE_SERVER_IMAGE="$dockerRepository/muse-server:$dockerTag"
MUSE_CLIENT_IMAGE="$dockerRepository/muse-client:$dockerTag"
MUSE_CLIENT_DEV_IMAGE="$dockerRepository/muse-client-dev:$dockerTag"
(cd "$rootDir" && exec ./tools/scripts/run.sh "$stage")
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"
(cd "$rootDir/tools/docker" && exec docker compose config)
(cd "$rootDir" && exec ./tools/scripts/run.sh "$stage" "dev")

echo -e "\033[0;32mList of available ports:\n\033[0m"
(cd "$rootDir" && exec cat ./tools/docker/env/$stage.env)
Loading