Skip to content

Commit

Permalink
update(build): build script
Browse files Browse the repository at this point in the history
  • Loading branch information
HolgerHuo committed Oct 16, 2024
1 parent 3dbeff4 commit 6fc6567
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 23 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/build-base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: build and push sharelatex-base image

on:
workflow_dispatch:
inputs:
revision:
description: 'image revision number'
required: true
default: '1'
type: string

env:
REGISTRY: ghcr.io
IMAGE_NAME: lcpu-club/sharelatex-base

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
strategy:
matrix:
version: ["latest",2022,2020]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
labels: |
org.opencontainers.image.title=sharelatex-base
org.opencontainers.image.description=base image for overleaf
#- name: Set up QEMU
# uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare to build
run: |
cp ${{ github.workspace }}/server-ce/.dockerignore ${{ github.workspace }}
- name: Build and push
if: ${{ matrix.version != 'latest' }}
uses: docker/build-push-action@v6
with:
provenance: false
build-args: |
TEXLIVE_MIRROR=https://ftp.math.utah.edu/pub/tex/historic/systems/texlive/${{ matrix.version }}/tlnet-final
TEXLIVE_VERSION=${{ matrix.version }}
push: true
context: ${{ github.workspace }}
file: ${{ github.workspace }}/server-ce/Dockerfile-base
#platforms: linux/amd64
tags: |
ghcr.io/lcpu-club/sharelatex-base:${{ matrix.version }}
ghcr.io/lcpu-club/sharelatex-base:${{ matrix.version }}.${{ inputs.revision }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=registry,ref=ghcr.io/lcpu-club/sharelatex-base:${{ matrix.version }}.${{ inputs.revision }}
type=registry,ref=ghcr.io/lcpu-club/sharelatex-base:${{ matrix.version }}
type=registry,ref=ghcr.io/lcpu-club/sharelatex-base:latest
cache-to: type=inline
- name: Get current year
if: ${{ matrix.version == 'latest' }}
id: date
run: echo "year=$(date +'%Y')" >> $GITHUB_OUTPUT
- name: Build and push
if: ${{ matrix.version == 'latest' }}
uses: docker/build-push-action@v6
with:
provenance: false
build-args: |
TEXLIVE_MIRROR=https://mirror.ox.ac.uk/sites/ctan.org/systems/texlive/tlnet
TEXLIVE_VERSION=${{ steps.date.outputs.year }}
push: true
context: ${{ github.workspace }}
file: ${{ github.workspace }}/server-ce/Dockerfile-base
#platforms: linux/amd64
tags: |
ghcr.io/lcpu-club/sharelatex-base:latest
ghcr.io/lcpu-club/sharelatex-base:${{ steps.date.outputs.year }}.${{ inputs.revision }}
ghcr.io/lcpu-club/sharelatex-base:${{ steps.date.outputs.year }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=registry,ref=ghcr.io/lcpu-club/sharelatex-base:${{ steps.date.outputs.year }}.${{ inputs.revision }}
type=registry,ref=ghcr.io/lcpu-club/sharelatex-base:${{ steps.date.outputs.year }}
type=registry,ref=ghcr.io/lcpu-club/sharelatex-base:latest
cache-to: type=inline
70 changes: 70 additions & 0 deletions .github/workflows/build-overleaf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: build and push sharelatex image

on:
push:
tags:
- "v*.*.*"
release:
types: [published]
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: lcpu-club/sharelatex

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
labels: |
org.opencontainers.image.title=overleaf
org.opencontainers.image.description=overleaf
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
type=ref,event=branch
#- name: Set up QEMU
# uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare to build
run: |
cp ${{ github.workspace }}/server-ce/.dockerignore ${{ github.workspace }}
- name: Build and push
uses: docker/build-push-action@v6
with:
provenance: false
build-args: |
OVERLEAF_BASE=ghcr.io/lcpu-club/sharelatex-base:latest
MONOREPO_REVISION=${{ github.sha }}
push: true
context: ${{ github.workspace }}
file: ${{ github.workspace }}/server-ce/Dockerfile
#platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=registry,ref=ghcr.io/lcpu-club/sharelatex:latest
type=registry,ref=ghcr.io/lcpu-club/sharelatex:main
cache-to: type=inline
27 changes: 27 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/bash
# Usage:
# 1. Add font source to .env
# 2. Build OCI Images
# 1) To build overleaf image, run ./deploy.sh
# 2) To also build base image, run ./deploy.sh REV_NUMBER VERSIONS...
# e.g. ./deploy.sh 2 latest 2023 2022 2021 2020

source .env

# download fonts
curl "$FONT_URL" --output fonts.zip

mkdir tmp_fonts
unzip fonts.zip -d tmp_fonts
mv tmp_fonts/fonts/* fonts

rm -rf tmp_fonts fonts.zip

cd server-ce

for version in "${@:2}"
do
VERSION=$version REV=$1 make build-base
done

make build-community
Empty file added fonts/.gitkeep
Empty file.
20 changes: 14 additions & 6 deletions server-ce/Dockerfile-base
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
build-essential wget net-tools unzip time imagemagick optipng strace nginx git python3 python-is-python3 zlib1g-dev libpcre3-dev gettext-base libwww-perl ca-certificates curl gnupg \
qpdf \
aspell aspell-en aspell-af aspell-am aspell-ar aspell-ar-large aspell-bg aspell-bn aspell-br aspell-ca aspell-cs aspell-cy aspell-da aspell-de aspell-de-1901 aspell-el aspell-eo aspell-es aspell-et aspell-eu-es aspell-fa aspell-fo aspell-fr aspell-ga aspell-gl-minimos aspell-gu aspell-he aspell-hi aspell-hr aspell-hsb aspell-hu aspell-hy aspell-id aspell-is aspell-it aspell-kk aspell-kn aspell-ku aspell-lt aspell-lv aspell-ml aspell-mr aspell-nl aspell-no aspell-nr aspell-ns aspell-pa aspell-pl aspell-pt aspell-pt-br aspell-ro aspell-ru aspell-sk aspell-sl aspell-ss aspell-st aspell-sv aspell-tl aspell-tn aspell-ts aspell-uk aspell-uz aspell-xh aspell-zu \
python3-pygments fonts-noto \
# upgrade base-image, batch all the upgrades together, rather than installing them on-by-one (which is slow!)
&& unattended-upgrade --verbose --no-minimal-upgrade-steps \
# install Node.js https://github.com/nodesource/distributions#nodejs
Expand All @@ -49,6 +50,8 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
# --build-arg TEXLIVE_MIRROR=https://ctan.crest.fr/tex-archive/systems/texlive/tlnet \
# -f Dockerfile-base -t sharelatex/sharelatex-base .
ARG TEXLIVE_MIRROR=https://mirror.ox.ac.uk/sites/ctan.org/systems/texlive/tlnet
ARG TEXLIVE_VERSION=2024
ENV PATH="$PATH:/usr/local/texlive/${TEXLIVE_VERSION}/bin/x86_64-linux"

RUN mkdir /install-tl-unx \
&& wget --quiet https://tug.org/texlive/files/texlive.asc \
Expand All @@ -71,15 +74,20 @@ RUN mkdir /install-tl-unx \
-repository ${TEXLIVE_MIRROR} \
\
&& $(find /usr/local/texlive -name tlmgr) path add \
&& tlmgr install --repository ${TEXLIVE_MIRROR} \
latexmk \
texcount \
synctex \
etoolbox \
xetex \
&& tlmgr option repository ${TEXLIVE_MIRROR} \
&& tlmgr update --self \
&& tlmgr install scheme-full \
&& tlmgr path add \
&& rm -rf /install-tl-unx

# Copy default latexmkrc
# -----------------------
COPY server-ce/config/latexmkrc /usr/local/share/latexmk/LatexMk

# Install fonts
# --------------------------
COPY fonts/. /usr/local/share/fonts/
RUN fc-cache -f -v

# Set up overleaf user and home directory
# -----------------------------------------
Expand Down
58 changes: 41 additions & 17 deletions server-ce/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
# Makefile
# Usage:
# This makefile has two targets: build-base and build-community
# Use environment VERSION and REV to specify TEX version and OCI Image tag revision number, e.g.:
# VERSION=2022 REV=3 make
# VERSION defaults to latest and REV defaults to 1
# All variables below assigned with ?= can be safely overwritten by env

MONOREPO_ROOT := ../

REV ?= 1
VERSION ?= latest

ifeq ($(VERSION),latest)
MIRROR ?= https://mirror.ox.ac.uk/sites/ctan.org/systems/texlive/tlnet
else
MIRROR ?= https://ftp.math.utah.edu/pub/tex/historic/systems/texlive/$(VERSION)/tlnet-final
endif

export MONOREPO_REVISION := $(shell git rev-parse HEAD)
export BRANCH_NAME ?= $(shell git rev-parse --abbrev-ref HEAD)
export OVERLEAF_BASE_BRANCH ?= sharelatex/sharelatex-base:$(BRANCH_NAME)
export OVERLEAF_BASE_LATEST ?= sharelatex/sharelatex-base
export OVERLEAF_BASE_TAG ?= sharelatex/sharelatex-base:$(BRANCH_NAME)-$(MONOREPO_REVISION)
export OVERLEAF_BRANCH ?= sharelatex/sharelatex:$(BRANCH_NAME)
export OVERLEAF_LATEST ?= sharelatex/sharelatex
export OVERLEAF_TAG ?= sharelatex/sharelatex:$(BRANCH_NAME)-$(MONOREPO_REVISION)
OVERLEAF_BASE ?= ghcr.io/lcpu-club/sharelatex-base
OVERLEAF ?= ghcr.io/lcpu-club/sharelatex

ifeq ($(VERSION),latest)
YEAR ?= $(shell date '+%Y')
IS_LATEST ?= docker tag $(OVERLEAF_BASE):$(YEAR).$(REV) $(OVERLEAF_BASE):latest # && docker push $(OVERLEAF_BASE):latest
else
YEAR?=$(VERSION)
IS_LATEST ?= @true
endif

all: build-base build-community

Expand All @@ -19,26 +38,31 @@ build-base:
--progress=plain \
--file Dockerfile-base \
--pull \
--cache-from $(OVERLEAF_BASE_LATEST) \
--cache-from $(OVERLEAF_BASE_BRANCH) \
--tag $(OVERLEAF_BASE_TAG) \
--tag $(OVERLEAF_BASE_BRANCH) \
--cache-from $(OVERLEAF_BASE):$(YEAR).$(REV) \
--cache-from $(OVERLEAF_BASE):$(YEAR) \
--cache-from $(OVERLEAF_BASE):latest \
--tag $(OVERLEAF_BASE):$(YEAR).$(REV) \
--tag $(OVERLEAF_BASE):$(YEAR) \
--build-arg TEXLIVE_MIRROR=$(MIRROR) \
--build-arg TEXLIVE_VERSION=$(YEAR) \
$(MONOREPO_ROOT)

docker push $(OVERLEAF_BASE):$(YEAR).$(REV)
$(IS_LATEST)

build-community:
cp .dockerignore $(MONOREPO_ROOT)
docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--progress=plain \
--build-arg OVERLEAF_BASE_TAG \
--build-arg OVERLEAF_BASE=$(OVERLEAF_BASE):latest \
--build-arg MONOREPO_REVISION \
--cache-from $(OVERLEAF_LATEST) \
--cache-from $(OVERLEAF_BRANCH) \
--cache-from $(OVERLEAF):latest \
--file Dockerfile \
--tag $(OVERLEAF_TAG) \
--tag $(OVERLEAF_BRANCH) \
--tag $(OVERLEAF):latest \
--tag $(OVERLEAF):main-$(MONOREPO_REVISION) \
$(MONOREPO_ROOT)
#docker push $(OVERLEAF):latest
#docker push $(OVERLEAF):main-$(MONOREPO_REVISION)


.PHONY: all build-base build-community
4 changes: 4 additions & 0 deletions server-ce/config/latexmkrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# equivalent to -gt option. Used to prevent latexmk from skipping recompilation
# of output.log and output.pdf
$go_mode = 3;
$pdflatex = 'pdflatex -shell-escape %O %S';
$xelatex = 'xelatex -shell-escape %O %S';
$lualatex = 'lualatex -shell-escape %O %S';
$latex = 'latex -shell-escape %O %S';

0 comments on commit 6fc6567

Please sign in to comment.