Skip to content

Commit

Permalink
Merge branch 'master' into heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-dietrich committed Nov 2, 2024
2 parents adc8734 + 35d42ca commit 2c81341
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 14 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/heroku-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Deploy to Heroku

on:
push:
branches:
- heroku

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Login to Heroku Container Registry
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
run: heroku container:login

- name: Build and push Docker image
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
run: |
docker build -t registry.heroku.com/$HEROKU_APP_NAME/web .
docker push registry.heroku.com/$HEROKU_APP_NAME/web
- name: Release to Heroku
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
run: heroku container:release web -a $HEROKU_APP_NAME
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ RUN DEBIAN_FRONTEND=noninteractive pip3 install \
pyarrow \
pandas \
scipy \
sympy \
pyyaml

RUN DEBIAN_FRONTEND=noninteractive apt-get install -y libcairo2-dev libpango1.0-dev
RUN DEBIAN_FRONTEND=noninteractive pip3 install \
pycairo \
manim

### Perl
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y perl

Expand Down
48 changes: 36 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ language: en
narrator: US English Female
onload
@onload
window.CodeRunner = {
ws: undefined,
handler: {},
connected: false,
error: "",
url: "",
firstConnection: true,
init(url, step = 0) {
this.url = url
Expand Down Expand Up @@ -98,22 +99,29 @@ window.CodeRunner = {
}, 2000)
} else {
sender.lia("LIA: wait")
//sender.lia("LIA: wait")
setTimeout(() => {
sender.lia(this.error)
sender.lia(" " + this.error)
sender.lia(" Maybe reloading fixes the problem ...")
sender.lia("LIA: stop")
}, 800)
}
} else {
setTimeout(function() {
self.send(uid, message, sender, false)
}, 2000)
if (sender) {
sender.lia("LIA: terminal")
//sender.log("waking up CodeRunner")
sender.log("stream", "", ".")
if (this.firstConnection) {
this.firstConnection = false
setTimeout(() => {
sender.log("stream", "", [" Waking up execution server ...\n", "This may take up to 30 seconds ...\n", "Please be patient ...\n"])
}, 100)
} else {
sender.log("stream", "", ".")
}
sender.lia("LIA: terminal")
}
}
Expand Down Expand Up @@ -299,6 +307,13 @@ CodeRunner.handle(uid, function (msg) {
}
}
if (msg.videos) {
for(let i = 0; i < msg.videos.length; i++) {
console.html("<hr/>", msg.videos[i].file)
console.html("<video title='" + msg.videos[i].file + "' src='" + msg.videos[i].data + "'></video>")
}
}
if (msg.files) {
let str = "<hr/>"
for(let i = 0; i < msg.files.length; i++) {
Expand Down Expand Up @@ -1179,6 +1194,7 @@ window.CodeRunner = {
connected: false,
error: "",
url: "",
firstConnection: true,
init(url, step = 0) {
this.url = url
Expand Down Expand Up @@ -1261,30 +1277,38 @@ window.CodeRunner = {
}, 2000)
} else {
sender.lia("LIA: wait")
//sender.lia("LIA: wait")
setTimeout(() => {
sender.lia(this.error)
sender.lia(" " + this.error)
sender.lia(" Maybe reloading fixes the problem ...")
sender.lia("LIA: stop")
}, 800)
}
} else {
setTimeout(function() {
self.send(uid, message, sender, false)
}, 2000)
if (sender) {
sender.lia("LIA: terminal")
sender.log("stream", "", ".")
if (this.firstConnection) {
this.firstConnection = false
setTimeout(() => {
sender.log("stream", "", [" Waking up execution server ...\n", "This may take up to 30 seconds ...\n", "Please be patient ...\n"])
}, 100)
} else {
sender.log("stream", "", ".")
}
sender.lia("LIA: terminal")
}
}
}
}
//window.CodeRunner.init("wss://coderunner.informatik.tu-freiberg.de/")
window.CodeRunner.init("ws://127.0.0.1:8000/")
//((window.CodeRunner.init("wss://ancient-hollows-41316.herokuapp.com/")
//window.CodeRunner.init("ws://127.0.0.1:8000/")
window.CodeRunner.init("wss://ancient-hollows-41316.herokuapp.com/")
@end
Expand Down
29 changes: 27 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def spawn(self) -> None:

self.process.close()

self.stop(None, self.list_images(), self.filter_files())
self.stop(None, self.list_images(), self.list_videos(), self.filter_files())

def filter_files(self):
'''
Expand Down Expand Up @@ -226,6 +226,28 @@ def list_images(self):

return images

def list_videos(self):
'''
Search the current directory for all video files and return them as base64.
'''

files = os.listdir(self.current_directory)
files = list(map(lambda filename: self.current_directory + "/" + filename, files))
files = sorted(filter(os.path.isfile, files), key=os.path.getmtime, reverse=True)

videos = []
for filename in files:
extension = pathlib.Path(filename).suffix.lower()[1:]

if extension in ["mp4", "avi", "mov", "mkv", "flv", "wmv", "webm"]:
with open(filename, "rb") as video_file:
videos.append({
"file": pathlib.Path(filename).name,
"data": "data:video/" + extension + ";base64," + base64.b64encode(video_file.read()).decode("utf8")
})

return videos

def read_line(self) -> bool:
'''
Read in a bunch of max 2000 characters from stdin and send them back to
Expand Down Expand Up @@ -461,7 +483,7 @@ def stdout(data):
"uid": message["uid"],
"data": escape_ansi(data)}))

def stop(error_message: str | None = None, images=[], files=[]):
def stop(error_message: str | None = None, images=[], videos=[], files=[]):
resp = {"ok": True, "service": "stop", "uid": message["uid"]}

if error_message:
Expand All @@ -470,6 +492,9 @@ def stop(error_message: str | None = None, images=[], files=[]):
if len(images) > 0:
resp["images"] = images

if len(videos) > 0:
resp["videos"] = videos

if len(files) > 0:
resp["files"] = files

Expand Down

0 comments on commit 2c81341

Please sign in to comment.