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: update migration script & add switch #283

Open
wants to merge 47 commits into
base: chore/add-binary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
52814c1
feat: update migration script & add switch
surajgour-d11 Feb 18, 2025
c9dfc35
feat: update binary
surajgour-d11 Feb 20, 2025
bb391fe
chore: updatecli binary
surajgour-d11 Feb 20, 2025
3bd4759
Update switch.py
yash-saxena-d11 Feb 20, 2025
e677581
check for service deploy using file
aakash-d11 Feb 21, 2025
896d408
update downloading logic
yash-saxena-d11 Feb 21, 2025
3864952
fix import
yash-saxena-d11 Feb 21, 2025
1df31e8
chore: update binary location
yash-saxena-d11 Feb 22, 2025
81c512d
updated migration script
aakash-d11 Feb 22, 2025
e7ea776
fix: handle operate and undeploy, correct migration check
yash-saxena-d11 Feb 24, 2025
a837b81
fix: add default execution
yash-saxena-d11 Feb 24, 2025
8169a23
fix: default execution
yash-saxena-d11 Feb 24, 2025
fd11aa4
fix: handle absence of service name
yash-saxena-d11 Feb 24, 2025
bbb820b
added support for delete
aakash-d11 Feb 24, 2025
46bedab
feat: handle service set
yash-saxena-d11 Feb 24, 2025
60c432a
merge origin
aakash-d11 Feb 24, 2025
f6dc2ed
Merge branch 'update/mig-script' of https://github.com/dream11/odin i…
aakash-d11 Feb 24, 2025
afd288b
fix for set env
aakash-d11 Feb 24, 2025
d096db4
feat: add service-set routing
yash-saxena-d11 Feb 26, 2025
4eb1923
progress save
aakash-d11 Feb 26, 2025
b80b38b
chore: minor fixes
yash-saxena-d11 Feb 27, 2025
61f8fd0
progress save
aakash-d11 Feb 27, 2025
554a7d2
merge origin
aakash-d11 Feb 27, 2025
6088a6d
added handling for cases where default env is set
aakash-d11 Feb 27, 2025
55ca228
fix: read config file for deciding dreampay
yash-saxena-d11 Feb 27, 2025
4270d1f
fix: old odin path init (#286)
surajgour-d11 Feb 28, 2025
b96adb7
chore: minor fixes (#287)
yash-saxena-d11 Feb 28, 2025
39452be
removed the team and created by columns from list env table
aakash-d11 Feb 28, 2025
cdf7f49
Merge branch 'update/mig-script' of https://github.com/dream11/odin i…
aakash-d11 Feb 28, 2025
bd29479
Merge pull request #288 from dream11/update/mig-aakash
aakash-d11 Feb 28, 2025
69b6629
chore: add python xcode symlink (#291)
surajgour-d11 Feb 28, 2025
8ca3075
chore: remove log (#292)
surajgour-d11 Feb 28, 2025
35a0d5e
feat: handle env create defaults (#298)
surajgour-d11 Mar 2, 2025
be09db5
Fix: add support for label for new odin (#297)
umanggoyald11 Mar 2, 2025
7a5ab29
chore: handled provisioning type for new envs (#296)
aakash-d11 Mar 2, 2025
78fe7c7
Fix : change ,atch to if-else (#300)
umanggoyald11 Mar 2, 2025
aba6c43
Update/mig aakash (#301)
aakash-d11 Mar 3, 2025
1403cad
Update/mig aakash (#303)
aakash-d11 Mar 3, 2025
6950a98
Update/mig aakash (#304)
aakash-d11 Mar 4, 2025
81159d7
Update/mig aakash (#305)
aakash-d11 Mar 4, 2025
c8aa065
fix: shared envs (#306)
yash-saxena-d11 Mar 4, 2025
0454ee6
chore: add none check (#308)
yash-saxena-d11 Mar 4, 2025
80b5b53
fix describe env
mnishhhD11 Mar 11, 2025
d399240
resolved comments
mnishhhD11 Mar 11, 2025
71a23f2
Merge pull request #309 from dream11/fix/describe-env
mnishhhD11 Mar 11, 2025
23ea7e7
fix add_component service name fetch (#311)
mnishhhD11 Mar 15, 2025
61c7bae
Update/mig aakash (#314)
aakash-d11 Mar 17, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bin
*.code-workspace
*.idea/
.DS_Store
.vscode/

# Service definition files
service.yaml
Expand Down
164 changes: 47 additions & 117 deletions migrate-odin.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,130 +1,60 @@
#!/bin/bash
set -e

# Revert function to restore old odin binary
revert_odin() {
echo "Reverting to old odin binary..."

# Check if there is a backup (old-odin) somewhere
if [ -f /usr/local/bin/old-odin ]; then
# If backup exists, remove any current odin binary
if [ -f /usr/local/bin/odin ]; then
sudo rm -f /usr/local/bin/odin
echo "Removed existing odin binary from /usr/local/bin"
# Check if Python is installed
if ! command -v python &>/dev/null; then
if command -v /Library/Developer/CommandLineTools/usr/bin/python3 &>/dev/null; then
sudo ln -s /Library/Developer/CommandLineTools/usr/bin/python3 /usr/local/bin/python
elif command -v python3 &>/dev/null; then
path=$(command -v python3)
sudo ln -s "$path" /usr/local/bin/python
else
echo "Python is not installed. Installing via Homebrew..."

# Check if Homebrew is installed
if ! command -v brew &>/dev/null; then
echo "Homebrew is not installed. Please install Homebrew first."
exit 1
fi
# Install Python using Homebrew
brew install python
fi

if [ -f /opt/homebrew/bin/odin ]; then
sudo rm -f /opt/homebrew/bin/odin
echo "Removed existing odin binary from /opt/homebrew/bin"
# Verify installation
if command -v python &>/dev/null; then
echo "Python successfully installed!"
else
echo "Python installation failed."
exit 1
fi
fi

# Restore the old-odin backup
sudo mv /usr/local/bin/old-odin /usr/local/bin/odin
chmod 755 /usr/local/bin/odin
echo "Reverted to the old odin binary successfully from /usr/local/bin, configure again to start using odin"

elif [ -f /opt/homebrew/bin/old-odin ]; then
# If backup exists, remove any current odin binary
if [ -f /opt/homebrew/bin/odin ]; then
sudo rm -f /opt/homebrew/bin/odin
echo "Removed existing odin binary from /opt/homebrew/bin"
fi
touch ~/.odin/config.toml

if [ -f /usr/local/bin/odin ]; then
sudo rm -f /usr/local/bin/odin
echo "Removed existing odin binary from /usr/local/bin"
# Define the function block
ODIN_FUNCTION='
#####ODIN_SWITCH_BEGIN#####
odin() {
curl --silent -o ~/.odin/switch.py https://artifactory.dream11.com/migrarts/odin-artifact/switch-script.py
if [ $? -ne 0 ]; then
echo "Failed to download the switch script. Exiting."
exit 1
fi

# Restore the old-odin backup
sudo mv /opt/homebrew/bin/old-odin /opt/homebrew/bin/odin
chmod 755 /opt/homebrew/bin/odin
echo "Reverted to the old odin binary successfully from /opt/homebrew/bin, configure again to start using odin"

else
echo "No backup odin binary found to revert to."
exit 1
fi
python ~/.odin/switch.py "$@"
}
#####ODIN_SWITCH_END#####
'

add_odin_to_shell_config() {
local shell_config="$1"

if [[ -f "$shell_config" ]]; then
cp "$shell_config" "$shell_config".bak && sed '/#####ODIN_SWITCH_BEGIN#####/,/#####ODIN_SWITCH_END#####/d' "$shell_config".bak > "$shell_config"
echo "$ODIN_FUNCTION" >> "$shell_config"
fi
}

# Check for revert flag
if [ "$1" == "revert" ]; then
revert_odin
exit 0
fi


# Fetching the odin binary from GitHub
curl -L -o ./odin https://raw.githubusercontent.com/dream11/odin/chore/add-binary/odin
if [ $? -ne 0 ]; then
echo "Failed to download the odin binary. Exiting."
exit 1
fi
chmod +x ./odin

echo "Downloaded the odin binary successfully."


if [ -f /usr/local/bin/odin ] && [ ! -f /usr/local/bin/old-odin ] && [ ! -f /opt/homebrew/bin/old-odin ]; then
echo "Existing odin binary found, moving it to backup."
sudo mv /usr/local/bin/odin /usr/local/bin/old-odin
fi

# Handle /opt/homebrew/bin case if it exists
if [ -f /opt/homebrew/bin/odin ] && [ ! -f /opt/homebrew/bin/old-odin ] && [ ! -f /usr/local/bin/old-odin ]; then
echo "Homebrew odin binary found, moving it to backup."
sudo mv /opt/homebrew/bin/odin /opt/homebrew/bin/old-odin
fi

sudo mv ./odin /usr/local/bin/
chmod 755 /usr/local/bin/odin


# Enable app verification and remove quarantine attributes
sudo spctl --master-enable
xattr -dr com.apple.quarantine /usr/local/bin/odin

# Verify the new odin installation
echo "New odin installed, running odin version to verify [Should output 2.0.0]"
odin version || { echo "Odin version verification failed."; exit 1; }


# Read access and secret keys from ~/.odin/config if they exist
CONFIG_FILE=~/.odin/config
if [ -f "$CONFIG_FILE" ]; then
echo "Reading access and secret keys from config."
ODIN_ACCESS_KEY=$(awk '/access_key:/ && !/secret_access_key:/ {print $2}' $CONFIG_FILE)
ODIN_SECRET_ACCESS_KEY=$(awk '/secret_access_key:/ {print $2}' $CONFIG_FILE)
else
echo "Config file not found. Prompting user for keys."
read -p "Enter ODIN_ACCESS_KEY: " ODIN_ACCESS_KEY </dev/tty
read -p "Enter ODIN_SECRET_ACCESS_KEY: " ODIN_SECRET_ACCESS_KEY </dev/tty
fi

# If keys are empty or file doesn't exist, prompt user for input
if [ -z "${ODIN_ACCESS_KEY:-}" ] || [ -z "${ODIN_SECRET_ACCESS_KEY:-}" ]; then
echo "Access keys are missing"
read -p "Enter ODIN_ACCESS_KEY: " ODIN_ACCESS_KEY </dev/tty
read -p "Enter ODIN_SECRET_ACCESS_KEY: " ODIN_SECRET_ACCESS_KEY </dev/tty
fi

# Backup existing configuration if it exists
if [ -f ~/.odin/config ]; then
echo "Existing odin config found, creating a backup."
mv ~/.odin/config ~/.odin/old-config
fi

# Set environment variables
export ODIN_ACCESS_KEY=${ODIN_ACCESS_KEY}
export ODIN_SECRET_ACCESS_KEY=${ODIN_SECRET_ACCESS_KEY}
export ODIN_BACKEND_ADDRESS="odin-deployer.dss-platform.private:80"
# Add to both ~/.zshrc and ~/.bashrc
add_odin_to_shell_config "$HOME/.zshrc"
add_odin_to_shell_config "$HOME/.bashrc"
#add_odin_to_shell_config "$HOME/.bash_profile"

# Configure odin
odin configure
if [ $? -eq 0 ]; then
echo "Odin configured successfully."
else
echo "Failed to configure odin."
exit 1
fi
Binary file added odin-2.0.0
Binary file not shown.
Loading