Skip to content

Commit

Permalink
Merge pull request #72 from OpenMined/rasswanth/fix-cd-deploy
Browse files Browse the repository at this point in the history
[CD] Fix Deploy CD
  • Loading branch information
yashgorana authored Oct 9, 2024
2 parents 4c5ba8b + 31f8328 commit bee1afa
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ serialize =
[bumpversion:file:pyproject.toml]

[bumpversion:file:syftbox/__version__.py]

[bumpversion:file:.github/workflows/cd-deploy.yaml]
16 changes: 9 additions & 7 deletions .github/workflows/cd-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
version:
description: "SyftBox Version to deploy"
type: string
default: latest
default: 0.1.3

# Prevents concurrent runs of the same workflow
# while the previous run is still in progress
Expand All @@ -15,23 +15,25 @@ concurrency:
cancel-in-progress: false

jobs:

deploy-syftbox-server:
runs-on: ubuntu-latest

steps:
- name: Checkout SyftBox repo
uses: actions/checkout@v4

- name: Install Just
uses: extractions/setup-just@v2
with:
just-version: "1.36.0"

- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SYFTBOX_SERVER_PRIVATE_KEY }}" > ~/.ssh/syftbox.pem
chmod 600 ~/.ssh/syftbox.pem
ssh-keyscan -H "20.168.10.234" >> ~/.ssh/known_hosts
mkdir -p ~/.ssh
echo "${{ secrets.SYFTBOX_SERVER_PRIVATE_KEY }}" > ~/.ssh/syftbox.pem
chmod 600 ~/.ssh/syftbox.pem
ssh-keyscan -H "20.168.10.234" >> ~/.ssh/known_hosts
- name: Deploy SyftBox Server
run: |
just deploy ~/.ssh/syftbox.pem ${{ inputs.version }}
just upload-pip ${{ inputs.version }} ~/.ssh/syftbox.pem [email protected]
100 changes: 53 additions & 47 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ alias rs := run-server
alias rc := run-client
alias rj := run-jupyter
alias b := build
alias d := deploy

# ---------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -76,51 +75,6 @@ build:
rm -rf dist
uv build

[group('build')]
fetch-syftbox-version version="latest":
#!/bin/bash
set -euo pipefail

# If version is latest, then fetch the latest version from PyPI
# else, check if the version exists on PyPI
if [ "{{ version }}" = "latest" ]; then
echo "Fetching the latest version of syftbox from PyPI..."
curl -sSf "https://pypi.org/pypi/syftbox/json" | jq -r ".info.version" || { echo "Failed to fetch the latest version." >&2; exit 1; }
else
echo "Checking if syftbox version {{ version }} exists on PyPI..."
if curl -sSf -o /dev/null "https://pypi.org/pypi/syftbox/{{ version }}/json"; then
echo "{{ version }}"
else
echo "syftbox version {{ version }} does not exist." >&2
exit 1
fi
fi


# Build & Deploy syftbox to a remote server using SSH
[group('build')]
deploy keyfile version="latest" remote="[email protected]":
#!/bin/bash
set -eou pipefail

# change permissions to comply with ssh/scp
chmod 600 {{ keyfile }}

# Sanity Check the syft box version
REMOTE_VERSION=$(just fetch-syftbox-version {{ version }} | tail -n 1)

echo -e "Deploying syftbox version $REMOTE_VERSION to {{ remote }}..."

# install pip package
ssh -i {{ keyfile }} {{ remote }} "pip install syftbox==$REMOTE_VERSION --break-system-packages --force"

# restart service
# TODO - syftbox service was created manually on 20.168.10.234
ssh -i {{ keyfile }} {{ remote }} "sudo systemctl daemon-reload"
ssh -i {{ keyfile }} {{ remote }} "sudo systemctl restart syftbox"

echo -e "{{ _green }}Deploy successful!{{ _nc }}"

# Bump version, commit and tag
[group('build')]
bump-version level="patch":
Expand Down Expand Up @@ -151,9 +105,61 @@ bump-version level="patch":

# ---------------------------------------------------------------------------------------------------------------------

# Build & Deploy syftbox to a remote server using SSH
[group('deploy')]
upload-dev keyfile remote="[email protected]": build
#!/bin/bash
set -eou pipefail

# there will be only one wheel file in the dist directory, but you never know...
LOCAL_WHEEL=$(ls dist/*.whl | grep syftbox | head -n 1)

# Remote paths to copy the wheel to
REMOTE_DIR="~"
REMOTE_WHEEL="$REMOTE_DIR/$(basename $LOCAL_WHEEL)"

echo -e "Deploying {{ _cyan }}$LOCAL_WHEEL{{ _nc }} to {{ _green }}{{ remote }}:$REMOTE_WHEEL{{ _nc }}"

# change permissions to comply with ssh/scp
chmod 600 {{ keyfile }}

# Use scp to transfer the file to the remote server
scp -i {{ keyfile }} "$LOCAL_WHEEL" "{{ remote }}:$REMOTE_DIR"

# install pip package
ssh -i {{ keyfile }} {{ remote }} "pip install --break-system-packages $REMOTE_WHEEL --force"

# restart service
# TODO - syftbox service was created manually on 20.168.10.234
ssh -i {{ keyfile }} {{ remote }} "sudo systemctl daemon-reload"
ssh -i {{ keyfile }} {{ remote }} "sudo systemctl restart syftbox"
echo -e "{{ _green }}Deployed SyftBox local wheel to {{ remote }}{{ _nc }}"

# Deploy syftbox from pypi to a remote server using SSH
[group('deploy')]
upload-pip version keyfile remote="[email protected]":
#!/bin/bash
set -eou pipefail

# change permissions to comply with ssh/scp
chmod 600 {{ keyfile }}

echo -e "Deploying syftbox version {{ version }} to {{ remote }}..."

# install pip package
ssh -i {{ keyfile }} {{ remote }} "pip install syftbox=={{ version }} --break-system-packages --force"

# restart service
ssh -i {{ keyfile }} {{ remote }} "sudo systemctl daemon-reload"
ssh -i {{ keyfile }} {{ remote }} "sudo systemctl restart syftbox"

echo -e "{{ _green }}Deployed SyftBox {{ version }} to {{ remote }}{{ _nc }}"

# ---------------------------------------------------------------------------------------------------------------------

[group('utils')]
ssh keyfile remote="[email protected]":
ssh -i {{ keyfile }} {{ remote }}
ssh -i {{ keyfile }} {{ remote }}

# remove all local files & directories
[group('utils')]
Expand Down

0 comments on commit bee1afa

Please sign in to comment.