Skip to content

Commit 403e322

Browse files
authored
V2.2.5 add manual theia autosave (#77)
* ADD manual theia autosave * FIX autosave script issues
1 parent 1fc8ffc commit 403e322

File tree

11 files changed

+150
-13
lines changed

11 files changed

+150
-13
lines changed

api/anubis/rpc/pipeline.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ def create_pipeline_job_obj(client, submission):
1717
:param submission:
1818
:return:
1919
"""
20+
21+
requirements = {
22+
'limits': {"cpu": "2", "memory": "750Mi"},
23+
'requests': {"cpu": "500m", "memory": "100Mi"},
24+
}
25+
26+
if is_debug():
27+
requirements = {}
28+
2029
container = client.V1Container(
2130
name="pipeline",
2231
image=submission.assignment.pipeline_image,
@@ -35,10 +44,7 @@ def create_pipeline_job_obj(client, submission):
3544
),
3645
),
3746
],
38-
resources=client.V1ResourceRequirements(
39-
limits={"cpu": "2", "memory": "750Mi"},
40-
requests={"cpu": "500m", "memory": "100Mi"},
41-
),
47+
resources=client.V1ResourceRequirements(**requirements),
4248
)
4349
# Create and configure a spec section
4450
template = client.V1PodTemplateSpec(

api/anubis/rpc/theia.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,22 @@ def create_theia_pod_obj(theia_session: TheiaSession):
7272
if "requests" in theia_session.options:
7373
requests = theia_session.options["requests"]
7474

75+
autosave = True
76+
if 'autosave' in theia_session.options:
77+
autosave = theia_session.options['autosave']
78+
7579
# Theia container
7680
theia_container = client.V1Container(
7781
name="theia",
7882
image=theia_session.image,
7983
image_pull_policy=os.environ.get("IMAGE_PULL_POLICY", default="Always"),
8084
ports=[client.V1ContainerPort(container_port=5000)],
85+
env=[
86+
client.V1EnvVar(
87+
name='AUTOSAVE',
88+
value='ON' if autosave else 'OFF',
89+
),
90+
],
8191
resources=client.V1ResourceRequirements(
8292
limits=limits,
8393
requests=requests,
@@ -94,10 +104,6 @@ def create_theia_pod_obj(theia_session: TheiaSession):
94104
)
95105
containers.append(theia_container)
96106

97-
autosave = True
98-
if 'autosave' in theia_session.options:
99-
autosave = theia_session.options['autosave']
100-
101107
# Sidecar container
102108
if autosave:
103109
sidecar_container = client.V1Container(

theia/ide/xv6/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,7 @@ RUN chmod g+rw /home && \
155155
COPY --from=theia /home/theia /home/theia
156156
WORKDIR /home/theia
157157
COPY supervisord.conf /supervisord.conf
158+
COPY autosave /usr/local/bin/autosave
159+
COPY autosave-dump.sh /autosave-dump.sh
158160

159161
ENTRYPOINT ["supervisord", "--nodaemon", "-c", "/supervisord.conf"]

theia/ide/xv6/autosave

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
if [ "$(cat /AUTOSAVE)" = "OFF" ]; then
4+
echo 'Autosave was disabled for this session.'
5+
exit 1
6+
fi
7+
8+
if git status | grep 'nothing to commit' &> /dev/null; then
9+
echo 'Nothing to autosave just yet. Make a change you would like to save!'
10+
exit 1
11+
fi
12+
13+
exec curl http://localhost:5001/ \
14+
--data "message=${@}"

theia/ide/xv6/autosave-dump.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
echo ${AUTOSAVE} > /AUTOSAVE

theia/ide/xv6/supervisord.conf

+7
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ command=env -i HOME=/home/theia THEIA_DEFAULT_PLUGINS=local-dir:/home/theia/plug
77
user=theia
88
stdout_logfile=/dev/fd/1
99
stdout_logfile_maxbytes=0
10+
11+
[program:autosave-dump]
12+
directory=/
13+
command=/autosave-dump.sh
14+
autorestart=false
15+
stdout_logfile=/dev/fd/1
16+
stdout_logfile_maxbytes=0

theia/sidecar/Dockerfile

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
FROM alpine:latest
1+
FROM python:3-alpine
22

33
RUN adduser -D -u 1001 theia \
4-
&& apk add --update --no-cache dcron git busybox-suid
4+
&& apk add --update --no-cache dcron git busybox-suid \
5+
&& pip3 install --no-cache-dir flask supervisor gunicorn
6+
7+
USER theia
8+
RUN git config --global user.email [email protected] \
9+
&& git config --global user.name os3224-robot \
10+
&& git config --global credential.store helper \
11+
&& git config --global credential.helper 'store --file ~/.git-credentials'
12+
USER root
513

614
VOLUME /home/project
715

8-
COPY entrypoint.sh /entrypoint.sh
16+
COPY supervisord.conf /supervisord.conf
17+
COPY autosave-loop.sh /autosave-loop.sh
918
COPY autosave.sh /autosave.sh
19+
COPY app.py /app.py
1020

11-
USER theia
12-
ENTRYPOINT /entrypoint.sh
21+
ENTRYPOINT ["supervisord", "--nodaemon", "-c", "/supervisord.conf"]
1322

1423

theia/sidecar/app.py

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/python3
2+
3+
from flask import Flask, request, make_response
4+
import subprocess
5+
6+
app = Flask(__name__)
7+
8+
@app.route('/', methods=['POST'])
9+
def index():
10+
message = request.form.get('message', default='Anubis Cloud IDE Autosave')
11+
if message.strip() == '':
12+
message = 'Anubis Cloud IDE Autosave'
13+
14+
try:
15+
# Add
16+
add = subprocess.run(
17+
['git', 'add', '.'],
18+
cwd='/home/project',
19+
timeout=3,
20+
stdout=subprocess.PIPE,
21+
stderr=subprocess.STDOUT,
22+
)
23+
if add.returncode != 0:
24+
response = make_response(
25+
'Failed to git add\n',
26+
)
27+
response.headers = {'Content-Type': 'text/plain'}
28+
return response
29+
30+
# Commit
31+
commit = subprocess.run(
32+
['git', 'commit', '-m', message],
33+
cwd='/home/project',
34+
timeout=3,
35+
stdout=subprocess.PIPE,
36+
stderr=subprocess.STDOUT,
37+
)
38+
if commit.returncode != 0:
39+
response = make_response(
40+
'Failed to git commit\n',
41+
)
42+
response.headers = {'Content-Type': 'text/plain'}
43+
return response
44+
45+
# Push
46+
push = subprocess.run(
47+
['git', 'push'],
48+
cwd='/home/project',
49+
timeout=3,
50+
stdout=subprocess.PIPE,
51+
stderr=subprocess.STDOUT,
52+
)
53+
if push.returncode != 0:
54+
response = make_response(
55+
'Failed to git push\n',
56+
)
57+
response.headers = {'Content-Type': 'text/plain'}
58+
return response
59+
60+
except subprocess.TimeoutExpired:
61+
response = make_response(
62+
'Autosave timeout\n',
63+
)
64+
response.headers = {'Content-Type': 'text/plain'}
65+
return response
66+
67+
output = (add.stdout + commit.stdout + push.stdout + b'\n').decode()
68+
response = make_response(output)
69+
response.headers = {'Content-Type': 'text/plain'}
70+
return response
File renamed without changes.

theia/sidecar/supervisord.conf

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[supervisord]
2+
logfile=/supervisord.log
3+
4+
[program:autosave-loop]
5+
directory=/
6+
command=/autosave-loop.sh
7+
autorestart=true
8+
user=theia
9+
stdout_logfile=/dev/fd/1
10+
stdout_logfile_maxbytes=0
11+
12+
[program:autosave-server]
13+
directory=/
14+
command=gunicorn -b 0.0.0.0:5001 -w 1 app:app
15+
autorestart=true
16+
environment=HOME="/home/theia"
17+
user=theia
18+
stdout_logfile=/dev/fd/1
19+
stdout_logfile_maxbytes=0

web/src/Components/Public/IDE/IDEDialog.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ export default function IDEDialog({selectedTheia, setSelectedTheia}) {
180180
<IDEInstructions/>
181181
</Grid>
182182
<FormControlLabel
183+
disabled={!!session}
183184
checked={autosaveEnabled}
184185
onChange={() => setAutosaveEnabled(!autosaveEnabled)}
185186
control={<Switch color={'primary'}/>}

0 commit comments

Comments
 (0)