Skip to content

Commit

Permalink
CHG remove user defined repo path
Browse files Browse the repository at this point in the history
  • Loading branch information
wabscale committed Sep 15, 2022
1 parent 1eb75a8 commit 52113e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions api/anubis/k8s/theia.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def create_theia_k8s_pod_pvc(
name="NETID",
value=netid,
),
k8s.V1EnvVar(name="GIT_REPO", value=repo_url),
*sidecar_extra_env,
],
# Add a security context to disable privilege escalation
Expand Down
22 changes: 12 additions & 10 deletions theia/sidecar/app.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#!/usr/bin/python3

import os
import json
import string
import subprocess
import traceback

from flask import Flask, Response, request, make_response

app = Flask(__name__)
NETID = os.environ.get('NETID', default=None)
ADMIN = os.environ.get('ANUBIS_ADMIN', default=None) == 'ON'
GIT_REPO = os.environ.get('GIT_REPO', default='')
GIT_REPO_PATH = '/home/anubis/' + GIT_REPO.split('/')[-1]
print(f'GIT_REPO = {GIT_REPO}')
print(f'GIT_REPO_PATH = {GIT_REPO_PATH}')

app = Flask(__name__)


def text_response(message: str, status_code: int = 200) -> Response:
Expand All @@ -30,7 +34,6 @@ def relatively_safe_filename(filename: str) -> str:
@app.route('/', methods=['POST'])
def index():
# Get options from the form
repo: str = request.form.get('repo', default=None)
message: str = request.form.get('message', default='Anubis Cloud IDE Autosave').strip()
push_only: bool = request.form.get('push_only', default='false').lower() == 'true'
force_push: bool = request.form.get('force_push', default='false').lower() == 'true'
Expand All @@ -44,7 +47,7 @@ def index():
message += ' netid=' + NETID

# Make sure that the repo given exists and is a git repo
if repo is None or not os.path.isdir(os.path.join(repo, '.git')):
if GIT_REPO_PATH is None or not os.path.isdir(os.path.join(GIT_REPO_PATH, '.git')):
return text_response('Please navigate to the repository that you would like to autosave')

output: str = ""
Expand All @@ -56,7 +59,7 @@ def index():
# Add
add = subprocess.run(
['git', '-c', 'core.hooksPath=/dev/null', '-c', 'alias.push=push', 'add', '.'],
cwd=repo,
cwd=GIT_REPO_PATH,
timeout=3,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
Expand All @@ -67,8 +70,9 @@ def index():

# Commit
commit = subprocess.run(
['git', '-c', 'core.hooksPath=/dev/null', '-c', 'alias.commit=commit', 'commit', '--no-verify', '-m', message],
cwd=repo,
['git', '-c', 'core.hooksPath=/dev/null', '-c', 'alias.commit=commit', 'commit', '--no-verify', '-m',
message],
cwd=GIT_REPO_PATH,
timeout=3,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
Expand All @@ -83,7 +87,7 @@ def index():
push_args.append('--force')
push = subprocess.run(
push_args,
cwd=repo,
cwd=GIT_REPO_PATH,
timeout=3,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
Expand Down Expand Up @@ -147,5 +151,3 @@ def clone():
return text_response(
'Succeeded:\n' + '\n'.join(succeeded) + '\nFailed:\n' + '\n'.join(failed)
)


5 changes: 3 additions & 2 deletions theia/sidecar/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ stdout_logfile=/tmp/autosave.log

[program:autosave-server]
directory=/
command=gunicorn -b 0.0.0.0:5001 -w 1 app:app
command=gunicorn -b 0.0.0.0:5001 -w 1 --capture-output --enable-stdio-inheritance app:app
autorestart=true
environment=HOME="/home/theia"
redirect_stderr=true
stdout_logfile=/tmp/server.log
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0

0 comments on commit 52113e3

Please sign in to comment.