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

Automagically commit unsaved work #3

Open
ericdill opened this issue Jun 12, 2019 · 1 comment
Open

Automagically commit unsaved work #3

ericdill opened this issue Jun 12, 2019 · 1 comment

Comments

@ericdill
Copy link

ericdill commented Jun 12, 2019

I poked around a bit and made some progress on automatically committing unsaved work in editor sessions. My approach is to run a script on the AE master (outside.sh) (or anywhere that you have kubectl access). That script copies a second script (commit.sh) into the running session and then executes it.
I'm currently hitting an issue where I'm getting a 403 from the git server inside the pod. If / when I figure that out I'll update this issue. Thanks @A-Aron-T

The usage here is:
$ bash outside.sh <pod name>

outside.sh:

#!/bin/bash

COMMIT_SCRIPT="./commit.sh"

PATH_IN_POD="/tmp/${COMMIT_SCRIPT}"

SESSION_POD=$1
echo "Session pod name is ${SESSION_POD}"
# get the name of the sidecar container
#SIDECAR_CONTAINER=$(kubectl describe po ${SESSION_POD} | grep tool-anaconda-platform-sync | sed 's/[ :]//g')

#echo "Sidecar container is ${SIDECAR_CONTAINER}"

kubectl cp ${COMMIT_SCRIPT} ${SESSION_POD}:${PATH_IN_POD}
#kubectl cp ${COMMIT_SCRIPT} ${SESSION_POD}:${PATH_IN_POD} -c ${SIDECAR_CONTAINER}


#kubectl exec ${SESSION_POD} -c ${SIDECAR_CONTAINER} -- ${PATH_IN_POD}
echo Executing bash script
kubectl exec ${SESSION_POD} -- sudo -u anaconda ${PATH_IN_POD}```

commit.sh:
```bash
#!/bin/bash
echo Switching to anaconda user
echo whoami: $(whoami)

echo activating lab_launch

source /opt/continuum/anaconda/bin/activate lab_launch

echo cd to project directory
pushd /opt/continuum/project
git add .
git commit -am "Automatic commit from command line

Date: $(date)
Reason: Reason why your code was auto committed"

cur_branch=$(git rev-parse --abbrev-ref HEAD)
git push origin ${cur_branch}

popd

Things that should be considered:

Q: What if there's a huge file?
A: Consider figuring out which files are big and commit them with git-lfs. You could achieve this with something like a find command to find the large files and then add them to be committed.

Q: What about the jupyter checkpoints from unsaved notebooks?
A: I don't think there's anyway way to force the browser to save an unsaved notebook. Though I'm hopeful to be wrong here.

@ericdill
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant