Skip to content

Commit

Permalink
use two-stage image with micromamba for cells
Browse files Browse the repository at this point in the history
  • Loading branch information
gpelouze committed Feb 15, 2024
1 parent 6f83041 commit b03945d
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 29 deletions.
34 changes: 26 additions & 8 deletions .github/workflows/make-flavor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ on:
required: true

jobs:
build-naavre-cell:
build-naavre-cell-build:
uses: ./.github/workflows/build-image.yaml
with:
dockerfile: naavre-cell.Dockerfile
dockerfile: naavre-cell-build.Dockerfile
flavor_dir: './flavors/${{ inputs.flavor_name }}'
image_name: naavre-cell-${{ inputs.flavor_name }}
image_name: naavre-cell-build-${{ inputs.flavor_name }}
image_repo: ${{ inputs.image_repo }}
image_version: ${{ inputs.image_version }}

build-naavre-cell-runtime:
uses: ./.github/workflows/build-image.yaml
with:
dockerfile: naavre-cell-runtime.Dockerfile
flavor_dir: './flavors/${{ inputs.flavor_name }}'
image_name: naavre-cell-runtime-${{ inputs.flavor_name }}
image_repo: ${{ inputs.image_repo }}
image_version: ${{ inputs.image_version }}

Expand All @@ -42,17 +51,26 @@ jobs:

test:
uses: ./.github/workflows/test-naavre-cell.yaml
needs: [build-naavre-cell]
needs: [build-naavre-cell-build, build-naavre-cell-runtime]
with:
image_name: naavre-cell-${{ inputs.flavor_name }}
image_name_build: naavre-cell-build-${{ inputs.flavor_name }}
image_name_runtime: naavre-cell-runtime-${{ inputs.flavor_name }}
image_repo: ${{ inputs.image_repo }}
tests_dir: './flavors/${{ inputs.flavor_name }}/tests/'

push-naavre-cell:
push-naavre-cell-build:
uses: ./.github/workflows/push-image.yaml
needs: [build-naavre-cell-build, test]
with:
image_name: naavre-cell-build-${{ inputs.flavor_name }}
image_repo: ${{ inputs.image_repo }}
if: ${{ github.event_name == 'release' }}

push-naavre-cell-runtime:
uses: ./.github/workflows/push-image.yaml
needs: [build-naavre-cell, test]
needs: [build-naavre-cell-runtime, test]
with:
image_name: naavre-cell-${{ inputs.flavor_name }}
image_name: naavre-cell-runtime-${{ inputs.flavor_name }}
image_repo: ${{ inputs.image_repo }}
if: ${{ github.event_name == 'release' }}

Expand Down
25 changes: 22 additions & 3 deletions .github/workflows/test-naavre-cell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ name: Test cell base image
on:
workflow_call:
inputs:
image_name:
description: 'Docker image name'
image_name_build:
description: 'Docker image name for build stage'
type: string
required: true
image_name_runtime:
description: 'Docker image name for runtime stage'
type: string
required: true
image_repo:
Expand Down Expand Up @@ -35,6 +39,21 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

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

- name: Build docker
uses: docker/build-push-action@v5
with:
context: .
file: docker/cell-test.Dockerfile
build-args: |
BUILD_IMAGE=${{ inputs.image_name_build }}
RUNTIME_IMAGE=${{ inputs.image_name_runtime }}
tags: cell_test
cache-from: type=gha
cache-to: type=gha,mode=min

- name: Run tests
run: |
docker run -v ${{ inputs.tests_dir }}:/tests/ ${{ inputs.image_repo }}/${{ inputs.image_name }} /bin/sh /tests/tests.sh
docker run -v ${{ inputs.tests_dir }}:/tests/ cell_test /bin/sh /tests/tests.sh
22 changes: 22 additions & 0 deletions docker/cell-test.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ARG BUILD_IMAGE
ARG RUNTIME_IMAGE

FROM ${BUILD_IMAGE} AS build
# When building actual cells, extra dependencies are installed here:
# COPY environment.yaml .
# RUN micromamba install -y -n venv -f environment.yaml
ARG MAMBA_DOCKERFILE_ACTIVATE=1
USER root
RUN conda-pack -p /opt/conda/envs/venv -o /tmp/env.tar && \
mkdir /venv && \
cd /venv && \
tar xf /tmp/env.tar && \
rm /tmp/env.tar
RUN /venv/bin/conda-unpack

FROM ${RUNTIME_IMAGE} AS runtime
COPY --from=build /venv /venv
WORKDIR /app
# When building actual cells, we copy files to the cell. In the tests, we use a
# volume mount
# COPY my-task-name.R .
6 changes: 6 additions & 0 deletions docker/naavre-cell-build.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM mambaorg/micromamba:1.5.6
RUN micromamba install -y -n base -c conda-forge conda-pack
ARG CONDA_ENV_FILE
COPY ${CONDA_ENV_FILE} environment.yaml
RUN micromamba create -y -f environment.yaml && \
micromamba clean --all --yes
1 change: 1 addition & 0 deletions docker/naavre-cell-runtime.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM ubuntu:24.04
18 changes: 0 additions & 18 deletions docker/naavre-cell.Dockerfile

This file was deleted.

0 comments on commit b03945d

Please sign in to comment.