anaconda / ae5-tools

A command-line tool for scripting AE5 actions
https://www.anaconda.com/enterprise/
BSD 3-Clause "New" or "Revised" License
9 stars 8 forks source link

Automagically commit unsaved work #3

Open ericdill opened 5 years ago

ericdill commented 5 years ago

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 commented 5 years ago

As @AlbertDeFusco points out, there's a much better approach. Use the UI API to do this: https://github.com/Anaconda-Platform/anaconda-platform/blob/92a55292490e6e17f242f573b5a0e93e8b15e8c5/ui/anaconda_platform/ui/api_tests/api_sessions/test_api_v2.py#L279-L291