Skip to content

Commit

Permalink
build the container with frontend pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
am009 committed May 11, 2024
1 parent 6a507c4 commit 5fa0fa2
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 42 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/docker-hub-backend.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,36 @@ jobs:
uses: actions/upload-pages-artifact@v3
with:
path: ./out
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: 'backend'
sparse-checkout-cone-mode: false
# All files should be moved to the project root.
- name: Move app files to root
run: |
ls -lah
shopt -s dotglob
mv backend/* .
rm -rf backend
mv ./out ./static
ls -lah
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: am009
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: am009/latexdiff-web-backend:latest,am009/latexdiff-web-backend:${{ github.ref_name }}

# Deployment job
deploy:
Expand Down
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: latexdiff_web",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/backend/latexdiff_web.py",
"console": "integratedTerminal",
"justMyCode": false,
"cwd": "${workspaceFolder}/backend"
}
]
}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Keywords: latexdiff latex diff web online pdfdiff
An web interface for [git-latexdiff](https://gitlab.com/git-latexdiff/git-latexdiff) (which is eventually based on [latexdiff](https://github.com/ftilmann/latexdiff)).

- Easy to Use: The input is two overleaf project zip file.
- Run your own backend: You can run and use your own backend, no file is sent to any remote server.
- Ready for paper submission: TODO

## Use it online!
Expand All @@ -14,6 +15,13 @@ An web interface for [git-latexdiff](https://gitlab.com/git-latexdiff/git-latexd

(P.S. I'm excited to provide my first public service to the whole internet. Any issue related to the public API endpoint is also welcomed.)

## Run the web backend

```
docker pull am009/latexdiff-web-worker && \
docker run -p 8000:8000 -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp --name latexdiff-backend -d am009/latexdiff-web-backend
```

## Use as a command line tool

Create a folder with the following three files:
Expand Down
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
static/
1 change: 1 addition & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ RUN if [[ ! -z "$UBUNTU_MIRROR" ]] ; then sed -i "s/archive.ubuntu.com/$UBUNTU_M

# Copy the backend api
COPY latexdiff_web.py wsgi.py /root/
COPY static /root/static/

ENTRYPOINT ["/bin/bash", "-c"]
CMD ["/usr/bin/python3 -m gunicorn wsgi:app -b 0.0.0.0:8000 --timeout 3600 --workers $(( $(nproc) * 2 ))"]
14 changes: 11 additions & 3 deletions backend/latexdiff_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
DEBUG = (__name__ == '__main__')
TIMEOUT_LIMIT = 600.0

from flask import Flask, request, redirect, jsonify
from flask import Flask, request, redirect, jsonify, send_from_directory
from flask_cors import CORS, cross_origin
from werkzeug.utils import secure_filename
from werkzeug.datastructures import FileStorage
Expand All @@ -23,8 +23,16 @@ def gen_redir():
return redirect(url)

@app.route('/')
def index():
return gen_redir()
def send_index():
if not os.path.exists('static'):
return gen_redir()
return send_from_directory('static', 'index.html')

@app.route('/<path:path>')
def send_web(path):
if not os.path.exists('static'):
return gen_redir()
return send_from_directory('static', path)

@app.route('/latexdiff', methods = ['GET', 'POST'])
def upload_file():
Expand Down

0 comments on commit 5fa0fa2

Please sign in to comment.