diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8a8ca498e455c0438e97de5f1e154fdcb44af2fd..671c7468721627b8930aef457265056c3ac861cc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,21 +9,72 @@ build: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - docker --version - # pull the latest build on master - - docker pull "$CI_REGISTRY_IMAGE/master:latest" || true - # pull the latest build on this branch + # put both versions in a env var, to be used as tag + - | + if [ "latest" == "${R_VERSION}" ]; then + export VERSIONS_TAG="${SHINY_SERVER_VERSION}" + else + if [ "latest" == "${SHINY_SERVER_VERSION}" ]; then + export VERSIONS_TAG="${R_VERSION}" + else + export VERSIONS_TAG="${R_VERSION}--${SHINY_SERVER_VERSION}" + fi + fi + # pull the latest build + - docker pull "$CI_REGISTRY_IMAGE:latest" || true + # pull the latest build of the targeted versions + - docker pull "$CI_REGISTRY_IMAGE:$VERSIONS_TAG" || true + # pull the latest build of the target R version in order to re-use it for the targeted SHINY_SERVER_VERSION + - docker pull "$CI_REGISTRY_IMAGE:$R_VERSION" || true + # pull the latest build of main + - docker pull "$CI_REGISTRY_IMAGE/main:latest" || true + # pull the latest build of this branch - docker pull "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:latest" || true - # build the image while passing commit SHA and tagging the image with it + # build the image while passing commit SHA and versions, and tagging the image with them - docker build - --build-arg CI_COMMIT_REF_SLUG - --build-arg CI_COMMIT_SHA + --build-arg R_VERSION + --build-arg SHINY_SERVER_VERSION --cache-from "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:latest" - --cache-from "$CI_REGISTRY_IMAGE/master:latest" + --cache-from "$CI_REGISTRY_IMAGE/main:latest" + --cache-from "$CI_REGISTRY_IMAGE:$VERSIONS_TAG" + --cache-from "$CI_REGISTRY_IMAGE:$R_VERSION" + --cache-from "$CI_REGISTRY_IMAGE:latest" --tag "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA" --tag "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:latest" + --tag "$CI_REGISTRY_IMAGE:$VERSIONS_TAG" + --tag "$CI_REGISTRY_IMAGE:$VERSIONS_TAG--$CI_COMMIT_SHORT_SHA" -f Dockerfile ./ # push image as latest for the current branch - docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:latest" # push image tagged with its sha - docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA" + # push image tagged with its versions + - docker push "$CI_REGISTRY_IMAGE:$VERSIONS_TAG" + # push image tagged with its versions and the commit sha (debug purpose) + - docker push "$CI_REGISTRY_IMAGE:$VERSIONS_TAG--$CI_COMMIT_SHORT_SHA" + parallel: + matrix: + - R_VERSION: ["3.6.3", "4.2.3", "latest"] + SHINY_SERVER_VERSION: ["latest"] + + +build-example: + stage: build + needs: ["build"] + before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + script: + # pull the latest example of rshiny-k8s image + - docker pull "$CI_REGISTRY_IMAGE/example:example" || true + # build the image while passing commit SHA and versions, and tagging the image with them + - docker build + --cache-from "$CI_REGISTRY_IMAGE/example:latest" + --tag "$CI_REGISTRY_IMAGE/example:latest" + --tag "$CI_REGISTRY_IMAGE/example:$CI_COMMIT_SHORT_SHA" + -f example.Dockerfile + ./ + # push image tagged as example + - docker push "$CI_REGISTRY_IMAGE/example:latest" + # push image tagged as example with its commit sha (debug purpose) + - docker push "$CI_REGISTRY_IMAGE/example:$CI_COMMIT_SHORT_SHA" diff --git a/Dockerfile b/Dockerfile index 34874c517ed35edd22799324d26fe24d1516bad3..b2eab070ba03c9d5456378d03ccc688f55c4ed8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,8 @@ FROM ubuntu:focal # define geographic location during R installation ENV TZ=Etc/UTC ENV DEBIAN_FRONTEND noninteractive -ARG SHINY_SERVER_VERSION +ARG SHINY_SERVER_VERSION=latest +ARG R_VERSION=latest EXPOSE 3838 CMD ["shiny-server"] @@ -14,15 +15,30 @@ RUN apt-get update \ nano \ wget \ curl \ - r-base \ - r-base-dev \ - r-recommended \ lsb-release \ - && rm -rf /var/lib/apt/lists/* \ - && R --version + libcurl4-openssl-dev \ + gcc \ + gfortran \ + g++ \ + libreadline-dev \ + zlib1g-dev \ + libbz2-dev \ + liblzma-dev \ + libpcre2-dev \ + libcairo-dev \ + libpng-dev \ + libicu-dev \ + make \ + libtiff-dev \ + && rm -rf /var/lib/apt/lists/* COPY ./scripts /opt/scripts +#install R, along with its dependencies +RUN /opt/scripts/install_r_cran.sh +# test R in another layer +RUN R -q -e "sessionInfo()" + # Install R packages included Shiny, then install shiny server RUN Rscript /opt/scripts/install_r_packages.R RUN /opt/scripts/install_shiny_server.sh @@ -30,9 +46,6 @@ RUN /opt/scripts/install_shiny_server.sh # allows trafic from all ips RUN sed -i "s/3838/3838 0.0.0.0/g" /etc/shiny-server/shiny-server.conf -# copy my shiny app. -COPY ./example_proj /srv/shiny-server - #RUN chown shiny:shiny /var/lib/shiny-server RUN mkdir -p /var/log/shiny-server \ && chown shiny:shiny /var/log/shiny-server diff --git a/example-in-pod.yaml b/example-in-pod.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c2b5ddccd149a8cc43e10d4038a46de9d4eecb04 --- /dev/null +++ b/example-in-pod.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: example +spec: + containers: + - name: example + image: registry-gitlab.pasteur.fr/hub/rshiny-k8s/example:latest + securityContext: + runAsGroup: 999 + runAsUser: 999 + ports: + - name: http + containerPort: 3838 + protocol: TCP diff --git a/example.Dockerfile b/example.Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..260e5d9c94a7e566e310f578ab417e4c22b80624 --- /dev/null +++ b/example.Dockerfile @@ -0,0 +1,14 @@ +# FROM registry-gitlab.pasteur.fr/hub/rshiny-k8s:4.2.3--1.5.21.1006 +# FROM registry-gitlab.pasteur.fr/hub/rshiny-k8s:1.5.21.1006 +# FROM registry-gitlab.pasteur.fr/hub/rshiny-k8s:4.2.3 +FROM registry-gitlab.pasteur.fr/hub/rshiny-k8s:latest + +# Copy your dependencies, destination filename must be "packages_to_install.csv" +COPY ./example_proj/my_packages_to_install.csv /opt/scripts/packages_to_install.csv + +# Install R packages +RUN Rscript /opt/scripts/install_r_packages.R + +# Copy you shiny app +COPY ./example_proj /srv/shiny-server + diff --git a/example_proj/my_packages_to_install.csv b/example_proj/my_packages_to_install.csv new file mode 100644 index 0000000000000000000000000000000000000000..9b60e0aa8985400b189e2b5fccb293a054fa985d --- /dev/null +++ b/example_proj/my_packages_to_install.csv @@ -0,0 +1,3 @@ +Package_name;Deposit_name +shiny;cran +shinythemes;cran diff --git a/scripts/install_r_cran.sh b/scripts/install_r_cran.sh new file mode 100755 index 0000000000000000000000000000000000000000..5727b358eb77fafae56bb5bd1dc67f661f7013e0 --- /dev/null +++ b/scripts/install_r_cran.sh @@ -0,0 +1,50 @@ +#!/bin/bash +set -e + +R_VERSION=${1:-${R_VERSION:-latest}} +R_HOME=${R_HOME:-"/usr/local/lib/R"} +CRAN="https://cran.r-project.org" + +cd /tmp + +if [ ! -f "R-${R_VERSION}.tar.gz" ]; then + echo "/tmp/R-${R_VERSION}.tar.gz is missing, downloading it" + if [ "$R_VERSION" = "latest" ]; then + curl -O https://cran.r-project.org/src/base/R-latest.tar.gz + else + curl -O https://cran.rstudio.com/src/base/R-${R_VERSION::1}/R-${R_VERSION}.tar.gz + fi +fi +tar -xzvf R-${R_VERSION}.tar.gz + +# go in uncompressed dir, when using R_VERSION="R-latest", +# the dir is not R-latest, but the one with the version +cd R-*/ +# Configure the sources, check dependencies +./configure \ + --enable-R-shlib \ + --enable-memory-profiling \ + --with-blas \ + --with-lapack \ + --with-x=no \ + --with-cairo=yes \ + --enable-java=no + +make +make install + +echo "Install completed, testing R" + +R -q -e "sessionInfo()" || exit 1 + +echo "R found in path, good to go!" + +make clean +rm /tmp/R-${R_VERSION}.tar.gz + +cat <<EOF >"${R_HOME}/etc/Rprofile.site" +options( + repos = c( CRAN = '${CRAN}'), + download.file.method = 'libcurl' +) +EOF