From d1466a256d29a965eae6b8d98e4642ea05b0a678 Mon Sep 17 00:00:00 2001 From: Tasko Olevski Date: Wed, 27 Nov 2024 22:50:23 +0100 Subject: [PATCH] feat: add vscodium images for new amalthea (#478) --- .../workflows/build-and-push-to-docker.yml | 232 +++++++++++++++++- docker/py/entrypoint.sh | 3 +- docker/vscode/R.Dockerfile | 29 +++ docker/vscode/base.Dockerfile | 23 ++ docker/vscode/conda.Dockerfile | 29 +++ docker/vscode/entrypoint.sh | 12 + docker/vscode/poetry.Dockerfile | 26 ++ 7 files changed, 352 insertions(+), 2 deletions(-) create mode 100644 docker/vscode/R.Dockerfile create mode 100644 docker/vscode/base.Dockerfile create mode 100644 docker/vscode/conda.Dockerfile create mode 100644 docker/vscode/entrypoint.sh create mode 100644 docker/vscode/poetry.Dockerfile diff --git a/.github/workflows/build-and-push-to-docker.yml b/.github/workflows/build-and-push-to-docker.yml index 9c6c8ce0..43d72b9c 100644 --- a/.github/workflows/build-and-push-to-docker.yml +++ b/.github/workflows/build-and-push-to-docker.yml @@ -42,6 +42,10 @@ jobs: - docker/julia/Dockerfile - docker/batch/Dockerfile - docker/qgis/Dockerfile + - docker/vscode/base.Dockerfile + - docker/vscode/conda.Dockerfile + - docker/vscode/poetry.Dockerfile + - docker/vscode/R.Dockerfile runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -414,7 +418,7 @@ jobs: PYTHON_VERSION: "3.11" steps: - name: Docker Login - uses: Azure/docker-login@v1 + uses: docker/login-action@v3 with: username: ${{ secrets.RENKU_DOCKER_USERNAME }} password: ${{ secrets.RENKU_DOCKER_PASSWORD }} @@ -698,3 +702,229 @@ jobs: tags: ${{ steps.meta.outputs.tags }} cache-from: type=gha provenance: false + + build-vscode-base: + needs: lint + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + include: + - BASE_IMAGE: ubuntu:24.04 + BASE_IMAGE_TAG: ubuntu + LATEST: true + steps: + - name: Docker Login + uses: docker/login-action@v3 + with: + username: ${{ secrets.RENKU_DOCKER_USERNAME }} + password: ${{ secrets.RENKU_DOCKER_PASSWORD }} + - uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.2.0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.DOCKER_PREFIX }}-vscode + tags: | + type=sha,prefix=${{ matrix.BASE_IMAGE_TAG }}- + type=semver,pattern={{version}},prefix=${{ matrix.BASE_IMAGE_TAG }}- + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && matrix.LATEST }} + - name: Build and export + uses: docker/build-push-action@v6 + with: + build-args: | + BASE_IMAGE=${{ matrix.BASE_IMAGE }} + cache-from: type=gha + cache-to: type=gha,mode=max + context: docker/vscode + file: docker/vscode/base.Dockerfile + labels: ${{ steps.meta.outputs.labels }} + push: true + tags: ${{ steps.meta.outputs.tags }} + provenance: false + + build-vscode-conda: + needs: build-vscode-base + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + include: + - PYTHON_VERSION: 3.12.7 + BASE_IMAGE_TAG: ubuntu + LATEST: true + - PYTHON_VERSION: 3.11.10 + BASE_IMAGE_TAG: ubuntu + LATEST: false + - PYTHON_VERSION: 3.10.15 + BASE_IMAGE_TAG: ubuntu + LATEST: false + steps: + - name: Docker Login + uses: docker/login-action@v3 + with: + username: ${{ secrets.RENKU_DOCKER_USERNAME }} + password: ${{ secrets.RENKU_DOCKER_PASSWORD }} + - uses: actions/checkout@v4 + - name: Set outputs + id: vars + run: | + sha_short=$(git rev-parse --short HEAD) + echo "sha_short=$sha_short" >> $GITHUB_OUTPUT + echo "renku_base=${DOCKER_PREFIX}-vscode:${{ matrix.BASE_IMAGE_TAG }}-${sha_short}" >> $GITHUB_OUTPUT + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.2.0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.DOCKER_PREFIX }}-vscode-python + tags: | + type=sha,prefix=py-${{ matrix.PYTHON_VERSION }}- + type=semver,pattern={{version}},prefix=py-${{ matrix.PYTHON_VERSION }}- + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && matrix.LATEST }} + - name: Build and export + uses: docker/build-push-action@v6 + with: + build-args: | + BASE_IMAGE=${{ steps.vars.outputs.renku_base }} + cache-from: type=gha + cache-to: type=gha,mode=max + context: docker/vscode + file: docker/vscode/conda.Dockerfile + labels: ${{ steps.meta.outputs.labels }} + push: true + tags: ${{ steps.meta.outputs.tags }} + provenance: false + + build-vscode-poetry: + needs: build-vscode-base + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + include: + - PYTHON_VERSION: 3.12.7 + BASE_IMAGE_TAG: ubuntu + PYENV_VERSION: v2.4.17 + POETRY_VERSION: 1.8.4 + LATEST: true + - PYTHON_VERSION: 3.11.10 + BASE_IMAGE_TAG: ubuntu + PYENV_VERSION: v2.4.17 + POETRY_VERSION: 1.8.4 + LATEST: false + - PYTHON_VERSION: 3.10.15 + BASE_IMAGE_TAG: ubuntu + PYENV_VERSION: v2.4.17 + POETRY_VERSION: 1.8.4 + LATEST: false + steps: + - name: Docker Login + uses: docker/login-action@v3 + with: + username: ${{ secrets.RENKU_DOCKER_USERNAME }} + password: ${{ secrets.RENKU_DOCKER_PASSWORD }} + - uses: actions/checkout@v4 + - name: Set outputs + id: vars + run: | + sha_short=$(git rev-parse --short HEAD) + echo "sha_short=$sha_short" >> $GITHUB_OUTPUT + echo "renku_base=${DOCKER_PREFIX}-vscode:${{ matrix.BASE_IMAGE_TAG }}-${sha_short}" >> $GITHUB_OUTPUT + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.2.0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.DOCKER_PREFIX }}-vscode-poetry + tags: | + type=sha,prefix=py-${{ matrix.PYTHON_VERSION }}- + type=semver,pattern={{version}},prefix=py-${{ matrix.PYTHON_VERSION }}- + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && matrix.LATEST }} + - name: Build and export + uses: docker/build-push-action@v6 + with: + build-args: | + BASE_IMAGE=${{ steps.vars.outputs.renku_base }} + PYTHON_VERSION=${{ matrix.PYTHON_VERSION }} + POETRY_VERSION=${{ matrix.POETRY_VERSION }} + PYENV_VERSION=${{ matrix.PYENV_VERSION }} + cache-from: type=gha + cache-to: type=gha,mode=max + context: docker/vscode + file: docker/vscode/poetry.Dockerfile + labels: ${{ steps.meta.outputs.labels }} + push: true + tags: ${{ steps.meta.outputs.tags }} + provenance: false + + build-vscode-r: + needs: build-vscode-base + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + include: + - R_VERSION: 4.4.2 + BASE_IMAGE_TAG: ubuntu + LATEST: true + - R_VERSION: 4.3.3 + BASE_IMAGE_TAG: ubuntu + LATEST: false + - R_VERSION: 4.2.3 + BASE_IMAGE_TAG: ubuntu + LATEST: false + steps: + - name: Docker Login + uses: docker/login-action@v3 + with: + username: ${{ secrets.RENKU_DOCKER_USERNAME }} + password: ${{ secrets.RENKU_DOCKER_PASSWORD }} + - uses: actions/checkout@v4 + - name: Set outputs + id: vars + run: | + sha_short=$(git rev-parse --short HEAD) + echo "sha_short=$sha_short" >> $GITHUB_OUTPUT + echo "renku_base=${DOCKER_PREFIX}-vscode:${{ matrix.BASE_IMAGE_TAG }}-${sha_short}" >> $GITHUB_OUTPUT + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.2.0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.DOCKER_PREFIX }}-vscode-r + tags: | + type=sha,prefix=r-${{ matrix.R_VERSION }}- + type=semver,pattern={{version}},prefix=r-${{ matrix.R_VERSION }}- + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && matrix.LATEST }} + - name: Build and export + uses: docker/build-push-action@v6 + with: + build-args: | + BASE_IMAGE=${{ steps.vars.outputs.renku_base }} + R_VERSION=${{ matrix.R_VERSION }} + cache-from: type=gha + cache-to: type=gha,mode=max + context: docker/vscode + file: docker/vscode/R.Dockerfile + labels: ${{ steps.meta.outputs.labels }} + push: true + tags: ${{ steps.meta.outputs.tags }} + provenance: false diff --git a/docker/py/entrypoint.sh b/docker/py/entrypoint.sh index e784f343..7c8e3da3 100755 --- a/docker/py/entrypoint.sh +++ b/docker/py/entrypoint.sh @@ -57,7 +57,8 @@ jupyter() { if [[ -v RENKU_BASE_URL_PATH ]]; then "$@" --ServerApp.port=8888 --ServerApp.base_url="$RENKU_BASE_URL_PATH" \ --ServerApp.token="" --ServerApp.password="" --ServerApp.allow_remote_access=true \ - --ContentsManager.allow_hidden=true --ServerApp.allow_origin=* + --ContentsManager.allow_hidden=true --ServerApp.allow_origin=* \ + --ServerApp.root_dir="${HOME}/work" fi # run the command diff --git a/docker/vscode/R.Dockerfile b/docker/vscode/R.Dockerfile new file mode 100644 index 00000000..6e4afdef --- /dev/null +++ b/docker/vscode/R.Dockerfile @@ -0,0 +1,29 @@ +ARG BASE_IMAGE=renku/renkulab-vscode:latest +FROM $BASE_IMAGE +ARG R_VERSION=4.4.2 +ARG SESSION_USER=vscode +ARG WORKDIR=/home/${SESSION_USER} +ARG MOUNTDIR=${WORKDIR}/work + +SHELL [ "/bin/bash", "-c", "-o", "pipefail" ] +USER root +# From https://docs.posit.co/resources/install-r.html +RUN curl -O https://cdn.rstudio.com/r/ubuntu-2404/pkgs/r-${R_VERSION}_1_amd64.deb \ + && apt-get update \ + && apt-get install -y --no-install-recommends ./r-${R_VERSION}_1_amd64.deb \ + && rm -rf /var/lib/apt/lists/* \ + && rm -rf ./r-${R_VERSION}_1_amd64.deb \ + && ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R \ + && ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript + +USER ${SESSION_USER} +ENV __MOUNTDIR__=${MOUNTDIR} +WORKDIR ${WORKDIR} +# The .Renviron changes allow R to install packages in the work directory +# See https://www.r-bloggers.com/2020/10/customizing-your-package-library-location/ +# The .Rprofile changes allow R to be able to use precompiled packages +# See https://packagemanager.posit.co/client/#/repos/cran/setup +RUN printf "\nR_LIBS_SITE=\"%s/.rlibs\"\n" "${MOUNTDIR}" >> /home/${SESSION_USER}/.Renviron \ + && printf "\noptions(repos = c(CRAN = \"https://packagemanager.posit.co/cran/__linux__/noble/latest\"))\n" >> /home/${SESSION_USER}/.Rprofile +ENTRYPOINT ["tini", "--", "sh", "-c"] +CMD ["mkdir -p ${__MOUNTDIR__}/.rlibs && bash /entrypoint.sh"] diff --git a/docker/vscode/base.Dockerfile b/docker/vscode/base.Dockerfile new file mode 100644 index 00000000..d5de0707 --- /dev/null +++ b/docker/vscode/base.Dockerfile @@ -0,0 +1,23 @@ +ARG BASE_IMAGE=ubuntu:24.04 +FROM $BASE_IMAGE +ARG VSCODIUM_VERSION=1.95.2.24313 +ARG SESSION_USER=vscode +ARG WORKDIR=/home/${SESSION_USER} +ARG MOUNTDIR=${WORKDIR}/work +SHELL [ "/bin/bash", "-c", "-o", "pipefail" ] +RUN apt-get update && \ + apt-get install -y --no-install-recommends ca-certificates curl tini build-essential git git-lfs && \ + mkdir -p /codium-server && \ + curl -L https://github.com/VSCodium/vscodium/releases/download/${VSCODIUM_VERSION}/vscodium-reh-web-linux-x64-${VSCODIUM_VERSION}.tar.gz | tar -xz -C /codium-server && \ + rm -rf /var/lib/apt/lists/* +RUN useradd -m -s /bin/bash ${SESSION_USER} +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +USER ${SESSION_USER} +COPY entrypoint.sh /entrypoint.sh +WORKDIR ${WORKDIR} +# We are setting this to a weird double underscore name to avoid collisions with user-set vars +ENV __MOUNTDIR__=${MOUNTDIR} +RUN mkdir -p ${MOUNTDIR} +ENTRYPOINT ["tini", "--", "/bin/bash", "/entrypoint.sh"] diff --git a/docker/vscode/conda.Dockerfile b/docker/vscode/conda.Dockerfile new file mode 100644 index 00000000..5e6b595d --- /dev/null +++ b/docker/vscode/conda.Dockerfile @@ -0,0 +1,29 @@ +ARG BASE_IMAGE=renku/renkulab-vscode:latest +FROM $BASE_IMAGE +ARG MICROMAMBA_VERSION=2.0.2-2 +ARG MAMBA_VERSION=1.5.9 +ARG CONDA_VERSION=24.9.2 +ARG PYTHON_VERSION=3.12.7 +ARG OS=linux +ARG ARCH=64 +ARG SESSION_USER=vscode +ARG WORKDIR=/home/${SESSION_USER} +ARG MOUNTDIR=${WORKDIR}/work +ARG VENVS_PATH=${MOUNTDIR}/.venvs +ENV __VENVS_PATH__=${VENVS_PATH} +ENV __PYTHON_VERSION__=${PYTHON_VERSION} +ENV __MAMBA_VERSION__=${MAMBA_VERSION} +ENV __CONDA_VERSION__=${CONDA_VERSION} +SHELL [ "/bin/bash", "-c", "-o", "pipefail" ] +USER root +RUN apt-get update && \ + apt-get install -y curl --no-install-recommends && \ + curl -L "https://github.com/mamba-org/micromamba-releases/releases/download/${MICROMAMBA_VERSION}/micromamba-${OS}-${ARCH}" -o /usr/local/bin/micromamba && \ + chmod a+x /usr/local/bin/micromamba && \ + rm -rf /var/lib/apt/lists/* + +USER ${SESSION_USER} +WORKDIR ${WORKDIR} +ENV __MOUNTDIR__=${MOUNTDIR} +ENTRYPOINT ["tini", "--", "sh", "-c"] +CMD ["set -ex && micromamba install --yes --root-prefix=${__VENVS_PATH__} --prefix=${__VENVS_PATH__} python=${__PYTHON_VERSION__} mamba=${__MAMBA_VERSION__} conda=${__CONDA_VERSION__} && ${__VENVS_PATH__}/bin/mamba init && ${__VENVS_PATH__}/bin/conda config --add channels conda-forge && ${__VENVS_PATH__}/bin/conda config --set channel_priority strict && ${__VENVS_PATH__}/bin/conda config --remove channels defaults && bash /entrypoint.sh"] diff --git a/docker/vscode/entrypoint.sh b/docker/vscode/entrypoint.sh new file mode 100644 index 00000000..2d3d9bb9 --- /dev/null +++ b/docker/vscode/entrypoint.sh @@ -0,0 +1,12 @@ +set -ex +MOUNTDIR=${__MOUNTDIR__} +mkdir -p "${MOUNTDIR}/.vscode/extensions" +/codium-server/bin/codium-server \ + --server-base-path "$RENKU_BASE_URL_PATH/" \ + --without-connection-token \ + --host 0.0.0.0 \ + --port 8888 \ + --extensions-dir "${MOUNTDIR}/.vscode/extensions" \ + --accept-server-license-terms \ + --telemetry-level off \ + --server-data-dir "${MOUNTDIR}/.vscode" diff --git a/docker/vscode/poetry.Dockerfile b/docker/vscode/poetry.Dockerfile new file mode 100644 index 00000000..07935fee --- /dev/null +++ b/docker/vscode/poetry.Dockerfile @@ -0,0 +1,26 @@ +ARG BASE_IMAGE=renku/renkulab-vscode:latest +FROM $BASE_IMAGE +ARG PYENV_VERSION=v2.4.17 +ARG PYTHON_VERSION=3.12.7 +# Empty string for poetry version means the latest version +ARG POETRY_VERSION="" +ARG SESSION_USER=vscode +ARG WORKDIR=/home/${SESSION_USER} +ARG MOUNTDIR=${WORKDIR}/work +ARG VENVS_PATH=${MOUNTDIR}/.venvs +SHELL [ "/bin/bash", "-c", "-o", "pipefail" ] +USER root +RUN apt-get update && \ + apt-get install -y --no-install-recommends curl libz-dev libreadline-dev libncurses-dev libsqlite3-dev libssl-dev liblzma-dev libgdbm-dev libbz2-dev libffi-dev && \ + mkdir -p /python-build && \ + curl -L https://github.com/pyenv/pyenv/archive/refs/tags/${PYENV_VERSION}.tar.gz | tar -xz -C /python-build && \ + /bin/sh /python-build/*/plugins/python-build/install.sh && \ + python-build ${PYTHON_VERSION} /usr/local && \ + rm -rf /python-build && \ + rm -rf /var/lib/apt/lists/* + +USER ${SESSION_USER} +ENV __MOUNTDIR__=${MOUNTDIR} +RUN curl -sSL https://install.python-poetry.org | python3 - --version=${POETRY_VERSION} && \ + /home/${SESSION_USER}/.local/bin/poetry config virtualenvs.path ${VENVS_PATH} +WORKDIR ${WORKDIR}