Skip to content

Commit a430453

Browse files
authored
DEV - Update Meson-gitpod (#1)
* 🏗️ [ENH] - Update Dockerfile - split into Meson and dev * ENH - Split Dockerbuilds * DEV: Add pip to avoid warning * ENH: Add docs to Dockerfile * DEV: Improve Docker build * DEV: Quick fix for env setup * DEV: Testing - will revert * DEV: Only use docutils * DEV: Revert test * DEV: Docutils install - will remove later
1 parent e849b98 commit a430453

File tree

10 files changed

+287
-39
lines changed

10 files changed

+287
-39
lines changed

.github/workflows/docker.yml

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ on:
77
branches:
88
- main
99
paths:
10+
# will keep both until there is a reason to get rid of scipy-dev entirely
1011
- 'environment_meson.yml'
12+
- 'environment.yml'
1113

1214
jobs:
13-
build:
15+
build-dev-base:
1416
name: Build base Docker image
1517
runs-on: ubuntu-latest
16-
environment: scipy-meson
18+
environment: scipy-dev
1719
if: "github.repository_owner == 'scipy' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]')"
1820
steps:
1921
- name: Clone repository
@@ -34,12 +36,52 @@ jobs:
3436
id: getrefs
3537
- name: Set up Docker Buildx
3638
uses: docker/setup-buildx-action@v1
37-
- name: Cache Docker layers
38-
uses: actions/cache@v3
39+
- name: Login to Docker Hub
40+
uses: docker/login-action@v1
41+
with:
42+
username: ${{ secrets.DOCKERHUB_USERNAME }}
43+
password: ${{ secrets.DOCKERHUB_TOKEN }}
44+
- name: Build and push
45+
id: docker_build
46+
uses: docker/build-push-action@v2
47+
with:
48+
context: "."
49+
file: "./tools/docker_dev/meson.Dockerfile"
50+
push: ${{ github.event_name != 'pull_request' }}
51+
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
52+
cache-from: type=gha
53+
cache-to: type=gha,mode=max
54+
tags: |
55+
scipy/scipy-dev:${{ steps.getrefs.outputs.date }}-${{ steps.getrefs.outputs.branch}}-${{ steps.getrefs.outputs.sha8 }}
56+
scipy/scipy-dev:latest
57+
- name: Image digest
58+
# Return details of the image build: sha and shell
59+
run: echo ${{ steps.docker_build.outputs.digest }}
60+
61+
build-meson-base:
62+
name: Build base Docker image
63+
runs-on: ubuntu-latest
64+
environment: scipy-dev
65+
if: "github.repository_owner == 'scipy' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]')"
66+
steps:
67+
- name: Clone repository
68+
uses: actions/checkout@v3
3969
with:
40-
path: /tmp/.buildx-cache
41-
key: ${{ runner.os }}-buildx-${{ github.sha }}
42-
restore-keys: ${{ runner.os }}-buildx-
70+
submodules: recursive
71+
- name: Lint Docker
72+
uses: brpaz/hadolint-action@v1.2.1
73+
with:
74+
dockerfile: ./tools/docker_dev/meson.Dockerfile
75+
- name: Get refs
76+
shell: bash
77+
run: |
78+
export raw_branch=${GITHUB_REF#refs/heads/}
79+
echo "::set-output name=branch::${raw_branch//\//-}"
80+
echo "::set-output name=date::$(date +'%Y%m%d')"
81+
echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)"
82+
id: getrefs
83+
- name: Set up Docker Buildx
84+
uses: docker/setup-buildx-action@v1
4385
- name: Login to Docker Hub
4486
uses: docker/login-action@v1
4587
with:
@@ -55,7 +97,8 @@ jobs:
5597
cache-from: type=local,src=/tmp/.buildx-cache
5698
cache-to: type=local,dest=/tmp/.buildx-cache
5799
tags: |
58-
scipy/scipy-dev:${{ steps.getrefs.outputs.date }}-${{ steps.getrefs.outputs.branch}}-${{ steps.getrefs.outputs.sha8 }}, scipy/scipy-dev:latest
100+
scipy/scipy-meson:${{ steps.getrefs.outputs.date }}-${{ steps.getrefs.outputs.branch}}-${{ steps.getrefs.outputs.sha8 }}
101+
scipy/scipy-meson:latest
59102
- name: Image digest
60103
# Return details of the image build: sha and shell
61104
run: echo ${{ steps.docker_build.outputs.digest }}

.github/workflows/gitpod.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build:
99
name: Build Gitpod Docker image
1010
runs-on: ubuntu-latest
11-
environment: scipy-meson
11+
environment: scipy-dev
1212
if: "github.repository_owner == 'scipy' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]')"
1313
steps:
1414
- name: Clone repository
@@ -27,12 +27,6 @@ jobs:
2727
id: getrefs
2828
- name: Set up Docker Buildx
2929
uses: docker/setup-buildx-action@v1
30-
- name: Cache Docker layers
31-
uses: actions/cache@v3
32-
with:
33-
path: /tmp/.buildx-cache
34-
key: ${{ runner.os }}-buildx-${{ github.sha }}
35-
restore-keys: ${{ runner.os }}-buildx-
3630
- name: Login to Docker Hub
3731
uses: docker/login-action@v1
3832
with:
@@ -47,8 +41,13 @@ jobs:
4741
push: ${{ github.event_name != 'pull_request' }}
4842
cache-from: type=local,src=/tmp/.buildx-cache
4943
cache-to: type=local,dest=/tmp/.buildx-cache
44+
build-args: |
45+
BASE_CONTAINER="scipy/scipy-meson:latest"
46+
BUILD_ARG="python dev.py --build-only -j2
47+
CONDA_ENV="scipy-meson"
5048
tags: |
51-
scipy/scipy-gitpod:${{ steps.getrefs.outputs.date }}-${{ steps.getrefs.outputs.branch}}-${{ steps.getrefs.outputs.sha8 }}, scipy/scipy-gitpod:latest
49+
scipy/scipy-gitpod:${{ steps.getrefs.outputs.date }}-${{ steps.getrefs.outputs.branch}}-${{ steps.getrefs.outputs.sha8 }}
50+
scipy/scipy-gitpod:latest
5251
- name: Image digest
5352
# Return details of the image build: sha and shell
5453
run: echo ${{ steps.docker_build.outputs.digest }}

.gitpod.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tasks:
1313
mkdir -p .vscode
1414
cp tools/docker_dev/settings.json .vscode/settings.json
1515
conda activate scipy-meson
16+
python -m pip install docutils
1617
git submodule update --init
1718
python dev.py --build-only -j2
1819
echo "🛠 Completed rebuilding SciPy!! 🛠 "
@@ -31,13 +32,13 @@ ports:
3132
vscode:
3233
extensions:
3334
- eamodio.gitlens
34-
- njpwerner.autodocstring
35+
- bungcip.better-toml
3536
- lextudio.restructuredtext
36-
- ritwickdey.liveserver
3737
- ms-python.python
38+
- njpwerner.autodocstring
39+
- ritwickdey.liveserver
40+
- trond-snekvik.simple-rst
3841
- yzhang.markdown-all-in-one
39-
- bungcip.better-toml
40-
- mhutchie.git-graph
4142

4243
# --------------------------------------------------------
4344
# using prebuilds for the container - note: atm this only

environment.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ dependencies:
4242
# For CLI
4343
- rich-click
4444
- click
45+
# Else Docker raise a warning
46+
- pip
4547
- pip:
4648
- doit==0.35.0

environment_meson.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,7 @@ dependencies:
4545
# For CLI
4646
- rich-click
4747
- click
48+
# Else Docker raise a warning
49+
- pip
4850
- pip:
4951
- doit==0.35.0

tools/docker_dev/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# Usage:
55
# -------
66
#
7-
# To make a local build of the container, from the 'Docker-dev' directory:
8-
# docker build --rm -f "Dockerfile" -t <build-tag> "."
7+
# To make a local build of the container, from the root directory:
8+
# docker build --rm -f "./tools/docker_dev/Dockerfile" -t <build-tag> "."
99
#
1010
# To use the container use the following command. It assumes that you are in
1111
# the root folder of the scipy git repository, making it available as

tools/docker_dev/gitpod.Dockerfile

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
# Dockerfile for SciPy - gitpod-based development
2+
# Usage:
3+
# -------
4+
#
5+
# To make a local build of the container, from the root directory:
6+
# docker build --rm -f "./tools/docker_dev/gitpod.Dockerfile" -t <build-tag> "."
7+
# docker build --rm -f "./tools/docker_dev/gitpod.Dockerfile" -t scipy/scipy-gitpod:latest "." --build-arg BASE_CONTAINER="scipy/scipy-meson:latest" --build-arg CONDA_ENV="scipy-meson" --build-arg BUILD_ARG="python dev.py --build-only -j2"
8+
#
19
# Doing a local shallow clone - keeps the container secure
210
# and much slimmer than using COPY directly or cloning a remote
11+
# To use the Meson container you'll need to use
12+
# --build-arg BASE_CONTAINER="scipy/scipy-meson:latest"
313
ARG BASE_CONTAINER=scipy/scipy-dev:latest
414
FROM ${BASE_CONTAINER} as clone
515

@@ -8,20 +18,27 @@ FROM ${BASE_CONTAINER} as clone
818
COPY --chown=gitpod . /tmp/scipy_repo
919
RUN git clone --depth 1 file:////tmp/scipy_repo /tmp/scipy
1020

21+
# -----------------------------------------------------------------------------
1122
# Using the Scipy-dev Docker image as a base
1223
# This way, we ensure we have all the needed compilers and dependencies
13-
# while reducing the build time
24+
# while reducing the build time - making this a build ARG so we can reuse for other images
25+
# to use the meson image instead --build-arg BASE_CONTAINER="scipy/scipy-meson:latest"
1426
ARG BASE_CONTAINER=scipy/scipy-dev:latest
1527
FROM ${BASE_CONTAINER} as build
1628

29+
# Build argument - can pass Meson arguments during the build:
30+
# --build-arg BUILD_ARG="python dev.py --build-only -j2"
31+
# --build-arg CONDA_ENV="scipy-meson"
32+
ARG BUILD_ARG="python setup.py build_ext --inplace" \
33+
CONDA_ENV=scipy-dev
34+
1735
# -----------------------------------------------------------------------------
1836
USER root
1937

2038
# -----------------------------------------------------------------------------
2139
# ---- ENV variables ----
2240
# ---- Directories needed ----
23-
ENV WORKSPACE=/workspace/scipy/ \
24-
CONDA_ENV=scipy-dev
41+
ENV WORKSPACE=/workspace/scipy/
2542

2643
# -----------------------------------------------------------------------------
2744
# Change default shell - this avoids issues with Conda later - note we do need
@@ -35,15 +52,18 @@ COPY --from=clone --chown=gitpod /tmp/scipy ${WORKSPACE}
3552

3653
WORKDIR ${WORKSPACE}
3754

38-
# Build scipy to populate the cache used by ccache
55+
# Build SciPy to populate the cache used by ccache
3956
# Must re-activate conda to ensure the ccache flags are picked up
40-
RUN git submodule update --init --depth=1 -- scipy/_lib/boost
41-
RUN git submodule update --init --depth=1 -- scipy/sparse/linalg/_propack/PROPACK
42-
RUN git submodule update --init --depth=1 -- scipy/_lib/unuran
43-
RUN git submodule update --init --depth=1 -- scipy/_lib/highs
57+
RUN git submodule update --init --depth=1 -- scipy/_lib/boost &&\
58+
git submodule update --init --depth=1 -- scipy/sparse/linalg/_propack/PROPACK && \
59+
git submodule update --init --depth=1 -- scipy/_lib/unuran && \
60+
git submodule update --init --depth=1 -- scipy/_lib/highs
61+
4462
RUN conda activate ${CONDA_ENV} && \
45-
python setup.py build_ext --inplace && \
46-
ccache -s
63+
${BUILD_ARG} && \
64+
ccache -s && \
65+
# needed for rst preview in gitpod
66+
python3 -m pip install docutils
4767

4868
# Gitpod will load the repository into /workspace/scipy. We remove the
4969
# directoy from the image to prevent conflicts

0 commit comments

Comments
 (0)