From 955e1dabfb2fca67c6f1facd90b221d0fcbf17f7 Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Thu, 5 Apr 2018 08:59:27 -0600 Subject: [PATCH 01/17] Create python package in docker --- .gitignore | 9 ++++---- Makefile | 55 ++++++++++++++++++++++++++++++++++++++++++------- docker.sh | 26 +++++++++++++++++++++++ notebooks/.keep | 0 4 files changed, 78 insertions(+), 12 deletions(-) create mode 100755 docker.sh create mode 100644 notebooks/.keep diff --git a/.gitignore b/.gitignore index e5471859..40b89258 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,10 @@ -# Compiled python modules. *.pyc - -# Setuptools distribution folder. /build/ /dist/ - -# Python egg metadata, regenerated from source files by setuptools. +/.conda/ +/.jupyter/ +/.local/ +/node_modules/ /*.egg-info /*.egg /*.eggs diff --git a/Makefile b/Makefile index 3c34c06b..1e7f42cb 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,63 @@ -.PHONY: test dist develop-setup develop +.PHONY: pull launch notebook2 notebook3 package dist test dist develop run +DOCKER_USER=$(shell id -nu) +DOCKER_UID=jenkins +DOCKER_GID=jenkins +ifeq (Linux,$(shell uname)) + DOCKER_UID=$(shell id -u) + DOCKER_GID=$(shell id -g) +endif + +PY3=continuumio/miniconda3:4.4.10 +PY2=continuumio/miniconda:4.4.10 + +pull: + docker pull $(PY3) + docker pull $(PY2) +# docker pull python:2.7 +# docker pull python:3.6 + docker pull node:6-slim + +launch: + docker run --rm -i -t \ + -v $(CURDIR)/notebooks:/notebooks \ + -v $(CURDIR):/rsconnect \ + -e NB_UID=${DOCKER_UID} \ + -e NB_GID=${DOCKER_GID} \ + -e NB_USER=${DOCKER_USER} \ + -p :9999:9999 \ + $(DOCKER_IMAGE) \ + /rsconnect/docker.sh $(TARGET) + + +notebook2: + make DOCKER_IMAGE=$(PY2) TARGET=run launch + +notebook3: + make DOCKER_IMAGE=$(PY3) TARGET=run launch test: +# TODO run in container python setup.py test dist: -# build egg - python setup.py sdist -# build wheel - # wheels don't get built if _any_ file it tries to touch has a timestamp < 1980 # (system files) so use the current timestamp as a point of reference instead SOURCE_DATE_EPOCH="$(shell date +%s)"; python setup.py bdist_wheel -develop-setup: - python setup.py develop +package: + make DOCKER_IMAGE=$(PY3) TARGET=dist launch develop: +# link python package + python setup.py develop +# install rsconnect as a jupyter extension jupyter-nbextension install --symlink --user --py rsconnect +# enable js extension jupyter-nbextension enable --py rsconnect +# enable python extension jupyter-serverextension enable --py rsconnect + +run: develop +# start notebook + jupyter-notebook -y --notebook-dir=/notebooks --ip='*' --port=9999 --no-browser diff --git a/docker.sh b/docker.sh new file mode 100755 index 00000000..d515cb08 --- /dev/null +++ b/docker.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -e +set -o pipefail + +if [[ $(id -u) == "0" ]]; +then + apt-get update -qq + apt-get install -y make + useradd --password password --no-create-home --home-dir /rsconnect --uid "$NB_UID" --gid "$NB_GID" "$NB_USER" + su -l -c "$0 $@" "$NB_USER" + exit $? +fi + +export PATH=/opt/conda/bin:$PATH + +if [[ $(conda env list | grep py3 | wc -l) == "1" ]]; +then + echo Environment already exists +else + # install jupyter into a new environment + conda create --yes --name py3 jupyter +fi +source activate py3 + +make -f /rsconnect/Makefile $1 diff --git a/notebooks/.keep b/notebooks/.keep new file mode 100644 index 00000000..e69de29b From 063e38babfd47b351a91aac84b87cdb389c3aa2c Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Thu, 5 Apr 2018 09:13:20 -0600 Subject: [PATCH 02/17] Utilize separate envs --- Makefile | 5 ++++- docker.sh | 13 +++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 1e7f42cb..f88fc1a4 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,8 @@ endif PY3=continuumio/miniconda3:4.4.10 PY2=continuumio/miniconda:4.4.10 +PY_VERSION=3 + pull: docker pull $(PY3) docker pull $(PY2) @@ -25,13 +27,14 @@ launch: -e NB_UID=${DOCKER_UID} \ -e NB_GID=${DOCKER_GID} \ -e NB_USER=${DOCKER_USER} \ + -e PY_VERSION=${PY_VERSION} \ -p :9999:9999 \ $(DOCKER_IMAGE) \ /rsconnect/docker.sh $(TARGET) notebook2: - make DOCKER_IMAGE=$(PY2) TARGET=run launch + make DOCKER_IMAGE=$(PY2) PY_VERSION=2 TARGET=run launch notebook3: make DOCKER_IMAGE=$(PY3) TARGET=run launch diff --git a/docker.sh b/docker.sh index d515cb08..89afaaca 100755 --- a/docker.sh +++ b/docker.sh @@ -8,19 +8,24 @@ then apt-get update -qq apt-get install -y make useradd --password password --no-create-home --home-dir /rsconnect --uid "$NB_UID" --gid "$NB_GID" "$NB_USER" - su -l -c "$0 $@" "$NB_USER" + su -c "$0 $@" "$NB_USER" exit $? fi +cd /rsconnect + +PYENV="py${PY_VERSION}" + export PATH=/opt/conda/bin:$PATH -if [[ $(conda env list | grep py3 | wc -l) == "1" ]]; +if [[ $(conda env list | grep "$PYENV" | wc -l) == "1" ]]; then echo Environment already exists else # install jupyter into a new environment - conda create --yes --name py3 jupyter + conda create --yes --name "$PYENV" jupyter fi -source activate py3 + +source activate "$PYENV" make -f /rsconnect/Makefile $1 From f49d4db839dac94f699558b30ce01e964b6315c1 Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Thu, 5 Apr 2018 15:18:53 -0600 Subject: [PATCH 03/17] Create docker images --- Dockerfile | 20 ++++++++++ Makefile | 66 ++++++++++++++++++++------------- docker.sh | 31 ---------------- {notebooks => notebooks2}/.keep | 0 notebooks3/.keep | 0 5 files changed, 61 insertions(+), 56 deletions(-) create mode 100644 Dockerfile delete mode 100755 docker.sh rename {notebooks => notebooks2}/.keep (100%) create mode 100644 notebooks3/.keep diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..33692562 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +ARG BASE_IMAGE +FROM ${BASE_IMAGE} +LABEL maintainer="RStudio Connect " + +ARG NB_USER +ARG NB_UID +ARG NB_GID +ARG PY_VERSION +RUN apt-get update -qq +RUN apt-get install -y make +RUN useradd --password password \ + --create-home \ + --home-dir /home/${NB_USER} \ + --uid ${NB_UID} \ + --gid ${NB_GID} \ + ${NB_USER} + +USER ${NB_UID}:${NB_GID} +WORKDIR /home/${NB_USER} +RUN conda create --yes --name py${PY_VERSION} jupyter diff --git a/Makefile b/Makefile index f88fc1a4..540f865e 100644 --- a/Makefile +++ b/Makefile @@ -1,43 +1,61 @@ -.PHONY: pull launch notebook2 notebook3 package dist test dist develop run +.PHONY: pull build-image image2 image3 launch notebook2 notebook3 package dist test dist run -DOCKER_USER=$(shell id -nu) -DOCKER_UID=jenkins -DOCKER_GID=jenkins -ifeq (Linux,$(shell uname)) - DOCKER_UID=$(shell id -u) - DOCKER_GID=$(shell id -g) -endif +NB_USER=$(shell id -nu) +NB_UID=$(shell id -u) +NB_GID=$(shell id -g) -PY3=continuumio/miniconda3:4.4.10 -PY2=continuumio/miniconda:4.4.10 - -PY_VERSION=3 +PY2=rstudio/rsconnect-jupyter-py2 +PY3=rstudio/rsconnect-jupyter-py3 pull: - docker pull $(PY3) - docker pull $(PY2) +# docker pull $(PY3) +# docker pull $(PY2) # docker pull python:2.7 # docker pull python:3.6 docker pull node:6-slim +build-image: image2 image3 + +image2: + docker build \ + --tag $(PY2) \ + --file Dockerfile \ + --build-arg BASE_IMAGE=continuumio/miniconda:4.4.10 \ + --build-arg NB_UID=$(NB_UID) \ + --build-arg NB_GID=$(NB_GID) \ + --build-arg NB_USER=$(NB_USER) \ + --build-arg PY_VERSION=2 \ + . + +image3: + docker build \ + --tag $(PY3) \ + --file Dockerfile \ + --build-arg BASE_IMAGE=continuumio/miniconda3:4.4.10 \ + --build-arg NB_UID=$(NB_UID) \ + --build-arg NB_GID=$(NB_GID) \ + --build-arg NB_USER=$(NB_USER) \ + --build-arg PY_VERSION=3 \ + . + launch: docker run --rm -i -t \ - -v $(CURDIR)/notebooks:/notebooks \ + -v $(CURDIR)/notebooks$(PY_VERSION):/notebooks \ -v $(CURDIR):/rsconnect \ - -e NB_UID=${DOCKER_UID} \ - -e NB_GID=${DOCKER_GID} \ - -e NB_USER=${DOCKER_USER} \ - -e PY_VERSION=${PY_VERSION} \ + -e NB_UID=$(NB_UID) \ + -e NB_GID=$(NB_GID) \ + -e NB_USER=$(NB_USER) \ + -e PY_VERSION=$(PY_VERSION) \ -p :9999:9999 \ $(DOCKER_IMAGE) \ - /rsconnect/docker.sh $(TARGET) + /rsconnect/run.sh $(TARGET) notebook2: make DOCKER_IMAGE=$(PY2) PY_VERSION=2 TARGET=run launch notebook3: - make DOCKER_IMAGE=$(PY3) TARGET=run launch + make DOCKER_IMAGE=$(PY3) PY_VERSION=3 TARGET=run launch test: # TODO run in container @@ -49,9 +67,9 @@ dist: SOURCE_DATE_EPOCH="$(shell date +%s)"; python setup.py bdist_wheel package: - make DOCKER_IMAGE=$(PY3) TARGET=dist launch + make DOCKER_IMAGE=$(PY3) PY_VERSION=3 TARGET=dist launch -develop: +run: develop # link python package python setup.py develop # install rsconnect as a jupyter extension @@ -60,7 +78,5 @@ develop: jupyter-nbextension enable --py rsconnect # enable python extension jupyter-serverextension enable --py rsconnect - -run: develop # start notebook jupyter-notebook -y --notebook-dir=/notebooks --ip='*' --port=9999 --no-browser diff --git a/docker.sh b/docker.sh deleted file mode 100755 index 89afaaca..00000000 --- a/docker.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -o pipefail - -if [[ $(id -u) == "0" ]]; -then - apt-get update -qq - apt-get install -y make - useradd --password password --no-create-home --home-dir /rsconnect --uid "$NB_UID" --gid "$NB_GID" "$NB_USER" - su -c "$0 $@" "$NB_USER" - exit $? -fi - -cd /rsconnect - -PYENV="py${PY_VERSION}" - -export PATH=/opt/conda/bin:$PATH - -if [[ $(conda env list | grep "$PYENV" | wc -l) == "1" ]]; -then - echo Environment already exists -else - # install jupyter into a new environment - conda create --yes --name "$PYENV" jupyter -fi - -source activate "$PYENV" - -make -f /rsconnect/Makefile $1 diff --git a/notebooks/.keep b/notebooks2/.keep similarity index 100% rename from notebooks/.keep rename to notebooks2/.keep diff --git a/notebooks3/.keep b/notebooks3/.keep new file mode 100644 index 00000000..e69de29b From c5be23279f1db9d7dd761b45c7425e33c650ab83 Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Thu, 5 Apr 2018 15:19:07 -0600 Subject: [PATCH 04/17] Forgot a file --- run.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 run.sh diff --git a/run.sh b/run.sh new file mode 100755 index 00000000..a1833f74 --- /dev/null +++ b/run.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -e +set -o pipefail + +if [[ $(id -u) == "0" ]]; +then + su -c "$0 $@" "$NB_USER" + exit $? +fi + +cd /rsconnect +export PATH=/opt/conda/bin:$PATH +source activate "py${PY_VERSION}" +make -f /rsconnect/Makefile $1 From 67b1f3b26569ee91800402d732fc32d23ba923ea Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Thu, 5 Apr 2018 15:30:08 -0600 Subject: [PATCH 05/17] Add some instructions --- Makefile | 4 ++-- README.md | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 540f865e..294b6774 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: pull build-image image2 image3 launch notebook2 notebook3 package dist test dist run +.PHONY: pull images image2 image3 launch notebook2 notebook3 package dist test dist run NB_USER=$(shell id -nu) NB_UID=$(shell id -u) @@ -14,7 +14,7 @@ pull: # docker pull python:3.6 docker pull node:6-slim -build-image: image2 image3 +images: image2 image3 image2: docker build \ diff --git a/README.md b/README.md index 1333ed77..e1039bf7 100644 --- a/README.md +++ b/README.md @@ -1 +1,24 @@ -TODO +# Development + +Need to run this after checkout and when modifying the docker images + + make images + +Launch jupyter in a python 2 environment + + make notebook2 + +Launch jupyter in a python 3 environment + + make notebook3 + + +> Note: notebooks in the `notebooks2` and `notebooks3` directories will be +> available in respective python environments. + +# Packaging + +The following will create a universal [wheel](https://pythonwheels.com/) ready +to be installed in any python 2 or python 3 environment. + + make package From 6ab5efa5fb6bd9cde0f9731e738db3c2a2a221ad Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Thu, 5 Apr 2018 15:32:44 -0600 Subject: [PATCH 06/17] Add note for code changes --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1039bf7..233c18ab 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,16 @@ Launch jupyter in a python 3 environment make notebook3 - > Note: notebooks in the `notebooks2` and `notebooks3` directories will be > available in respective python environments. +## Seeing code changes + +When modifying JavaScript files simply refresh the browser window to see +changes. + +When modifying Python files restart the jupyter process to see changes. + # Packaging The following will create a universal [wheel](https://pythonwheels.com/) ready From 446481aba12e04090f80a9ca18f69af04dc00450 Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Thu, 5 Apr 2018 15:36:56 -0600 Subject: [PATCH 07/17] Add clean target --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 294b6774..ad96e200 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: pull images image2 image3 launch notebook2 notebook3 package dist test dist run +.PHONY: clean pull images image2 image3 launch notebook2 notebook3 package dist test dist run NB_USER=$(shell id -nu) NB_UID=$(shell id -u) @@ -7,6 +7,9 @@ NB_GID=$(shell id -g) PY2=rstudio/rsconnect-jupyter-py2 PY3=rstudio/rsconnect-jupyter-py3 +clean: + rm -rf build/ dist/ rsconnect.egg-info/ + pull: # docker pull $(PY3) # docker pull $(PY2) @@ -69,7 +72,7 @@ dist: package: make DOCKER_IMAGE=$(PY3) PY_VERSION=3 TARGET=dist launch -run: develop +run: # link python package python setup.py develop # install rsconnect as a jupyter extension From e0c8e83a24d506e3250161ed8bd768c8aa0dcec4 Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Thu, 5 Apr 2018 16:06:46 -0600 Subject: [PATCH 08/17] Add Jenkinsfile --- Jenkinsfile | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..f10b34d8 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,114 @@ +#!groovy + +def gitClean() { + // inspired by: https://issues.jenkins-ci.org/browse/JENKINS-31924 + // https://issues.jenkins-ci.org/browse/JENKINS-32540 + // The sequence of reset --hard and clean -fdx first + // in the root and then using submodule foreach + // is based on how the Jenkins Git SCM clean before checkout + // feature works. + sh 'git reset --hard' + sh 'git clean -ffdx' +} + +// Build the name:tag for a docker image where the tag is the checksum +// computed from a specified file. +def imageName(name, filenames) { + // If this is extended to support multiple files, be wary of: + // https://issues.jenkins-ci.org/browse/JENKINS-26481 + // closures don't really work. + + // Suck in the contents of the file and then hash the result. + def contents = ""; + for (int i=0; i" + + // Looking up the author also demands being in a `node`. + gitAuthor = sh(returnStdout: true, script: 'git --no-pager show -s --format="%aN" HEAD').trim() + + def selenium + stage('prepare environment') { + selenium = pullBuildPush( + image_name: 'jenkins/rsconnect-jupyter', + image_tag: 'python3', + docker_context: './', + build_arg_NB_UID: 'JENKINS_UID', + build_arg_NB_GID: 'JENKINS_GID', + build_arg_NB_USER: 'jenkins', + build_arg_PY_VERSION: '3', + build_arg_BASE_IMAGE: 'continuumio/miniconda3:4.4.10', + push: !isUserBranch) + } + + try { + stage('package') { + print "building python wheel package from build ${TRIGGERING_BUILD_NUMBER}" + sh 'make package' + archiveArtifacts artifacts: 'dist/*.whl' + } + } + } + + // Slack message includes username information. + message = "${messagePrefix} by ${gitAuthor} passed" + slackSend channel: slackChannelPass, color: 'good', message: message +} catch(err) { + // Slack message includes username information. When master/release fails, + // CC the whole connect team. + slackNameFail = "unknown" + if (!isUserBranch) { + slackNameFail = "${gitAuthor} (cc @kenny)" + } + + message = "${messagePrefix} by ${slackNameFail} failed: ${err}" + slackSend channel: slackChannelFail, color: 'bad', message: message + throw err +} From 8ff8e52a3990feaa0f989eebc8ed338d7b0a2508 Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Thu, 5 Apr 2018 16:17:29 -0600 Subject: [PATCH 09/17] Remove parameter from Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f10b34d8..e79fec61 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -90,7 +90,7 @@ try { try { stage('package') { - print "building python wheel package from build ${TRIGGERING_BUILD_NUMBER}" + print "building python wheel package" sh 'make package' archiveArtifacts artifacts: 'dist/*.whl' } From 1580182f1bcc19e18b9cc8083f8ca49deff7d71d Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Thu, 5 Apr 2018 16:31:32 -0600 Subject: [PATCH 10/17] Fix syntax error --- Jenkinsfile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e79fec61..af7f17e2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -74,9 +74,9 @@ try { // Looking up the author also demands being in a `node`. gitAuthor = sh(returnStdout: true, script: 'git --no-pager show -s --format="%aN" HEAD').trim() - def selenium + def dockerImage stage('prepare environment') { - selenium = pullBuildPush( + dockerImage = pullBuildPush( image_name: 'jenkins/rsconnect-jupyter', image_tag: 'python3', docker_context: './', @@ -88,12 +88,11 @@ try { push: !isUserBranch) } - try { - stage('package') { + stage('package') { print "building python wheel package" sh 'make package' archiveArtifacts artifacts: 'dist/*.whl' - } + } } } From 3868e83b2b48ce0a35f7bcbb2abccf7fdeb0ef95 Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Fri, 6 Apr 2018 10:31:51 -0600 Subject: [PATCH 11/17] Package inside docker --- Jenkinsfile | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index af7f17e2..c1cc9b75 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -77,21 +77,24 @@ try { def dockerImage stage('prepare environment') { dockerImage = pullBuildPush( - image_name: 'jenkins/rsconnect-jupyter', - image_tag: 'python3', - docker_context: './', - build_arg_NB_UID: 'JENKINS_UID', - build_arg_NB_GID: 'JENKINS_GID', - build_arg_NB_USER: 'jenkins', - build_arg_PY_VERSION: '3', - build_arg_BASE_IMAGE: 'continuumio/miniconda3:4.4.10', - push: !isUserBranch) + image_name: 'jenkins/rsconnect-jupyter', + image_tag: 'python3', + docker_context: './', + build_arg_NB_UID: 'JENKINS_UID', + build_arg_NB_GID: 'JENKINS_GID', + build_arg_NB_USER: 'jenkins', + build_arg_PY_VERSION: '3', + build_arg_BASE_IMAGE: 'continuumio/miniconda3:4.4.10', + push: !isUserBranch + ) } - stage('package') { + dockerImage.inside() { + stage('package') { print "building python wheel package" - sh 'make package' + sh 'make dist' archiveArtifacts artifacts: 'dist/*.whl' + } } } } From 28fd0303d3ded82b7f80ab4950efa440c6b9f089 Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Fri, 6 Apr 2018 10:40:08 -0600 Subject: [PATCH 12/17] Flatten update and install so Docker works :( --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 33692562..84bda004 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,8 @@ ARG NB_USER ARG NB_UID ARG NB_GID ARG PY_VERSION -RUN apt-get update -qq -RUN apt-get install -y make +RUN apt-get update -qq \ + && apt-get install -y make RUN useradd --password password \ --create-home \ --home-dir /home/${NB_USER} \ From b8d764cc18cb280df01531dd46fb921c9fb838ad Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Fri, 6 Apr 2018 10:46:21 -0600 Subject: [PATCH 13/17] Minimize layers? --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 84bda004..9a174a32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,5 +16,5 @@ RUN useradd --password password \ ${NB_USER} USER ${NB_UID}:${NB_GID} -WORKDIR /home/${NB_USER} -RUN conda create --yes --name py${PY_VERSION} jupyter +RUN cd /home/${NB_USER} \ + conda create --yes --name py${PY_VERSION} jupyter From f38cd38ff90221624bd09884f0098a1cd31d6e00 Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Fri, 6 Apr 2018 11:39:03 -0600 Subject: [PATCH 14/17] Hopefully now? --- Jenkinsfile | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c1cc9b75..f9a21085 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -56,6 +56,14 @@ if (isUserBranch) { nodename = 'connect-branches' } +def build_args() { + def user = sh (script: 'id -nu jenkins', returnStdout: true).trim() + def uid = sh (script: 'id -u jenkins', returnStdout: true).trim() + def gid = sh (script: 'id -g jenkins', returnStdout: true).trim() + def image = 'continuumio/miniconda3:4.4.10' + return " --build-arg PY_VERSION=3 --build-arg BASE_IMAGE=${image} --build-arg NB_USER=${user} --build-arg NB_UID=${uid} --build-arg NB_GID=${gid} " +} + try { node(nodename) { timestamps { @@ -79,12 +87,9 @@ try { dockerImage = pullBuildPush( image_name: 'jenkins/rsconnect-jupyter', image_tag: 'python3', - docker_context: './', - build_arg_NB_UID: 'JENKINS_UID', - build_arg_NB_GID: 'JENKINS_GID', - build_arg_NB_USER: 'jenkins', - build_arg_PY_VERSION: '3', - build_arg_BASE_IMAGE: 'continuumio/miniconda3:4.4.10', + build_arg_nb_uid: 'JENKINS_UID', + build_arg_nb_gid: 'JENKINS_GID', + build_args: build_args(), push: !isUserBranch ) } From 262a8eaebfef5e4251f7a616c6101b728fe1e76c Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Fri, 6 Apr 2018 11:42:37 -0600 Subject: [PATCH 15/17] Echo a thing --- Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Dockerfile b/Dockerfile index 9a174a32..82f61d2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,12 @@ ARG NB_GID ARG PY_VERSION RUN apt-get update -qq \ && apt-get install -y make +RUN echo useradd --password password \ + --create-home \ + --home-dir /home/${NB_USER} \ + --uid ${NB_UID} \ + --gid ${NB_GID} \ + ${NB_USER} RUN useradd --password password \ --create-home \ --home-dir /home/${NB_USER} \ From e7bee002ee8340561afc9a6360eeca0b98dea2c3 Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Fri, 6 Apr 2018 11:49:21 -0600 Subject: [PATCH 16/17] Hardcode user and group name --- Dockerfile | 14 ++++---------- Jenkinsfile | 3 +-- Makefile | 4 ---- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 82f61d2e..34432a66 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,25 +2,19 @@ ARG BASE_IMAGE FROM ${BASE_IMAGE} LABEL maintainer="RStudio Connect " -ARG NB_USER ARG NB_UID ARG NB_GID ARG PY_VERSION RUN apt-get update -qq \ && apt-get install -y make -RUN echo useradd --password password \ - --create-home \ - --home-dir /home/${NB_USER} \ - --uid ${NB_UID} \ - --gid ${NB_GID} \ - ${NB_USER} +RUN getent group ${NB_GID} || groupadd -g ${NB_GID} builder RUN useradd --password password \ --create-home \ - --home-dir /home/${NB_USER} \ + --home-dir /home/builder \ --uid ${NB_UID} \ --gid ${NB_GID} \ - ${NB_USER} + builder USER ${NB_UID}:${NB_GID} -RUN cd /home/${NB_USER} \ +RUN cd /home/builder \ conda create --yes --name py${PY_VERSION} jupyter diff --git a/Jenkinsfile b/Jenkinsfile index f9a21085..b56bec66 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -57,11 +57,10 @@ if (isUserBranch) { } def build_args() { - def user = sh (script: 'id -nu jenkins', returnStdout: true).trim() def uid = sh (script: 'id -u jenkins', returnStdout: true).trim() def gid = sh (script: 'id -g jenkins', returnStdout: true).trim() def image = 'continuumio/miniconda3:4.4.10' - return " --build-arg PY_VERSION=3 --build-arg BASE_IMAGE=${image} --build-arg NB_USER=${user} --build-arg NB_UID=${uid} --build-arg NB_GID=${gid} " + return " --build-arg PY_VERSION=3 --build-arg BASE_IMAGE=${image} --build-arg NB_UID=${uid} --build-arg NB_GID=${gid} " } try { diff --git a/Makefile b/Makefile index ad96e200..bca357b5 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ .PHONY: clean pull images image2 image3 launch notebook2 notebook3 package dist test dist run -NB_USER=$(shell id -nu) NB_UID=$(shell id -u) NB_GID=$(shell id -g) @@ -26,7 +25,6 @@ image2: --build-arg BASE_IMAGE=continuumio/miniconda:4.4.10 \ --build-arg NB_UID=$(NB_UID) \ --build-arg NB_GID=$(NB_GID) \ - --build-arg NB_USER=$(NB_USER) \ --build-arg PY_VERSION=2 \ . @@ -37,7 +35,6 @@ image3: --build-arg BASE_IMAGE=continuumio/miniconda3:4.4.10 \ --build-arg NB_UID=$(NB_UID) \ --build-arg NB_GID=$(NB_GID) \ - --build-arg NB_USER=$(NB_USER) \ --build-arg PY_VERSION=3 \ . @@ -47,7 +44,6 @@ launch: -v $(CURDIR):/rsconnect \ -e NB_UID=$(NB_UID) \ -e NB_GID=$(NB_GID) \ - -e NB_USER=$(NB_USER) \ -e PY_VERSION=$(PY_VERSION) \ -p :9999:9999 \ $(DOCKER_IMAGE) \ From a6c0c3b7584bb54ee3284af6f9775deee9abd398 Mon Sep 17 00:00:00 2001 From: Jonathan Curran Date: Fri, 6 Apr 2018 12:21:40 -0600 Subject: [PATCH 17/17] Forgot && --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 34432a66..4d82da86 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,4 +17,4 @@ RUN useradd --password password \ USER ${NB_UID}:${NB_GID} RUN cd /home/builder \ - conda create --yes --name py${PY_VERSION} jupyter + && conda create --yes --name py${PY_VERSION} jupyter