Skip to content

Commit

Permalink
Merge pull request #265 from rstudio/mbh-rsconnect-ci
Browse files Browse the repository at this point in the history
Use latest rsconnect-python in tests
  • Loading branch information
meatballhat authored Jun 24, 2020
2 parents c86b557 + 07da120 commit 82cd173
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 70 deletions.
53 changes: 38 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
tags: ['*']
pull_request:
branches: [master]
env:
DOCKER_TTY_FLAGS: ''
jobs:
test:
strategy:
Expand Down Expand Up @@ -45,22 +47,41 @@ jobs:
restore-keys: |
virtualenvs-${{ matrix.os }}-py${{ matrix.python-version }}-${{ hashFiles('Pipfile.lock') }}
virtualenvs-${{ matrix.os }}-py${{ matrix.python-version }}-
- run: pip install -U -I pip pipenv
- run: pipenv install --dev
- run: pipenv run pip freeze
- run: pipenv run python setup.py --version
- run: echo '::set-env name=PYTHONPATH::'${GITHUB_WORKSPACE}
- run: make prereqs
- run: make version
- run: make install
- run: make lint
- run: make test
- if: false
name: currently busted selenium test stuff
run: >
make image${{ matrix.python-version }}
make -C selenium build
make -C selenium clean
make -C selenium test-env-up
make -C selenium jupyter-up
make -C selenium test
selenium:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: git fetch --prune --unshallow
- uses: actions/setup-python@v2
with:
python-version: 3.8.x
- uses: actions/cache@v1
with:
path: ~/.cache/pip
key: pip-ubuntu-latest-py3.8-${{ hashFiles('Pipfile.lock') }}
restore-keys: |
pip-ubuntu-latest-py3.8-${{ hashFiles('Pipfile.lock') }}
pip-ubuntu-latest-py3.8-
- uses: actions/cache@v1
with:
path: ~/.local/share/virtualenvs
key: virtualenvs-ubuntu-latest-py3.8-${{ hashFiles('Pipfile.lock') }}
restore-keys: |
virtualenvs-ubuntu-latest-py3.8-${{ hashFiles('Pipfile.lock') }}
virtualenvs-ubuntu-latest-py3.8-
- run: echo '::set-env name=PYTHONPATH::'${GITHUB_WORKSPACE}
- run: make image3.8
- run: make -C selenium build
- run: make -C selenium clean
- run: make -C selenium test-env-up
- run: make -C selenium jupyter-up
- run: make -C selenium test
distributions:
needs: test
runs-on: ubuntu-latest
Expand All @@ -84,8 +105,10 @@ jobs:
restore-keys: |
virtualenvs-ubuntu-latest-py3.8-${{ hashFiles('Pipfile.lock') }}
virtualenvs-ubuntu-latest-py3.8-
- run: pip install -U -I pip pipenv
- run: pipenv install --dev
- run: echo '::set-env name=PYTHONPATH::'${GITHUB_WORKSPACE}
- run: make prereqs
- run: pipenv clean
- run: pipenv install --skip-lock --dev
- run: pipenv run pip install -U 'SecretStorage>=3'
- run: make dist
id: create_dist
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ WORKDIR /rsconnect_jupyter
ENV WORKON_HOME=/home/builder \
PIPENV_DONT_LOAD_ENV=1 \
PIPENV_SHELL=/bin/bash \
PATH=/home/builder/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PATH=/home/builder/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
PYTHONPATH=/rsconnect_jupyter
COPY Pipfile Pipfile
COPY Pipfile.lock Pipfile.lock
RUN python -m pip install -I -U pip pipenv && \
Expand Down
39 changes: 33 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,31 @@ NB_UID := $(shell id -u)
NB_GID := $(shell id -g)

IMAGE := rstudio/rsconnect-jupyter-py
VERSION := $(shell pipenv run python setup.py --version)
VERSION := $(shell pipenv run python setup.py --version 2>/dev/null || echo 'NOTSET')
BDIST_WHEEL := dist/rsconnect_jupyter-$(VERSION)-py2.py3-none-any.whl
S3_PREFIX := s3://rstudio-connect-downloads/connect/rsconnect-jupyter
PORT := $(shell printenv PORT || echo 9999)

JUPYTER_LOG_LEVEL ?= INFO

# NOTE: See the `dist` target for why this exists.
SOURCE_DATE_EPOCH := $(shell date +%s)
export SOURCE_DATE_EPOCH

PYTHONPATH ?= $(CURDIR)
export PYTHONPATH


.PHONY: prereqs
prereqs:
pip install -U pip
pip install -U pipenv


.PHONY: install-latest-rsconnect-python
install-latest-rsconnect-python:
pipenv run pip install -U https://cdn.rstudio.com/connect/rsconnect-python/latest/rsconnect_python-latest-py2.py3-none-any.whl

.PHONY: clean
clean:
rm -rf build/ dist/ docs/out/ rsconnect_jupyter.egg-info/
Expand Down Expand Up @@ -55,16 +71,23 @@ dist: version-frontend

.PHONY: run
run: install
pipenv run jupyter-notebook -y --notebook-dir=/notebooks --ip='0.0.0.0' --port=9999 --no-browser --NotebookApp.token=''
pipenv run jupyter notebook \
-y \
--log-level=$(JUPYTER_LOG_LEVEL) \
--notebook-dir=/notebooks \
--ip='0.0.0.0' \
--port=9999 \
--no-browser \
--NotebookApp.token=''

.PHONY: install
install: yarn
pipenv install --dev
$(MAKE) install-latest-rsconnect-python
$(MAKE) version-frontend
pipenv run pip install -e .
pipenv run jupyter-nbextension install --symlink --user --py rsconnect_jupyter
pipenv run jupyter-nbextension enable --py rsconnect_jupyter
pipenv run jupyter-serverextension enable --py rsconnect_jupyter
pipenv run jupyter nbextension install --symlink --user --py rsconnect_jupyter
pipenv run jupyter nbextension enable --py rsconnect_jupyter
pipenv run jupyter serverextension enable --py rsconnect_jupyter

build/mock-connect/bin/flask:
bash -c '\
Expand Down Expand Up @@ -123,6 +146,10 @@ docs/out:
dist/rsconnect-jupyter-$(VERSION).pdf: docs/README.md docs/*.gif docs/out
$(BUILD_DOC)

.PHONY: version
version:
@echo $(VERSION)

.PHONY: version-frontend
version-frontend:
printf '{"version":"%s"}\n' $(VERSION) >rsconnect_jupyter/static/version.json
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ wheel = "*"
nbconvert = ">=5.0"
nbformat = "*"
notebook = "*"
rsconnect-python = "1.5.0b1"
rsconnect-python = ">=1.5.0b2"
six = "*"

[pipenv]
Expand Down
29 changes: 14 additions & 15 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 26 additions & 14 deletions selenium/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ JUPYTER_LOG=jupyter-py${PY_VERSION}.log
JUPYTER_PORT=9999
JUPYTER_SCHEME=http
JUPYTER_IMAGE=rstudio/rsconnect-jupyter-py${PY_VERSION}
JUPYTER_LOG_LEVEL ?= INFO
LOGS_DIR=${RSCONNECT_DIR}/selenium
NB_UID=$(shell id -u)
NB_GID=$(shell id -g)
NETWORK=${PROJECT}_default
NOTEBOOKS_DIR=/notebooks
PROJECT=rscjnet
PY_VERSION=3.8
PYTESTLOG?=selenium_tests.log
Expand All @@ -34,18 +34,22 @@ SCALE_FIREFOX=${SCALE}
SCALE_CHROME=${SCALE}
SELENIUM_VERSION=3.8.1-dubnium
TMP_PIPE=tmp.pipe
TRE_IMAGE?=rstudio/checkrs-tew:0.3.2
TRE_IMAGE?=rstudio/checkrs-tew:0.4.0

NOTEBOOKS_DIR_MOUNT := /notebooks
NOTEBOOKS_DIR := $(CURDIR)/../notebooks$(PY_VERSION)

# Allocate a tty and keep stdin open when running locally
# Jenkins nodes don't have input tty, so we set this to ""
DOCKER_TTY_FLAGS?=-it

DOCKER_RUN_COMMAND=docker run --rm --init \
DOCKER_RUN_COMMAND = \
docker run --rm --init \
${DOCKER_TTY_FLAGS} \
--name=tre-${HOURMINSEC} \
--network=$(NETWORK) \
--volume=$(CURDIR)/..:${RSCONNECT_DIR} \
--volume=$(CURDIR)/../notebooks$(PY_VERSION):${NOTEBOOKS_DIR} \
--volume=$(NOTEBOOKS_DIR):$(NOTEBOOKS_DIR_MOUNT) \
--user=$(NB_UID):$(NB_GID) \
--workdir=${RSCONNECT_DIR}/selenium \
${TRE_IMAGE}
Expand All @@ -60,11 +64,11 @@ TEST_RUNNER_COMMAND = \
--jupyter-url='${JUPYTER_SCHEME}://${JUPYTER_HOST}:${JUPYTER_PORT}' \
--connect-url='${CONNECT_SCHEME}://${CONNECT_HOST}:${CONNECT_PORT}' \
--data-dir=${RSCONNECT_DIR}/selenium/data \
--notebooks-dir=${NOTEBOOKS_DIR} \
--notebooks-dir=$(NOTEBOOKS_DIR_MOUNT) \
-vv \
--tb=short \
--reruns=${RERUN_FAILURES} \
-m rsconnect_jupyter \
-m 'rsconnect_jupyter and not fail' \
${PYTESTOPTS}

ifdef DEBUG
Expand All @@ -82,11 +86,16 @@ build-mock-connect:
docker build -t ${CONNECT_IMAGE} ${CONNECT_DOCKERFILE_DIR}

clean:
rm -f *.png *.log *.xml ${TMP_PIPE}
rm -rf .pytest_cache
$(RM) *.png *.log *.xml ${TMP_PIPE}
$(RM) -r .pytest_cache
$(RM) -r $(NOTEBOOKS_DIR)

distclean: clean

$(NOTEBOOKS_DIR):
mkdir -p $@
chmod -v 0777 $@

# The test target launches a Docker container to run the test cases.
# Prior to launching the Docker container, we check that the prerequisite
# systems (selenium grid, system under test) are up and accepting requests.
Expand All @@ -95,8 +104,8 @@ distclean: clean
# we remove the named pipe, which also ends the pytest output from being
# printed to stdout through the tee command.

test: wait-for-systems-up prepare-logging
${DOCKER_RUN_COMMAND} ${TEST_RUNNER_COMMAND} > ${TMP_PIPE} || EXITCODE=$$?; \
test: $(NOTEBOOKS_DIR) wait-for-systems-up prepare-logging
${DOCKER_RUN_COMMAND} ${TEST_RUNNER_COMMAND} >${TMP_PIPE} || EXITCODE=$$?; \
rm -f ${TMP_PIPE}; \
exit $$EXITCODE

Expand All @@ -111,7 +120,7 @@ prepare-logging:
mkfifo ${TMP_PIPE}
tee ${PYTESTLOG} < ${TMP_PIPE} &

run:
run: $(NOTEBOOKS_DIR)
@${DOCKER_RUN_COMMAND} ${COMMAND}

test-env-up: grid-up connect-up
Expand Down Expand Up @@ -169,22 +178,24 @@ network-down: connect-down grid-down
docker network rm ${NETWORK}; \
fi

jupyter-up:
jupyter-up: $(NOTEBOOKS_DIR)
@echo "Creating ${JUPYTER_HOST} ..."
@docker run --rm -d --init \
${DOCKER_TTY_FLAGS} \
--name=${JUPYTER_HOST} \
--network=${NETWORK} \
--volume=$(CURDIR)/../notebooks$(PY_VERSION):${NOTEBOOKS_DIR} \
--volume=$(NOTEBOOKS_DIR):$(NOTEBOOKS_DIR_MOUNT) \
--volume=$(CURDIR)/..:${RSCONNECT_DIR} \
--env=NB_UID=$(NB_UID) \
--env=NB_GID=$(NB_GID) \
--env=PY_VERSION=$(PY_VERSION) \
--env=TINI_SUBREAPER=1 \
--env=PYTHONPATH=${RSCONNECT_DIR} \
--publish=:${JUPYTER_PORT}:${JUPYTER_PORT} \
--workdir=${RSCONNECT_DIR} \
--user=$(NB_UID):$(NB_GID) \
$(JUPYTER_IMAGE) \
make -C ${RSCONNECT_DIR} run \
make -C ${RSCONNECT_DIR} run JUPYTER_LOG_LEVEL=$(JUPYTER_LOG_LEVEL) \
1>/dev/null
@docker logs -f ${JUPYTER_HOST} > ${JUPYTER_LOG} &
@echo " done"
Expand All @@ -207,6 +218,7 @@ connect-up:
--env=FLASK_APP=mock_connect.py \
--publish=:${CONNECT_PORT}:${CONNECT_PORT} \
--workdir=${RSCONNECT_DIR} \
--user=$(NB_UID):$(NB_GID) \
$(CONNECT_IMAGE) \
flask run --host=0.0.0.0 --port=${CONNECT_PORT} \
1>/dev/null
Expand Down
Loading

0 comments on commit 82cd173

Please sign in to comment.