Skip to content

Commit

Permalink
Docker image with shell-escape
Browse files Browse the repository at this point in the history
  • Loading branch information
rigon authored Nov 2, 2024
1 parent 005a59d commit 3d1d5be
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 49 deletions.
100 changes: 76 additions & 24 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,46 @@ on:
- "master"

jobs:
build:
name: Push Docker image to Docker Hub
# # NOTE: Not required for now
# prepare:
# name: Prepare environment
# runs-on: ubuntu-latest
# steps:
# - name: Free Disk Space (Ubuntu)
# uses: insightsengineering/disk-space-reclaimer@v1
# with:
# # this might remove tools that are actually needed,
# # if set to "true" but frees about 6 GB
# tools-cache: true

# # all of these default to true, but feel free to set to
# # "false" if necessary for your workflow
# android: true
# dotnet: true
# haskell: true
# large-packages: true
# swap-storage: true
# docker-images: true

base:
name: Base image
runs-on: ubuntu-latest
# needs: prepare
steps:
- name: Free Disk Space (Ubuntu)
uses: insightsengineering/disk-space-reclaimer@v1
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tools-cache: true

# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
swap-storage: true
docker-images: true
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: rigon/sharelatex-full
# generate Docker tags based on the following events/attributes
Expand All @@ -44,22 +60,58 @@ jobs:
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Print tags
run: printf "== TAGS ==\n${{ steps.meta.outputs.tags }}"
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
target: base
push: true
platforms: linux/amd64 #,linux/arm64,linux/arm/v6
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

shell-escape:
name: Shell-escape image
runs-on: ubuntu-latest
needs: base
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: rigon/sharelatex-full
flavor: |
latest=auto
suffix=-shell-escape,onlatest=true
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Print tags
run: printf "== TAGS ==\n${{ steps.meta.outputs.tags }}"
- name: Build and push Docker image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: .
target: shell-escape
push: true
platforms: linux/amd64 #,linux/arm64,linux/arm/v6
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Monitor Docker Hub for New Tags
name: Monitor Docker Hub for new tags

on:
push:
Expand All @@ -10,7 +10,7 @@ on:

jobs:
monitor:
name: Check for new versions on Docker Hub
name: Check for new versions of Sharelatex
runs-on: ubuntu-latest
steps:
- name: Fetch latest tag from Docker Hub
Expand Down
24 changes: 22 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM sharelatex/sharelatex
FROM sharelatex/sharelatex AS base

# # Install TeX Live: metapackage pulling in all components of TeX Live
# RUN set -x && \
Expand Down Expand Up @@ -33,5 +33,25 @@ RUN set -x && \

# Code Highlighting with minted
# https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted
RUN pip install latexminted

####################
# Stage shell-escape
####################
FROM base AS shell-escape

# Tools mentioned by the community:
# https://tex.stackexchange.com/questions/598818/how-can-i-enable-shell-escape

# Enable shell-escape
RUN printf "\n%% Enable shell-escape\nshell_escape = t\n" | \
/bin/bash -c "tee -a /usr/local/texlive/*/texmf.cnf"

# Install additional tools used by TeX packages
RUN set -x && \
pip install latexminted
apt-get update && \
apt-get install -y --no-install-recommends graphviz gnuplot inkscape asymptote && \
# Cleanup
apt-get clean && rm -rf /var/lib/apt

RUN pip install dot2tex
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@ ShareLatex with all Latex packages installed by default.

This is an extension of the [official sharelatex](https://hub.docker.com/r/sharelatex/sharelatex/).

The goal is to create an image with many Latex packages as possible, so you do not have (hopefully) to worry about missing packages. The downside is the large size of the image.

The [tlmgr](https://www.tug.org/texlive/tlmgr.html) [full scheme](https://tex.stackexchange.com/questions/234749/downloading-every-package-with-tex-live) is installed on top of Sharelatex, plus additional external tools required by common LaTeX packges:

- [`latexminted`](https://pypi.org/project/latexminted/) for [Code Highlighting with minted](https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted)

The goal is to create an image with many Latex packages as possible, so you do not have (hopefully) to worry about missing packages. The downside is the large size of the image.
And with shell-escape enabled:

- [Inkscape](https://inkscape.org/) to support [SVG images](https://en.wikipedia.org/wiki/SVG)
- [Graphviz](https://graphviz.org/) using [`dot2tex`](https://pypi.org/project/dot2tex/) package
- [Asymptote](https://asymptote.sourceforge.io/) using `asypictureB` package
- [gnuplot](http://www.gnuplot.info/) using `gnuplottex` package

> [!WARNING]
> Be aware that using `-shell-escape` or `-enable-write18` allows LATEX to run potentially arbitrary commands on your system. These should only be used when necessary, with documents from trusted sources. If you understand the implications use the docker image `rigon/sharelatex:latest-shell-escape` instead.
## How to run

Expand Down
41 changes: 21 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
restart: always
# Server Pro users:
# image: quay.io/sharelatex/sharelatex-pro
image: rigon/sharelatex-full
image: rigon/sharelatex-full # :latest-shell-escape
container_name: sharelatex
depends_on:
mongo:
Expand Down Expand Up @@ -53,33 +53,34 @@ services:
## Set for SSL via nginx-proxy
#VIRTUAL_HOST: 103.112.212.22

# SHARELATEX_SITE_URL: http://sharelatex.mydomain.com
# SHARELATEX_NAV_TITLE: Our ShareLaTeX Instance
# SHARELATEX_HEADER_IMAGE_URL: http://somewhere.com/mylogo.png
# SHARELATEX_ADMIN_EMAIL: [email protected]
# OVERLEAF_SITE_URL: http://sharelatex.mydomain.com
# OVERLEAF_NAV_TITLE: Our ShareLaTeX Instance
# OVERLEAF_HEADER_IMAGE_URL: http://somewhere.com/mylogo.png
# OVERLEAF_ADMIN_EMAIL: [email protected]

# SHARELATEX_LEFT_FOOTER: '[{"text": "Powered by <a href=\"https://www.sharelatex.com\">ShareLaTeX</a> 2016"},{"text": "Another page I want to link to can be found <a href=\"here\">here</a>"} ]'
# SHARELATEX_RIGHT_FOOTER: '[{"text": "Hello I am on the Right"} ]'
# OVERLEAF_LEFT_FOOTER: '[{"text": "Powered by <a href=\"https://www.sharelatex.com\">ShareLaTeX</a> 2016"},{"text": "Another page I want to link to can be found <a href=\"here\">here</a>"} ]'
# OVERLEAF_RIGHT_FOOTER: '[{"text": "Hello I am on the Right"} ]'

# SHARELATEX_EMAIL_FROM_ADDRESS: "[email protected]"
# OVERLEAF_EMAIL_FROM_ADDRESS: "[email protected]"

# SHARELATEX_EMAIL_AWS_SES_ACCESS_KEY_ID:
# SHARELATEX_EMAIL_AWS_SES_SECRET_KEY:
# OVERLEAF_EMAIL_AWS_SES_ACCESS_KEY_ID:
# OVERLEAF_EMAIL_AWS_SES_SECRET_KEY:

# SHARELATEX_EMAIL_SMTP_HOST: smtp.mydomain.com
# SHARELATEX_EMAIL_SMTP_PORT: 587
# SHARELATEX_EMAIL_SMTP_SECURE: false
# SHARELATEX_EMAIL_SMTP_USER:
# SHARELATEX_EMAIL_SMTP_PASS:
# SHARELATEX_EMAIL_SMTP_TLS_REJECT_UNAUTH: true
# SHARELATEX_EMAIL_SMTP_IGNORE_TLS: false
# SHARELATEX_EMAIL_SMTP_NAME: '127.0.0.1'
# SHARELATEX_EMAIL_SMTP_LOGGER: true
# SHARELATEX_CUSTOM_EMAIL_FOOTER: "This system is run by department x"
# OVERLEAF_EMAIL_SMTP_HOST: smtp.mydomain.com
# OVERLEAF_EMAIL_SMTP_PORT: 587
# OVERLEAF_EMAIL_SMTP_SECURE: false
# OVERLEAF_EMAIL_SMTP_USER:
# OVERLEAF_EMAIL_SMTP_PASS:
# OVERLEAF_EMAIL_SMTP_TLS_REJECT_UNAUTH: true
# OVERLEAF_EMAIL_SMTP_IGNORE_TLS: false
# OVERLEAF_EMAIL_SMTP_NAME: '127.0.0.1'
# OVERLEAF_EMAIL_SMTP_LOGGER: true
# OVERLEAF_CUSTOM_EMAIL_FOOTER: "This system is run by department x"

################
## Server Pro ##
################
## https://github.com/overleaf/overleaf/wiki/Server-Pro:-sandboxed-compiles

# SANDBOXED_COMPILES: 'true'

Expand Down
87 changes: 87 additions & 0 deletions tests/asypictureB.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
\documentclass{article}
\usepackage{asypictureB} % Include asypictureB package

\begin{document}

\title{LaTeX Document with Asymptote Graphic}
\author{Your Name}
\date{\today}
\maketitle

\section{Introduction}

This is an example of including an Asymptote graphic within a LaTeX document using the \texttt{asypictureB} package. Asymptote allows for powerful vector graphic rendering, making it a great tool for illustrations and figures in technical documents.

\begin{asypicture}{width=5cm}
// Global Asymptote definitions can be put here.
settings.prc=true;
import three;
usepackage("bm");
texpreamble("\def\V#1{\bm{#1}}");
// One can globally override the default toolbar settings here:
// settings.toolbar=true;

size(4cm,0);
pen colour1=red;
pen colour2=green;

pair z0=(0,0);
pair z1=(-1,0);
pair z2=(1,0);
real r=1.5;
path c1=circle(z1,r);
path c2=circle(z2,r);
fill(c1,colour1);
fill(c2,colour2);

picture intersection=new picture;
fill(intersection,c1,colour1+colour2);
clip(intersection,c2);

add(intersection);

draw(c1);
draw(c2);

//draw("$\A$",box,z1); // Requires [inline] package option.
//draw(Label("$\B$","$B$"),box,z2); // Requires [inline] package option.
draw("$A$",box,z1);
draw("$\V{B}$",box,z2);

pair z=(0,-2);
real m=3;
margin BigMargin=Margin(0,m*dot(unit(z1-z),unit(z0-z)));

draw(Label("$A\cap B$",0),conj(z)--z0,Arrow,BigMargin);
draw(Label("$A\cup B$",0),z--z0,Arrow,BigMargin);
draw(z--z1,Arrow,Margin(0,m));
draw(z--z2,Arrow,Margin(0,m));

shipout(bbox(0.25cm));
\end{asypicture}

\section{Asymptote Graphic Example}

Below is an Asymptote graphic generated within the document:

\begin{asypicture}{width=5cm}
// Begin Asymptote code
import graph;

size(5cm);
draw((0,0)--(2,2), blue+linewidth(1));
draw((0,2)--(2,0), red+linewidth(1));

label("$A$", (0,0), SW);
label("$B$", (2,2), NE);
label("$C$", (0,2), NW);
label("$D$", (2,0), SE);

draw((0,0)..(1,1.5)..(2,2), green+linewidth(0.8));
\end{asypicture}

\section{Conclusion}

This document shows how to use the \texttt{asypictureB} package to include Asymptote graphics within a LaTeX document. This technique can be useful for including high-quality, scalable graphics in your document, particularly for complex diagrams and plots.

\end{document}
Loading

0 comments on commit 3d1d5be

Please sign in to comment.