Skip to content

Commit

Permalink
Manage TinyTeX installation with Quarto (#814)
Browse files Browse the repository at this point in the history
* Manage TinyTeX installation with Quarto

Add CLI options to `install_quarto.sh` to install, update, add to path, or uninstall TinyTeX

Add an option to use Workbench's preinstalled Quarto for TinyTeX management

* Add TinyTeX test to Goss

Fix usage error

* Auto-detect Workbench installed Quarto and use if present

* Update product/base/scripts/ubuntu/install_quarto.sh

Co-authored-by: Benjamin R. J. Schwedler <[email protected]>

* Move Quarto and TinyTeX install to after workbench install in WGCW

---------

Co-authored-by: Benjamin R. J. Schwedler <[email protected]>
  • Loading branch information
ianpittwood and bschwedler authored Jul 22, 2024
1 parent 2a40e4f commit 6f7c47a
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 21 deletions.
2 changes: 1 addition & 1 deletion connect/Dockerfile.ubuntu2204
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ARG QUARTO_VERSION=1.4.557
ARG SCRIPTS_DIR=/opt/positscripts

### Install Quarto ###
RUN QUARTO_VERSION=${QUARTO_VERSION} ${SCRIPTS_DIR}/install_quarto.sh \
RUN QUARTO_VERSION=${QUARTO_VERSION} ${SCRIPTS_DIR}/install_quarto.sh --install-tinytex --add-path-tinytex \
&& ln -s /opt/quarto/${QUARTO_VERSION}/bin/quarto /usr/local/bin/quarto

SHELL [ "/bin/bash", "-o", "pipefail", "-c"]
Expand Down
7 changes: 7 additions & 0 deletions connect/test/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,10 @@ command:
"/usr/local/bin/quarto check --quiet":
title: quarto_check
exit-status: 0

# Ensure TinyTeX is installed
"quarto list tools":
title: quarto_tinytex_installed
exit-status: 0
stderr:
- "/tinytex\\s+Up to date\\s+v\\d{4}\\.\\d{2}\\.\\d{2}\\s+v\\d{4}\\.\\d{2}\\.\\d{2}/"
8 changes: 0 additions & 8 deletions product/base/Dockerfile.ubuntu2204
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ RUN gpg --batch --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 595E85A6B1
&& chmod +x /tini \
&& ln -s /tini /usr/local/bin/tini

### Install TinyTeX ###
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl -sL "https://yihui.org/tinytex/install-bin-unix.sh" | sh \
&& /root/.TinyTeX/bin/*/tlmgr path remove \
&& mv /root/.TinyTeX/ /opt/TinyTeX \
&& /opt/TinyTeX/bin/*/tlmgr option sys_bin /usr/local/bin \
&& /opt/TinyTeX/bin/*/tlmgr path add

### Install R versions ###
RUN R_VERSION=${R_VERSION} ${SCRIPTS_DIR}/install_r.sh \
&& R_VERSION=${R_VERSION_ALT} ${SCRIPTS_DIR}/install_r.sh \
Expand Down
79 changes: 70 additions & 9 deletions product/base/scripts/ubuntu/install_quarto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,34 @@ usage() {
echo " QUARTO_VERSION=1.3.340 $0"
echo ""
echo "Options:"
echo " -d, --debug Enable debug output"
echo " -h, --help Print usage and exit"
echo " --prefix Install Quarto to a custom prefix"
echo " Each version of Quarto will have its own subdirectory"
echo " Default: /opt/quarto"
echo " -d, --debug Enable debug output"
echo " -h, --help Print usage and exit"
echo " --prefix Install Quarto to a custom prefix"
echo " Each version of Quarto will have its own subdirectory"
echo " Default: /opt/quarto"
echo " --install-tinytex Install TinyTeX using Quarto"
echo " --add-path-tinytex Add TinyTeX to PATH using Quarto"
echo " --update-tinytex Update TinyTeX using Quarto"
echo " --uninstall-tinytex Uninstall TinyTeX from Quarto"
}


# Set defaults
PREFIX="/opt/quarto"
QUARTO_PATH="${PREFIX}/${QUARTO_VERSION}/bin/quarto"
ADD_PATH_TINYTEX=0
INSTALL_TINYTEX=0
UPDATE_TINYTEX=0
UNINSTALL_TINYTEX=0
IS_WORKBENCH_INSTALLATION=0

OPTIONS=$(getopt -o hdr: --long help,debug,prefix: -- "$@")
# Set Quarto Path to the bundled version in Workbench if it exists
if [ -f "/lib/rstudio-server/bin/quarto/bin/quarto" ]; then
QUARTO_PATH="/lib/rstudio-server/bin/quarto/bin/quarto"
IS_WORKBENCH_INSTALLATION=1
fi

OPTIONS=$(getopt -o hd --long help,debug,prefix:,install-tinytex,add-path-tinytex,update-tinytex,uninstall-tinytex -- "$@")
# shellcheck disable=SC2181
if [[ $? -ne 0 ]]; then
exit 1;
Expand All @@ -49,21 +65,37 @@ while true; do
PREFIX="$2"
shift 2
;;
--install-tinytex)
INSTALL_TINYTEX=1
shift
;;
--add-path-tinytex)
ADD_PATH_TINYTEX=1
shift
;;
--update-tinytex)
UPDATE_TINYTEX=1
shift
;;
--uninstall-tinytex)
UNINSTALL_TINYTEX=1
shift
;;
--) shift;
break
;;
esac
done

if [ -z "$QUARTO_VERSION" ]; then
if [ -z "$QUARTO_VERSION" ] && [[ "$IS_WORKBENCH_INSTALLATION" -eq 0 ]]; then
usage
exit 1
fi

install_quarto() {
# Check if Quarto is already installed
# shellcheck disable=SC2086
if ${PREFIX}/${QUARTO_VERSION}/bin/quarto --version | grep -qE "^${QUARTO_VERSION}" ; then
if $QUARTO_PATH --version | grep -qE "^${QUARTO_VERSION}" ; then
echo "$d Quarto $QUARTO_VERSION is already installed in $PREFIX/$QUARTO_VERSION $d"
return
fi
Expand All @@ -72,4 +104,33 @@ install_quarto() {
wget -q -O - "https://github.com/quarto-dev/quarto-cli/releases/download/v${QUARTO_VERSION}/quarto-${QUARTO_VERSION}-linux-amd64.tar.gz" | tar xzf - -C "/opt/quarto/${QUARTO_VERSION}" --strip-components=1
}

install_quarto
update_tinytex() {
$QUARTO_PATH update tinytex --no-prompt
}

uninstall_tinytex() {
$QUARTO_PATH uninstall tinytex --no-prompt
}

install_tinytex() {
uninstall_tinytex
if [[ "$ADD_PATH_TINYTEX" -eq 1 ]]; then
$QUARTO_PATH install tinytex --update-path --no-prompt
else
$QUARTO_PATH install tinytex --no-prompt
fi
}

if [[ "$IS_WORKBENCH_INSTALLATION" -eq 0 ]]; then
# Skip installation if Quarto is bundled with Workbench
install_quarto
fi
if [[ "$INSTALL_TINYTEX" -eq 1 ]]; then
install_tinytex
fi
if [[ "$UPDATE_TINYTEX" -eq 1 ]]; then
update_tinytex
fi
if [[ "$UNINSTALL_TINYTEX" -eq 1 ]]; then
uninstall_tinytex
fi
3 changes: 3 additions & 0 deletions r-session-complete/Dockerfile.ubuntu2204
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ RUN apt-get update \
### Install Quarto to PATH ###
RUN ln -s /lib/rstudio-server/bin/quarto/bin/quarto /usr/local/bin/quarto

### Install TinyTeX using Quarto ###
RUN $SCRIPTS_DIR/install_quarto.sh --install-tinytex --add-path-tinytex

COPY maybe_install_vs_code.sh /tmp/maybe_install_vs_code.sh
RUN /tmp/maybe_install_vs_code.sh \
&& rm /tmp/maybe_install_vs_code.sh
Expand Down
7 changes: 7 additions & 0 deletions r-session-complete/test/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,10 @@ command:
"/usr/local/bin/quarto check --quiet":
title: quarto_check
exit-status: 0

# Ensure TinyTeX is installed
"quarto list tools":
title: quarto_tinytex_installed
exit-status: 0
stderr:
- "/tinytex\\s+Up to date\\s+v\\d{4}\\.\\d{2}\\.\\d{2}\\s+v\\d{4}\\.\\d{2}\\.\\d{2}/"
9 changes: 6 additions & 3 deletions workbench-for-google-cloud-workstations/Dockerfile.ubuntu2204
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

### Install Quarto to PATH ###
RUN ln -s /lib/rstudio-server/bin/quarto/bin/quarto /usr/local/bin/quarto

### Install Pro Drivers ###
RUN ${SCRIPTS_DIR}/apt.sh --update upgrade \
&& ${SCRIPTS_DIR}/apt.sh install unixodbc unixodbc-dev \
Expand Down Expand Up @@ -99,6 +96,12 @@ RUN curl -o rstudio-workbench.deb "${RSW_DOWNLOAD_URL}/${RSW_NAME}-${RSW_VERSION
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/lib/rstudio-server/r-versions

### Install Quarto to PATH ###
RUN ln -s /lib/rstudio-server/bin/quarto/bin/quarto /usr/local/bin/quarto

### Install TinyTeX using Quarto ###
RUN $SCRIPTS_DIR/install_quarto.sh --install-tinytex --add-path-tinytex

# Workaround to ensure no pre-generated certificates are included in image distributions.
# This happens in the step immediately following Workbench installation in case the certificates are generated.
RUN rm -f /etc/rstudio/launcher.pem /etc/rstudio/launcher.pub
Expand Down
7 changes: 7 additions & 0 deletions workbench-for-google-cloud-workstations/test/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,10 @@ command:
"/usr/local/bin/quarto check --quiet":
title: quarto_check
exit-status: 0

# Ensure TinyTeX is installed
"quarto list tools":
title: quarto_tinytex_installed
exit-status: 0
stderr:
- "/tinytex\\s+Up to date\\s+v\\d{4}\\.\\d{2}\\.\\d{2}\\s+v\\d{4}\\.\\d{2}\\.\\d{2}/"
3 changes: 3 additions & 0 deletions workbench-for-microsoft-azure-ml/Dockerfile.ubuntu2204
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ RUN rm -f /etc/rstudio/launcher.pem /etc/rstudio/launcher.pub
### Install Quarto to PATH ###
RUN ln -s /lib/rstudio-server/bin/quarto/bin/quarto /usr/local/bin/quarto

### Install TinyTeX using Quarto ###
RUN $SCRIPTS_DIR/install_quarto.sh --install-tinytex --add-path-tinytex

COPY --chmod=0755 license-manager-shim /opt/rstudio-license/license-manager
COPY --chmod=0775 startup.sh /usr/local/bin/startup.sh
COPY startup/* /startup/base/
Expand Down
7 changes: 7 additions & 0 deletions workbench-for-microsoft-azure-ml/test/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,10 @@ command:
"/usr/local/bin/quarto check --quiet":
title: quarto_check
exit-status: 0

# Ensure TinyTeX is installed
"quarto list tools":
title: quarto_tinytex_installed
exit-status: 0
stderr:
- "/tinytex\\s+Up to date\\s+v\\d{4}\\.\\d{2}\\.\\d{2}\\s+v\\d{4}\\.\\d{2}\\.\\d{2}/"
3 changes: 3 additions & 0 deletions workbench/Dockerfile.ubuntu2204
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ RUN rm -f /etc/rstudio/launcher.pem /etc/rstudio/launcher.pub
### Install Quarto to PATH ###
RUN ln -s /lib/rstudio-server/bin/quarto/bin/quarto /usr/local/bin/quarto

### Install TinyTeX using Quarto ###
RUN $SCRIPTS_DIR/install_quarto.sh --install-tinytex --add-path-tinytex

COPY maybe_install_vs_code.sh /tmp/maybe_install_vs_code.sh
RUN /tmp/maybe_install_vs_code.sh \
&& rm /tmp/maybe_install_vs_code.sh
Expand Down
7 changes: 7 additions & 0 deletions workbench/test/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,10 @@ command:
"/usr/local/bin/quarto check --quiet":
title: quarto_check
exit-status: 0

# Ensure TinyTeX is installed
"quarto list tools":
title: quarto_tinytex_installed
exit-status: 0
stderr:
- "/tinytex\\s+Up to date\\s+v\\d{4}\\.\\d{2}\\.\\d{2}\\s+v\\d{4}\\.\\d{2}\\.\\d{2}/"

0 comments on commit 6f7c47a

Please sign in to comment.