Skip to content

Commit

Permalink
Merge pull request #22 from nansencenter/multi_python_versions
Browse files Browse the repository at this point in the history
Support multiple python versions
  • Loading branch information
akorosov authored Dec 12, 2023
2 parents bff8b7b + f71e53a commit d2bd2b3
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 145 deletions.
102 changes: 27 additions & 75 deletions .github/workflows/build_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,103 +7,55 @@ on:
types: [released]
env:
IMAGE_NAME: "${{ secrets.DOCKER_ORG }}/nansat_base"
TAG: "${{ github.ref_type == 'tag' && github.ref_name || 'tmp' }}"
jobs:
build_standard_docker_image:
build_docker_images:
runs-on: 'ubuntu-20.04'
env:
latest: ${{ matrix.python_version == '3.11' && 'true' || '' }}
strategy:
matrix:
python_version:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
steps:
- name: 'Checkout repository'
uses: actions/checkout@v2

- name: "Extract tag name"
id: get_version
run: |
if [[ $GITHUB_REF == refs/tags/* ]];then
TAG="${GITHUB_REF#refs/tags/}"
else
TAG='tmp'
fi
echo "::set-output name=VERSION::${TAG}"
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-standard-${{ github.sha }}
key: ${{ runner.os }}-buildx-python${{ matrix.python_version }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-standard-
${{ runner.os }}-buildx-python${{ matrix.python_version }}-
- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}

- name: Build docker image
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: ${{ startsWith(github.ref, 'refs/tags/') }}
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
build_slim_docker_image:
runs-on: 'ubuntu-20.04'
steps:
- name: 'Checkout repository'
uses: actions/checkout@v2

- name: "Extract tag name"
id: get_version
run: |
if [[ $GITHUB_REF == refs/tags/* ]];then
TAG="${GITHUB_REF#refs/tags/}"
else
TAG='tmp'
fi
echo "::set-output name=VERSION::${TAG}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-slim-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-slim-
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}

- name: Build docker image
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile_slim
push: ${{ startsWith(github.ref, 'refs/tags/') }}
build-args: 'PYTHON_VERSION=${{ matrix.python_version }}'
push: ${{ github.ref_type == 'tag' }}
tags: |
${{ env.IMAGE_NAME }}:latest-slim
${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}-slim
cache-from: type=local,src=/tmp/.buildx-cache
${{ env.IMAGE_NAME }}:latest-python${{ matrix.python_version }}
${{ env.IMAGE_NAME }}:${{ github.ref_name }}-python${{ matrix.python_version }}
${{ env.latest && format('{0}:{1}', env.IMAGE_NAME, github.ref_name) || '' }}
${{ env.latest && format('{0}:latest', env.IMAGE_NAME) || '' }}
cache-from: |
type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

# Temp fix
Expand Down
25 changes: 17 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM continuumio/miniconda3
FROM continuumio/miniconda3:23.9.0-0

LABEL maintainer="Anton Korosov <anton.korosov@nersc.no>"
LABEL purpose="Python libs for developing and running Nansat"

ARG PYTHON_VERSION=3.7

ENV PYTHONUNBUFFERED=1 \
PYTHONPATH=/src \
MOD44WPATH=/usr/share/MOD44W/
Expand All @@ -11,20 +13,27 @@ RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
gcc \
libxau6 \
&& apt clean \
&& rm -rf /var/lib/apt/lists/*

COPY environment.yml /tmp/environment.yml
COPY environment-${PYTHON_VERSION}.yml /tmp/environment.yml

RUN conda install python=3.7 setuptools \
&& conda update conda \
&& conda env update -n base --file /tmp/environment.yml \
RUN conda env update -n base --file /tmp/environment.yml --prune \
&& rm /tmp/environment.yml \
&& conda clean -a -y \
&& conda clean -a -y -f \
&& rm /opt/conda/pkgs/* -rf \
&& python -c 'import pythesint; pythesint.update_all_vocabularies()' \
&& wget -nc -nv -P /usr/share/MOD44W https://github.com/nansencenter/mod44w/raw/master/MOD44W.tgz \
&& find /opt/conda/ -follow -type f -name '*.a' -delete \
&& find /opt/conda/ -follow -type f -name '*.pyc' -delete

RUN python -c 'import pythesint; pythesint.update_all_vocabularies()'

RUN wget -nc -nv -P /usr/share/MOD44W https://github.com/nansencenter/mod44w/raw/master/MOD44W.tgz \
&& tar -xzf /usr/share/MOD44W/MOD44W.tgz -C /usr/share/MOD44W/ \
&& rm /usr/share/MOD44W/MOD44W.tgz

ENV GDAL_DRIVER_PATH=/opt/conda/lib/gdalplugins
ENV GDAL_DATA=/opt/conda/share/gdal
ENV PROJ_LIB=/opt/conda/share/proj

WORKDIR /src
36 changes: 0 additions & 36 deletions Dockerfile_slim

This file was deleted.

30 changes: 30 additions & 0 deletions environment-3.10.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: environment
channels:
- defaults
- conda-forge
dependencies:
- python=3.10.13
- conda=23.10.0
- nomkl=3.0
- openblas=0.3.21

- cartopy=0.22.0
- coverage=7.2.2
- coveralls=1.7.0
- gdal=3.7.3
- ipython=8.15.0
- matplotlib-base=3.8.0
- mock=4.0.3
- netcdf4=1.6.5
- nose=1.3.7
- numpy-base=1.26.0
- pillow=10.1.0
- pip=23.3
- pyshp=2.3.1
- PyYAML=5.4.1
- scipy=1.11.3
- setuptools=68.0.0
- urllib3=2.0.3
- pip:
- pythesint==1.6.6
30 changes: 30 additions & 0 deletions environment-3.11.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: environment
channels:
- defaults
- conda-forge
dependencies:
- python=3.11.5
- conda=23.10.0
- nomkl=3.0
- openblas=0.3.21

- cartopy=0.22.0
- coverage=7.2.2
- coveralls=1.7.0
- gdal=3.7.3
- ipython=8.15.0
- matplotlib-base=3.8.0
- mock=4.0.3
- netcdf4=1.6.5
- nose=1.3.7
- numpy-base=1.26.0
- pillow=10.1.0
- pip=23.3
- pyshp=2.3.1
- PyYAML=5.4.1
- scipy=1.11.3
- setuptools=68.0.0
- urllib3=2.0.3
- pip:
- pythesint==1.6.6
28 changes: 28 additions & 0 deletions environment-3.7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: environment
channels:
- defaults
dependencies:
- python=3.7.16
- conda=23.1.0
- nomkl=3.0
- openblas=0.3.21

- cartopy=0.18.0
- coverage=6.3.2
- coveralls=1.7.0
- gdal=3.6.0
- ipython=7.31.1
- matplotlib-base=3.5.3
- mock=4.0.3
- netcdf4=1.6.2
- nose=1.3.7
- numpy-base=1.21.5
- pillow=9.4.0
- pip=22.3.1
- PyYAML=5.4.1
- scipy=1.7.3
- setuptools=65.6.3
- urllib3=1.26.14
- pip:
- pythesint==1.6.6
29 changes: 29 additions & 0 deletions environment-3.8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: environment
channels:
- defaults
dependencies:
- python=3.8.18
- conda=23.9.0
- nomkl=3.0
- openblas=0.3.21

- cartopy=0.18.0
- coverage=5.5
- coveralls=3.2.0
- gdal=3.6.2
- ipython=8.12.2
- matplotlib-base=3.5.3
- mock=4.0.3
- netcdf4=1.6.2
- nose=1.3.7
- numpy-base=1.24.3
- pillow=10.0.1
- pip=23.3
- PyYAML=5.4.1
- scipy=1.10.1
- setuptools=68.0.0
- shapely=1.8.4
- urllib3=1.26.18
- pip:
- pythesint==1.6.6
29 changes: 29 additions & 0 deletions environment-3.9.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: environment
channels:
- defaults
dependencies:
- python=3.9.18
- conda=23.10.0
- nomkl=3.0
- openblas=0.3.21

- cartopy=0.18.0
- coverage=7.2.2
- coveralls=1.7.0
- gdal=3.6.2
- ipython=8.15.0
- matplotlib-base=3.5.3
- mock=4.0.3
- netcdf4=1.6.2
- nose=1.3.7
- numpy-base=1.26.0
- pillow=10.0.1
- pip=23.3
- PyYAML=5.4.1
- scipy=1.11.3
- setuptools=68.0.0
- shapely=1.8.4
- urllib3=1.26.18
- pip:
- pythesint==1.6.6
26 changes: 0 additions & 26 deletions environment.yml

This file was deleted.

0 comments on commit d2bd2b3

Please sign in to comment.