From 751af36a9ba6904504a966c40c2e1544680c7434 Mon Sep 17 00:00:00 2001 From: Wen Wei Tseng Date: Sat, 11 Nov 2023 01:31:25 +0800 Subject: [PATCH] docker --- .github/dependabot.yml | 14 ++++++ .github/workflows/ci.yml | 68 +++++++++++---------------- .github/workflows/update-manifest.yml | 18 +++++-- environment.yml => conda.yml | 4 -- env.Dockerfile | 28 +++++++++++ requirements.txt | 0 6 files changed, 83 insertions(+), 49 deletions(-) rename environment.yml => conda.yml (55%) create mode 100644 env.Dockerfile create mode 100644 requirements.txt diff --git a/.github/dependabot.yml b/.github/dependabot.yml index df3f89d6..d88ba24b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,5 +1,12 @@ version: 2 updates: + - package-ecosystem: pip + directory: "/" + open-pull-requests-limit: 1 + schedule: + interval: daily + labels: + - automerge - package-ecosystem: github-actions directory: "/" open-pull-requests-limit: 1 @@ -7,3 +14,10 @@ updates: interval: daily labels: - automerge + - package-ecosystem: docker + directory: "/" + open-pull-requests-limit: 1 + schedule: + interval: daily + labels: + - automerge diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a8c6621..cb19cad1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,58 +13,46 @@ concurrency: env: NPROC: '2' # Number of Julia processes to run the notebooks - JULIA_CPU_TARGET: 'generic;haswell,clone_all' - JULIA_NUM_THREADS: 'auto' - JULIA_CONDAPKG_BACKEND: 'Current' - JULIA_CI: 'true' - GKSwstype: '100' - JULIA_CACHE_NUM: '1' jobs: CI: runs-on: ubuntu-latest + permissions: + packages: write steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ github.token }} + - name: Get docker image hash + id: img + run: echo "hash=${{ hashFiles('requirements.txt', 'Project.toml', 'Manifest.toml', 'src/**', 'env.Dockerfile') }}" >> "$GITHUB_OUTPUT" + - name: Build Docker container + env: + IMG: ghcr.io/${{ github.repository }}:${{ steps.img.outputs.hash }} + run: | + docker manifest inspect ${IMG} && exit 0 + docker build -f env.Dockerfile -t ${IMG} . + docker push ${IMG} + - name: Run Literate notebooks + env: + IMG: ghcr.io/${{ github.repository }}:${{ steps.img.outputs.hash }} + run: > + docker run --rm + -w /tmp -v ${{ github.workspace }}:/tmp + -e JULIA_PROJECT=@. + ${IMG} + julia --color=yes -p ${{ env.NPROC }} literate.jl - name: Setup micromamba uses: mamba-org/setup-micromamba@v1 with: - environment-file: environment.yml + environment-file: conda.yml cache-environment: true post-cleanup: all - - name: Read Julia version - uses: SebRollen/toml-action@v1.0.2 - id: read_toml - with: - file: 'Manifest.toml' - field: 'julia_version' - - name: Install Julia using jill.sh - run: | - wget -O /tmp/jill.sh https://raw.githubusercontent.com/abelsiqueira/jill/main/jill.sh - bash /tmp/jill.sh --version ${{ steps.read_toml.outputs.value }} -y - echo "$HOME/.local/bin" >> $GITHUB_PATH - - name: Cache Julia deps - uses: actions/cache@v3 - with: - path: | - ~/.julia/artifacts - ~/.julia/compiled - ~/.julia/packages - ~/.julia/environments - ~/.julia/scratchspaces - key: ${{ runner.os }}-jill-${{ env.JULIA_CACHE_NUM }}-${{ hashFiles('src/**','Project.toml', 'Manifest.toml')}} - restore-keys: | - ${{ runner.os }}-jill-${{ env.JULIA_CACHE_NUM }}- - - name: Install Julia deps - shell: micromamba-shell {0} - run: | - julia --color=yes -e 'using Pkg; Pkg.add(["PrettyTables", "Literate"])' - julia --project=@. --color=yes -e 'using Pkg, Dates; Pkg.instantiate(); Pkg.precompile(); Pkg.gc(collect_delay=Day(1))' - - name: Run program - shell: micromamba-shell {0} - env: - JULIA_PROJECT: '@.' - run: julia --color=yes -p ${{ env.NPROC }} literate.jl - name: Build website shell: micromamba-shell {0} run: jupyter-book build docs/ diff --git a/.github/workflows/update-manifest.yml b/.github/workflows/update-manifest.yml index 45e51a62..bd9419c1 100644 --- a/.github/workflows/update-manifest.yml +++ b/.github/workflows/update-manifest.yml @@ -16,6 +16,7 @@ concurrency: env: APP_ID: '189113' # https://github.com/apps/wen-wei-s-pr-bot + IMG_NAME: 'app:test' jobs: update-manifest: @@ -26,12 +27,19 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Setup Julia - uses: julia-actions/setup-julia@v1 + - name: Build and load docker image + uses: docker/build-push-action@v5 + with: + context: . + file: 'env.Dockerfile' + tags: ${{ env.IMG_NAME }} + load: true + target: base - name: Update Julia dependencies - env: - JULIA_PKG_PRECOMPILE_AUTO: '0' - run: julia --color=yes --project=@. -e 'import Pkg; Pkg.update()' + run: > + docker run --rm -e JULIA_PKG_PRECOMPILE_AUTO=0 + ${{ env.IMG_NAME }} + julia --color=yes --project=@. -e 'import Pkg; Pkg.update()' # Authenticate with a custom GitHub APP # https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens - name: Generate token for PR diff --git a/environment.yml b/conda.yml similarity index 55% rename from environment.yml rename to conda.yml index 3c257969..8a3e7bc8 100644 --- a/environment.yml +++ b/conda.yml @@ -1,10 +1,6 @@ name: ci dependencies: - - python>=3.11 # Jupyter Book - jupyter-book - docutils>=0.17.1,<0.18|>=0.20 - # PythonPlot - # - matplotlib - # - libstdcxx-ng<13.0 diff --git a/env.Dockerfile b/env.Dockerfile new file mode 100644 index 00000000..d6653ed3 --- /dev/null +++ b/env.Dockerfile @@ -0,0 +1,28 @@ +FROM julia:1.9.3 as julia +FROM python:3.12.0-slim as base + +# Julia config +ENV JULIA_CI 'true' +ENV JULIA_NUM_THREADS 'auto' +# Let PythonCall use built-in python +ENV JULIA_CONDAPKG_BACKEND 'Null' +# Simple output for GR +ENV GKSwstype '100' +ENV JULIA_CPU_TARGET 'generic;haswell,clone_all' +ENV JULIA_PATH '/usr/local/julia/' +ENV JULIA_DEPOT_PATH '/srv/juliapkg/' +ENV PATH ${JULIA_PATH}/bin:${PATH} +COPY --from=julia ${JULIA_PATH} ${JULIA_PATH} + +FROM base + +WORKDIR /work + +# Python dependencies. e.g. matplotlib +COPY requirements.txt ./ +RUN pip install --no-cache-dir nbconvert -r requirements.txt + +# Julia environment +COPY Project.toml Manifest.toml ./ +COPY src/ src +RUN julia --color=yes -e 'using Pkg; Pkg.add(["PrettyTables", "Literate"]); Pkg.activate("."); Pkg.instantiate(); Pkg.precompile()' diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..e69de29b