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

feat: start local env #67

Merged
merged 1 commit into from
Sep 17, 2024
Merged
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
69 changes: 69 additions & 0 deletions scripts/start_local_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/sh

# remember to chmod +x start_local_env.sh
kotorekisteri_start_tmux() {
SESS_NAME=kotorekisteri
PANE1=kotorekisteri
REPO_ROOT=${1:-'.'}

(
cd $REPO_ROOT

# Install dependencies
echo "Installing dependencies..."
mise install

# Use old session if exists
tmux has-session -t $SESS_NAME 2>/dev/null
if [ $? -eq 0 ]; then
tmux attach -t $SESS_NAME
# TODO: Instead of return, kill the old session.
return
Comment on lines +19 to +21
Copy link
Contributor Author

@saku-koodari saku-koodari Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Näin se poistais vanhan session, jos haluais, että scripti luo kaiken aina alusta.

Suggested change
tmux attach -t $SESS_NAME
# TODO: Instead of return, kill the old session.
return
tmux kill-session -t $SESS_NAME

fi

# If there is no session...
# Start a new tmux session and detach immediately
# Window 0:zsh
echo "Starting new tmux session..."
tmux new-session -d -s $SESS_NAME

# Window 0:database
WINDOW="database"
# database: left pane (docker running)
tmux rename-window -t $SESS_NAME:0 "$WINDOW"
tmux send-keys -t $SESS_NAME:"$WINDOW.0" "open -a \"Docker\"" C-m
tmux send-keys -t $SESS_NAME:"$WINDOW.0" "docker compose up" C-m

# database: right pane (flyway migrate)
tmux split-window -h -t $SESSION:"$WINDOW"
tmux send-keys -t $SESS_NAME:"$WINDOW.1" "(cd server &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tää on vähä ruma stdoutissa, mutta hoitaa asiansa, eli ajaa migraatiot sitten kun docker on pystyssä.

sleep 5 && echo \"10 seconds left to run migrations...\" &&
sleep 5 && echo \"05 seconds left to run migrations...\" &&
./mvnw flyway:migrate)" C-m

# Window 1:idea
WINDOW="idea"
tmux new-window -t $SESS_NAME -n "idea"
tmux send-keys -t $SESS_NAME:"idea" "idea ." C-m

# Window 2:springboot
WINDOW="springboot"
tmux new-window -t $SESS_NAME -n "$WINDOW"
tmux send-keys -t $SESS_NAME:"$WINDOW" "cd server && sleep 5" C-m
tmux send-keys -t $SESS_NAME:"$WINDOW" "mvn clean install" C-m
tmux send-keys -t $SESS_NAME:"$WINDOW" "mvn package" C-m
tmux send-keys -t $SESS_NAME:"$WINDOW" "./mvnw spring-boot:run" C-m

# Window 3:workspace
WINDOW="workspace"
tmux new-window -t $SESS_NAME -n "$WINDOW"
tmux send-keys -t $SESS_NAME:"$WINDOW" "git log --oneline --decorate=full --graph --all --oneline" C-m
tmux split-window -h -t $SESSION:"$WINDOW"
tmux send-keys -t $SESS_NAME:"$WINDOW.1" "ls -la" C-m
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tree:llä sais must paremman puurakenteen

Suggested change
tmux send-keys -t $SESS_NAME:"$WINDOW.1" "ls -la" C-m
tmux send-keys -t $SESS_NAME:"$WINDOW.1" "tree -L 2" C-m

tmux send-keys -t $SESS_NAME:"$WINDOW.1" "git status" C-m

tmux attach
)
}

kotorekisteri_start_tmux $1