Last active
September 29, 2022 20:31
-
-
Save nkthiebaut/f2a0c108dc447a3a0ddcd0c2b5e3da9f to your computer and use it in GitHub Desktop.
Script to add a GitHub repo on a SageMaker notebook when SSO is enforce on GitHub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 0: Attach a lifecycle configuration to you Notebook instance to persist environments between sessions | |
# See https://modelpredict.com/sagemaker-save-your-conda-environments/ for instruction | |
# Alternative: create environments under the persisted folder (/home/ec2-user/SageMaker) with | |
# conda create -p /home/ec2-user/SageMaker/py310 python=3.10 | |
# then systematically symlink: ln -s /home/ec2-user/SageMaker/py310 ~/anaconda3/envs/py310 | |
# 1: Create a new conda environment and make it accessible to SageMaker | |
conda create -y -n py310 python=3.10 | |
conda activate py310 | |
# From https://forum.deepchem.io/t/deploying-a-deepchem-sagemaker-notebook-instance/174 | |
conda install -y ipykernel && python -m ipykernel install --user --name=py310 | |
# 2: Set up GitHub connection | |
conda install -y gh --channel conda-forge | |
# You can either login through the UI, or | |
# create a keypair in GitHub https://github.com/settings/tokens with repo, read:org, and admin:public_key permissions, then click on Enable SSO | |
gh auth login | |
mkdir /home/ec2-user/SageMaker/.ssh # Persisted folder for our new SSH key | |
mv .ssh/id_ed25519* SageMaker/.ssh/ | |
gh ssh-key add /home/ec2-user/SageMaker/.ssh/id_ed25519.pub | |
# Enable SSO for the newly created SSH key: https://github.com/settings/keys | |
# Make the persisted key accessible to SSH | |
cat << EOF >> /home/ec2-user/.ssh/config | |
Host github.com | |
IdentityFile /home/ec2-user/SageMaker/.ssh/id_ed25519 | |
EOF | |
chmod 644 .ssh/config | |
# 3: clone repo and install package | |
cd /home/ec2-user/SageMaker/ # This folder is persisted by AWS | |
git clone [email protected]:hired/my-repo.git | |
cd my-repo | |
# Pip version | |
pip install -r requirements.txt | |
# Poetry version | |
# pip install poetry && poetry install | |
pre-commit install && pip install -e . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment