Skip to content

Commit

Permalink
Merge pull request #39 from WORD-COINS/feature/fast-ci
Browse files Browse the repository at this point in the history
キャッシュを複数ポイントで持つようにした
  • Loading branch information
Till0196 authored Nov 14, 2024
2 parents 2d0364c + 1c58219 commit b393408
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 36 deletions.
64 changes: 47 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,17 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
platform: linux/amd64
- os: macos-latest
platform: linux/arm64
runs-on: ${{ matrix.os }}
platform:
- linux/amd64
- linux/arm64
runs-on: ubuntu-latest
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
echo "REGISTRY_IMAGE=`echo ghcr.io/${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >> ${GITHUB_ENV}
- name: Install Docker and start Colima on macOS
if: matrix.os == 'macos-latest'
run: |
brew install docker
brew install colima
LIMACTL_PATH=$(brew --prefix)/bin/limactl
sudo curl -L -o $LIMACTL_PATH https://github.com/mikekazakov/lima-nohvf/raw/master/limactl && sudo chmod +x $LIMACTL_PATH
colima start --network-address --arch arm64 --vm-type=qemu
- uses: actions/checkout@v4

- name: Docker meta
Expand All @@ -60,6 +49,47 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get current date
run: |
echo "CURRENT_TIME=$(TZ=Asia/Tokyo date "+%Y-%m-%d-%H%M%S")" >> $GITHUB_ENV
- name: Get latest cache key
id: cache-key
# 100MB以上かつ最も新しいキャッシュを取得
run: |
LATEST_CACHE_KEY=$(gh cache list --key cache-pkgs-${{ env.PLATFORM_PAIR }}- --json key,sizeInBytes,createdAt --jq '.[] | select(.sizeInBytes >= 100*1024*1024) | .key' | head -n 1)
echo "LATEST_CACHE_KEY=$LATEST_CACHE_KEY" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Echo latest cache key
run: |
echo $LATEST_CACHE_KEY
- name: Package Cache
id: cache
uses: actions/cache@v4
with:
# keyに固定値を指定するとキャッシュがアップロードされないので、現在の日時を指定
key: cache-pkgs-${{ env.PLATFORM_PAIR }}-${{ env.CURRENT_TIME }}
restore-keys: ${{ env.LATEST_CACHE_KEY }}
path: |
tlmgr-pkgs
var-cache-apt
var-lib-apt-lists
- name: inject cache into docker
# v3.1.2のcommitを指定
uses: reproducible-containers/buildkit-cache-dance@5b6db76d1da5c8b307d5d2e0706d266521b710de
with:
cache-map: |
{
"tlmgr-pkgs": "/tlmgr-pkgs",
"var-cache-apt": "/var/cache/apt",
"var-lib-apt-lists": "/var/lib/apt/lists"
}
skip-extraction: false

- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
Expand All @@ -69,8 +99,8 @@ jobs:
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha
cache-to: type=gha,mode=max
cache-from: type=gha,scope=platform-${{ env.PLATFORM_PAIR }}
cache-to: type=gha,mode=max,scope=platform-${{ env.PLATFORM_PAIR }}

- name: Export digest
run: |
Expand Down
52 changes: 33 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,41 @@ FROM ubuntu:noble AS base
ARG TARGETARCH

FROM base AS build-arm64
ENV AWS_CLI_ARCH=linux-aarch64
ENV TEX_LIVE_ARCH=aarch64-linux
ARG AWS_CLI_ARCH=linux-aarch64
ARG TEX_LIVE_ARCH=aarch64-linux

FROM base AS build-amd64
ENV AWS_CLI_ARCH=linux-x86_64
ENV TEX_LIVE_ARCH=x86_64-linux
ARG AWS_CLI_ARCH=linux-x86_64
ARG TEX_LIVE_ARCH=x86_64-linux

FROM build-${TARGETARCH}

# WORD内部向けコンテナなので、何か問題が有ったらSlack上で通知して下さい。
LABEL maintainer="Totsugekitai <[email protected]>"

ENV PERSISTENT_DEPS="tar fontconfig unzip wget curl make perl ghostscript bash git groff less fonts-ebgaramond"
ARG PERSISTENT_DEPS="ca-certificates tzdata tar fontconfig unzip wget curl \
make perl ghostscript bash git groff less fonts-ebgaramond"

# キャッシュ修正とパッケージインストールは同時にやる必要がある
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
tzdata $PERSISTENT_DEPS
RUN rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
$PERSISTENT_DEPS

# install awscliv2
RUN curl "https://awscli.amazonaws.com/awscli-exe-$AWS_CLI_ARCH.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
./aws/install && \
rm -r ./aws awscliv2.zip

ENV FONT_URLS="https://github.com/adobe-fonts/source-code-pro/archive/2.030R-ro/1.050R-it.zip \
ARG FONT_URLS="https://github.com/adobe-fonts/source-code-pro/archive/2.030R-ro/1.050R-it.zip \
https://github.com/adobe-fonts/source-han-sans/releases/latest/download/SourceHanSansJP.zip \
https://github.com/adobe-fonts/source-han-serif/raw/release/SubsetOTF/SourceHanSerifJP.zip"
ENV FONT_PATH="/usr/share/fonts/"
ARG FONT_PATH="/usr/share/fonts/"
RUN mkdir -p $FONT_PATH && \
wget $FONT_URLS && \
unzip -j "*.zip" "*.otf" -d $FONT_PATH && \
Expand Down Expand Up @@ -65,14 +71,22 @@ RUN echo "Set PATH to $PATH" && \
# tlmgr section
RUN tlmgr update --self

# package install
RUN tlmgr install --no-persistent-downloads \
latexmk collection-luatex collection-langjapanese \
ARG DEPS_FOR_TLMGR="latexmk collection-luatex collection-langjapanese \
collection-fontsrecommended type1cm mdframed needspace newtx \
fontaxes boondox everyhook svn-prov framed subfiles titlesec \
tocdata xpatch etoolbox l3packages \
fontaxes boondox everyhook svn-prov framed subfiles titlesec tocdata \
biblatex pbibtex-base logreq biber import environ trimspaces tcolorbox \
ebgaramond algorithms algorithmicx xstring siunitx bussproofs enumitem && \
ebgaramond algorithms algorithmicx xstring siunitx bussproofs enumitem"

# /tlmgr-pkgsにtlmgrのパッケージをバックアップして次回以降のビルド時に再利用する
# package install
RUN --mount=type=cache,target=/tlmgr-pkgs,sharing=locked \
tlmgr list --only-installed | grep '^i ' | awk '{print $2}' | sed 's/:$//' > /tmp/installed-packages.txt && \
tlmgr restore --force --backupdir /tlmgr-pkgs --all || true && \
tlmgr install --no-persistent-downloads ${DEPS_FOR_TLMGR} && \
tlmgr backup --clean --backupdir /tlmgr-pkgs --all && \
tlmgr list --only-installed | grep '^i ' | awk '{print $2}' | sed 's/:$//' > /tmp/current_installed_packages.txt && \
bash -c 'comm -23 <(sort /tmp/current_installed_packages.txt) <(sort /tmp/installed-packages.txt) > /tmp/new_packages.txt' && \
tlmgr backup $(cat /tmp/new_packages.txt) --backupdir /tlmgr-pkgs && \
tlmgr path add

# EBGaramond
Expand All @@ -81,9 +95,9 @@ RUN cp /usr/share/fonts/opentype/ebgaramond/EBGaramond12-Regular.otf "/usr/share
luaotfload-tool --update

# Install Pandoc
ENV PANDOC_VERSION="3.5"
ENV PANDOC_DOWNLOAD_URL="https://github.com/jgm/pandoc/releases/download/$PANDOC_VERSION/pandoc-$PANDOC_VERSION-linux-$TARGETARCH.tar.gz"
ENV PANDOC_ROOT="/usr/local/bin/pandoc"
ARG PANDOC_VERSION="3.5"
ARG PANDOC_DOWNLOAD_URL="https://github.com/jgm/pandoc/releases/download/$PANDOC_VERSION/pandoc-$PANDOC_VERSION-linux-$TARGETARCH.tar.gz"
ARG PANDOC_ROOT="/usr/local/bin/pandoc"
RUN wget -qO- "$PANDOC_DOWNLOAD_URL" | tar -xzf - && \
cp pandoc-$PANDOC_VERSION/bin/pandoc $PANDOC_ROOT && \
rm -Rf pandoc-$PANDOC_VERSION/
Expand Down

0 comments on commit b393408

Please sign in to comment.