Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

キャッシュを複数ポイントで持つようにした #39

Merged
merged 25 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c059b4a
tlmgrをキャッシュするようにした
Till0196 Nov 13, 2024
c3e8414
colimaの起動にqemuが必要らしいので追加
Till0196 Nov 13, 2024
e89b023
apt-get cleanを追加した
Till0196 Nov 13, 2024
6172ab7
tlmgr-pkgsのキャッシュを固定値にした
Till0196 Nov 13, 2024
39ce828
macosにはgnu tarを入れる
Till0196 Nov 13, 2024
e7ec333
fix
Till0196 Nov 13, 2024
9b264f4
fix
Till0196 Nov 13, 2024
6edd738
fix
Till0196 Nov 13, 2024
77ac7d5
$GITHUB_PATHにgnu-tarを使うように書き込む
Till0196 Nov 13, 2024
964dc94
パス確認のstepを追加
Till0196 Nov 13, 2024
bbe9242
せっかくなのでaptのパッケージもキャッシュさせてみる
Till0196 Nov 13, 2024
f639434
イメージ作成後に毎回キャッシュ送信を行うようにした
Till0196 Nov 13, 2024
fd87d98
macをやめて、全てqemuでやらせてみる
Till0196 Nov 13, 2024
5787b99
etoolbox l3packages xpatchはsmallイメージに含まれているので削除
Till0196 Nov 13, 2024
7e60d3c
fix-ci
Till0196 Nov 13, 2024
17db532
fix-ci
Till0196 Nov 13, 2024
09b925b
fix
Till0196 Nov 13, 2024
867ab15
tokyo時間に設定
Till0196 Nov 13, 2024
09d94ee
100MB以上の最も新しいキャッシュを使うようにした
Till0196 Nov 13, 2024
84d4bd8
fix
Till0196 Nov 13, 2024
b96dfc3
fix
Till0196 Nov 13, 2024
70a256e
効率よくパッケージをバックアップするようにした
Till0196 Nov 13, 2024
9ca95a0
fix workflow
Till0196 Nov 13, 2024
8a8bdd6
optimize
Till0196 Nov 13, 2024
1c58219
scopeを設定
Till0196 Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 47 additions & 17 deletions .github/workflows/ci.yml
Till0196 marked this conversation as resolved.
Show resolved Hide resolved
Till0196 marked this conversation as resolved.
Show resolved Hide resolved
Till0196 marked this conversation as resolved.
Show resolved Hide resolved
Till0196 marked this conversation as resolved.
Show resolved Hide resolved
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: |
Till0196 marked this conversation as resolved.
Show resolved Hide resolved
Till0196 marked this conversation as resolved.
Show resolved Hide resolved
Till0196 marked this conversation as resolved.
Show resolved Hide resolved
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: |
Till0196 marked this conversation as resolved.
Show resolved Hide resolved
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: |
Till0196 marked this conversation as resolved.
Show resolved Hide resolved
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: |
Till0196 marked this conversation as resolved.
Show resolved Hide resolved
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 \
Till0196 marked this conversation as resolved.
Show resolved Hide resolved
--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 \
Till0196 marked this conversation as resolved.
Show resolved Hide resolved
Till0196 marked this conversation as resolved.
Show resolved Hide resolved
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