diff --git a/.github/workflows/docker-hub-backend.yml b/.github/workflows/docker-hub-backend.yml deleted file mode 100644 index 74b72a6..0000000 --- a/.github/workflows/docker-hub-backend.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Docker Image for Backend - -on: - push: - tags: - - '**' -jobs: - docker: - runs-on: ubuntu-latest - steps: - - 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 - 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 }} diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 40712d2..e451dbd 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -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: diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d81d574 --- /dev/null +++ b/.vscode/launch.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index da8ff08..e4fa986 100644 --- a/README.md +++ b/README.md @@ -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! @@ -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: diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000..93a464b --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1 @@ +static/ \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile index b7fab52..3d08239 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -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 ))"] diff --git a/backend/latexdiff_web.py b/backend/latexdiff_web.py index d7d8f1c..b96c866 100644 --- a/backend/latexdiff_web.py +++ b/backend/latexdiff_web.py @@ -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 @@ -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('/') +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():