Skip to content

Conversation

@sagerb
Copy link
Contributor

@sagerb sagerb commented May 9, 2022

Description

These commands now accept the --image or -m parameter, to specify the content image

  • rsconnect write-manifest api:

  • rsconnect write-manifest bokeh:

  • rsconnect write-manifest dash:

  • rsconnect write-manifest fastapi:

  • rsconnect write-manifest notebook:

  • rsconnect write-manifest quarto:

  • rsconnect write-manifest streamlit:

  • rsconnect deploy api

  • rsconnect deploy bokeh

  • rsconnect deploy dash

  • rsconnect deploy fastapi

  • rsconnect deploy notebook

  • rsconnect deploy quarto

  • rsconnect deploy streamlit

Not impacted (but related) and unaffected (do not accept the --image parameter)

  • rsconnect deploy manifest
  • rsconnect deploy other-content
  • rsconnect deploy html

Fixes rstudio/connect#21381

Implementation Notes

The objective of this PR was to add a single command line option to multiple commands. Unfortunately, the refactoring involved encountered a number of early errors which highlighted the need to enable and utilize better development tooling as part of the refactoring process. After discussions with multiple folks who were focused on the rsconnect-python codebase, we made the decision to gain confidence by making two major changes in the areas where the code was being impacted:

  • Use of 3.5 compatible type hints - basically adding type definitions to the impacted functions (and trying to stay away from the use of Any
  • Removal of optional / default parameters from the function declarations, so that tooling would be able to identify missing parameters. The actual use of optional parameters (often time un-named) was limited to test code, so the refactoring involved in this was rather small for the benefit we gained.

In addition, these changes allowed us to turn on linting for our test code, which was also calling these refactored functions.

After these changes were made, our confidence of being able to identify issues with the refactoring statically rather than functionality was greatly improved. Reproduction of the manually encountered errors within the new codebase were successfully identified by the make lint build step and did not require actual execution of the code path having the problem.

The changes, therefore, within this PR are a bit larger than one would think for simply adding an option or two to the commands listed above. They were, however, critical to improving our confidence in making this change (where in the past, this was a recognized fragile effort).

I have also added notes into the CONTRIBUTE.md file which should help bootstrap development efforts for this repo. These were previously missing and did represent an initial barrier to contribution.

Testing Notes / Validation Steps

This feature does not make any changes to the APIs being used, so it should not have introduced any new compatibility requirements w/ a Connect version. The new options, present on the CLI, will happily be accepted by rsconnect-python regardless how the Connect server is configured. The impact, however, of how they are used by the server, differs by the Connect release and configuration. Starting with the May 2022 release, the Connect server when configured with Launcher.Enabled = true and Launcher.Kubernetes = true, will attempt to use the environment.image setting within the content bundle to match the target content image. If this configuration is not active or if it is a previous version of Connect, that field will be ignored and the legacy behavior will not be impacted. Because of this.. it is prudent to run a few of these commands against an older version or a non-kubernetes configuration, just to make sure there is no compatibility issue. Those steps are NOT outlined below.

Approach taken

By using a kubernetes configuration for Connect, which utilizes two duplicate images, we are able to verify the functionality of which image is used by the server when the image flag is specified and when it is not.

Verification for each of the impacted commands is grouped by target, allowing us to focus on a target at a time, but executing fairly similar steps for each target:

Validate write-manifest

  • Validate the help output contains the image option
  • Update the reference manifest.json to be reflective of the active version of python, save this off.
  • Use rsconnect write-manifest -image rstudio/dev-connect-duplicate <target> to update the manifest.json to include the environment.image setting
  • Diff the manifest.json files (with and without image) to confirm there are no other significant differences

Validate deploy manifest for the manifest.json with the image setting

  • Use rsconnect deploy manifest <manifest file> to confirm proper deployment

Validate deploy with and without image

  • Validate the help output contains image
  • Use rsconnect deploy <target> to validate that target is able to be deployed to server and that the server selects the content image target by using the built-in algorithm (will select rstudio/dev-connect).
  • Use rsconnect deploy <target> --image rstudio/dev-connect-duplicate to validate that target is able to be deployed to server and that the server uses the image option to determine the target image (will be rstudio/dev-connect-duplicate).

Testing details

Need to be setup specifically with Python 3.8.x to work with the test data / content outlined below.

brew install python@3.8
#Updated my path to have `/usr/local/opt/python@3.8/bin` ahead of `/usr/local/bin` in ~/.zshenv 
source ~/.zshenv

Setup virtual environment to use branch rsconnect within the base directory of rsconnect-python repo:

# Setup a virtual python environment w/ 3.8.x
rm -rd .venv
python3 --version        
# confirm version listed above is 3.8.x
python3 -m venv .venv
# Activate the virtual environment
source .venv/bin/activate
python3 --version        
# confirm version listed above is 3.8.x
# install our requirements into the virtual environment
pip install -r requirements.txt
# install rsconnect-python with a symbolic link to the locations repository, 
# meaning any changes to code in there will automatically be reflected
pip install -e ./
# clear out path to executables
hash -r

For Connect, I recommend using the new dev-connect docker file workflow, which will be available from main before this PR goes to testing, as will David's supporting server branch which implements the image logic needed on the server.

To start the server, you'll need to:

  1. Build the codebase, from the root of the rstudio/connect project:
    • just ui/dashboard/clean
    • just bootstrap build
  2. Update yeti/docker/built-in/connect-shared-files/rsc-launcher-runtime.yml to have the following two additional image specifications, to be placed at top of image list (on line 3, after the line images:). This should move all of the other image entries down in the file / list.
  - 
    name: rstudio/dev-connect
    python:
      installations:
        - path: /opt/python/3.8.12/bin/python3.8
          version: 3.8.12
    r:
      installations:
        - path: /opt/R/3.6.3/bin/R
          version: 3.6.3
    quarto:
      installations:
        - path: /opt/rstudio-connect/ext/quarto/bin/quarto
          version: 0.9.16
  - 
    name: rstudio/dev-connect-duplicate
    python:
      installations:
        - path: /opt/python/3.8.12/bin/python3.8
          version: 3.8.12
    r:
      installations:
        - path: /opt/R/3.6.3/bin/R
          version: 3.6.3
    quarto:
      installations:
        - path: /opt/rstudio-connect/ext/quarto/bin/quarto
          version: 0.9.16
  -
  1. Create a custom template and add an imagePullPolicy=Never to the pods volume definition.
    • Copy packaging/launcher/connect-k8s-templates/job.tpl to config/launcher/k8s-custom-templates
    • Edit config/launcher/k8s-custom-templates/job.tpl and add the following line after line 83 (image: {{ toYaml .Job.container.image }}) - should be indented same level as the image line.
          imagePullPolicy: Never
- Save the file with your changes.
  1. Temporarily update the main justfile to have (updating area around 228 of justfile):
    # Always build the docker images
    docker build . -t rstudio/dev-connect -f docker/devconnect/Dockerfile
    if [[ "${USE_KUBERNETES}" == "yes" ]]; then
        docker build . -t rstudio/dev-connect-duplicate -f docker/devconnect/Dockerfile
    fi
  1. Reset the dev-connect data volume:
    • docker volume rm dev-connect-volume
  2. Reset your kubernetes cluster:
    • kubectl -n rsc-dev delete jobs --all
    • kubectl -n rsc-dev delete svc --all
  3. Start the server:
    • USE_KUBERNETES=yes just start-dev-connect

Validate changes for target: API

Verify write-manifest api

WITH the venv active.. cd into your rstudio/connect-content repo.
From: rstudio/connect-content

  1. cd bundles/python-flaskapi
  2. execute:
rsconnect write-manifest api --help

and confirm that --image and -m is listed in the help

  1. execute:
cd bundles/python-flaskapi
rsconnect write-manifest api --help

Confirm that --image and -m is listed in the help

  1. execute:
# baseline the manifest w/ your virtual environment basics
rsconnect write-manifest api . --overwrite
mv manifest.json manifest-original.json
rsconnect write-manifest api --image rstudio/dev-connect-duplicate .
diff manifest.json manifest-original.json

confirm that you see the environment/image path added in the new manifest. This will look something like:

16,18d15
<   "environment": {
<     "image": "rstudio/dev-connect-duplicate"
<   },
26,28d22
<     "manifest-original.json": {
<       "checksum": "f5dcb185f388ab9694ac4e6e3ce9f8e0"
<     },

where the first section is the important verification (and the second is just an artifact that we added a file).

Verify deploy manifest

rsconnect deploy manifest -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new ./manifest.json

Verify output is similar to:

Deployment log:
Building Python API...
A target image was specified: rstudio/dev-connect-duplicate, checking if it is compatible...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect-duplicate with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect-duplicate which has version 3.8.8

Verify deploy api

WITH your terminal working directory same as previously (bundles/python-flaskapi)

  1. Confirm that the help output contains the image option:
rsconnect deploy api --help
  1. execute:
rsconnect deploy api -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new .

Confirm that the automatic image was selected, by verifying the output is similar to:

Deployment log:
Building Python API...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect which has version 3.8.8
  1. execute:
rsconnect deploy api -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --image rstudio/dev-connect-duplicate --new .

Verify the output is similar to the following:

Deployment log:
Building Python API...
A target image was specified: rstudio/dev-connect-duplicate, checking if it is compatible...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect-duplicate with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect-duplicate which has version 3.8.8

Validate changes for target: BOKEH

Verify write-manifest bokeh

WITH the venv active.. cd into your rstudio/connect-content repo.
From: rstudio/connect-content:

cd bundles/python-bokeh
rsconnect write-manifest bokeh --help
# confirm that `--image` and `-m` is listed in the help
# baseline the manifest w/ your virtual environment basics
rsconnect write-manifest bokeh . --overwrite
mv manifest.json manifest-original.json
rsconnect write-manifest bokeh --image rstudio/dev-connect-duplicate .
diff manifest.json manifest-original.json

Confirm that you see the environment/image path added in the new manifest. This will look something like the following

16,18d15
<   "environment": {
<     "image": "rstudio/dev-connect-duplicate"
<   },
26,28d22
<     "manifest-original.json": {
<       "checksum": "f5dcb185f388ab9694ac4e6e3ce9f8e0"
<     },

Where the first section is the important verification (and the second is just an artifact that we added a file).

Verify deploy manifest

rsconnect deploy manifest -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new  ./manifest.json

Verify output is similar to:

Deployment log:
Building Bokeh application...
A target image was specified: rstudio/dev-connect-duplicate, checking if it is compatible...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect-duplicate with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect-duplicate which has version 3.8.8

Verify deploy bokeh

WITH your terminal working directory same as previously (bundles/python-bokeh)

  1. Confirm that the help output contains the image option:
rsconnect deploy bokeh --help
  1. execute:
rsconnect deploy bokeh -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new .

Confirm that the automatic image was selected, by verifying the output is similar to:

Deployment log:
Building Bokeh application...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect which has version 3.8.8
  1. execute:
rsconnect deploy bokeh -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --image rstudio/dev-connect-duplicate --new .

Verify the output is similar to the following:

Deployment log:
Building Bokeh application...
A target image was specified: rstudio/dev-connect-duplicate, checking if it is compatible...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect-duplicate with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect-duplicate which has version 3.8.8

Validate changes for target: DASH

Verify write-manifest dash

WITH the venv active.. cd into your rstudio/connect-content repo.
From: rstudio/connect-content:

  1. Execute:
cd bundles/python-dash
rsconnect write-manifest dash --help

Confirm that --image and -m is listed in the help

  1. Execute:
# baseline the manifest w/ your virtual environment basics
rsconnect write-manifest dash . --overwrite
mv manifest.json manifest-original.json
rsconnect write-manifest dash --image rstudio/dev-connect-duplicate .
diff manifest.json manifest-original.json

Confirm that you see the environment/image path added in the new manifest. This will look something like the following

16,18d15
<   "environment": {
<     "image": "rstudio/dev-connect-duplicate"
<   },
26,28d22
<     "manifest-original.json": {
<       "checksum": "f5dcb185f388ab9694ac4e6e3ce9f8e0"
<     },

Where the first section is the important verification (and the second is just an artifact that we added a file).

Verify deploy manifest

rsconnect deploy manifest -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new  ./manifest.json

Verify output is similar to:

Deployment log:
Building Dash application...
A target image was specified: rstudio/dev-connect-duplicate, checking if it is compatible...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect-duplicate with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect-duplicate which has version 3.8.8

Verify deploy dash

WITH your terminal working directory same as previously (bundles/python-dash)

  1. Confirm that the help output contains the image option:
rsconnect deploy dash --help
  1. execute:
rsconnect deploy dash -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new .

Confirm that the automatic image was selected, by verifying the output is similar to:

Deployment log:
Building Dash application...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect which has version 3.8.8
  1. execute:
rsconnect deploy dash -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --image rstudio/dev-connect-duplicate --new .

Verify the output is similar to the following:

Deployment log:
Building Dash application...
A target image was specified: rstudio/dev-connect-duplicate, checking if it is compatible...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect-duplicate with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect-duplicate which has version 3.8.8

Validate changes for target: FASTAPI

Verify write-manifest fastapi

WITH the venv active.. cd into your rstudio/connect-content repo.
From: rstudio/connect-content:

  1. Execute:
cd bundles/fastapi-simple
rsconnect write-manifest fastapi --help

Confirm that --image and -m is listed in the help

  1. Execute:
# baseline the manifest w/ your virtual environment basics
rsconnect write-manifest fastapi . --overwrite
mv manifest.json manifest-original.json
rsconnect write-manifest fastapi --image rstudio/dev-connect-duplicate .
diff manifest.json manifest-original.json

Confirm that you see the environment/image path added in the new manifest. This will look something like the following

16,18d15
<   "environment": {
<     "image": "rstudio/dev-connect-duplicate"
<   },
26,28d22
<     "manifest-original.json": {
<       "checksum": "f5dcb185f388ab9694ac4e6e3ce9f8e0"
<     },

Where the first section is the important verification (and the second is just an artifact that we added a file).

Verify deploy manifest

rsconnect deploy manifest -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new  ./manifest.json

Verify output is similar to:

Deployment log:
Building FastAPI application...
A target image was specified: rstudio/dev-connect-duplicate, checking if it is compatible...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect-duplicate with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect-duplicate which has version 3.8.8

Verify deploy fastapi

WITH your terminal working directory same as previously (bundles/fastapi-simple)

  1. Confirm that the help output contains the image option:
rsconnect deploy fastapi --help
  1. execute:
rsconnect deploy fastapi -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new .

Confirm that the automatic image was selected, by verifying the output is similar to:

Deployment log:
Building FastAPI application...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect which has version 3.8.8
  1. execute:
rsconnect deploy fastapi -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --image rstudio/dev-connect-duplicate --new .

Verify the output is similar to the following:

Deployment log:
Building FastAPI application...
A target image was specified: rstudio/dev-connect-duplicate, checking if it is compatible...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect-duplicate with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect-duplicate which has version 3.8.8

Validate changes for target: NOTEBOOK

Verify write-manifest notebook

WITH the venv active.. cd into your rstudio/connect-content repo.
From: rstudio/connect-content:

  1. Execute:
cd bundles/stock-report-jupyter
rsconnect write-manifest notebook --help

Confirm that --image and -m is listed in the help

  1. Execute:
# baseline the manifest w/ your virtual environment basics
rsconnect write-manifest notebook --overwrite stock-report-jupyter.ipynb quandl-wiki-tsla.json.gz thumbnail.jpg
mv manifest.json manifest-original.json
rsconnect write-manifest notebook --image rstudio/dev-connect-duplicate stock-report-jupyter.ipynb quandl-wiki-tsla.json.gz thumbnail.jpg
diff manifest.json manifest-original.json

Confirm that you see the environment/image path added in the new manifest. This will look something like the following

16,18d15
<   "environment": {
<     "image": "rstudio/dev-connect-duplicate"
<   },

Where the first section is the important verification (and the second is just an artifact that we added a file).

Verify deploy manifest

rsconnect deploy manifest -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new  ./manifest.json

Verify output is similar to:

Deployment log:
Building Jupyter notebook...
A target image was specified: rstudio/dev-connect-duplicate, checking if it is compatible...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect-duplicate with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect-duplicate which has version 3.8.8

Verify deploy notebook

WITH your terminal working directory same as previously (bundles/stock-report-jupyter)

  1. Confirm that the help output contains the image option:
rsconnect deploy notebook --help
  1. execute:
rsconnect deploy notebook -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new stock-report-jupyter.ipynb quandl-wiki-tsla.json.gz thumbnail.jpg

Confirm that the automatic image was selected, by verifying the output is similar to:

Deployment log:
Building Jupyter notebook...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect which has version 3.8.8
  1. execute:
rsconnect deploy notebook -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --image rstudio/dev-connect-duplicate --new stock-report-jupyter.ipynb quandl-wiki-tsla.json.gz thumbnail.jpg

Verify the output is similar to the following:

Deployment log:
Building Jupyter notebook...
A target image was specified: rstudio/dev-connect-duplicate, checking if it is compatible...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect-duplicate with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect-duplicate which has version 3.8.8

Validate changes for target: QUARTO

Verify write-manifest quarto

WITH the venv active.. cd into your rstudio/connect-content repo.
From: rstudio/connect-content:

  1. Execute:
cd bundles/quarto-proj-py
rsconnect write-manifest quarto --help

Confirm that --image and -m is listed in the help

  1. Execute:
# baseline the manifest w/ your virtual environment basics
rsconnect write-manifest quarto . --overwrite
mv manifest.json manifest-original.json
rsconnect write-manifest quarto --image rstudio/dev-connect-duplicate .
diff manifest.json manifest-original.json

Confirm that you see the environment/image path added in the new manifest. This will look something like the following

16,18d15
<   "environment": {
<     "image": "rstudio/dev-connect-duplicate"
<   },
26,28d22
<     "manifest-original.json": {
<       "checksum": "f5dcb185f388ab9694ac4e6e3ce9f8e0"
<     },

Where the first section is the important verification (and the second is just an artifact that we added a file).

Verify deploy manifest

rsconnect deploy manifest -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new  ./manifest.json

Verify output is similar to:

Deployment log:
Building Quarto document...
Bundle created with Python version 3.8.13 and Quarto version 0.9.16 is compatible with environment Kubernetes::rstudio/dev-connect with Python version 3.8.12 from /opt/python/3.8.12/bin/python3.8 and Quarto version 0.9.16 from /opt/rstudio-connect/ext/quarto/bin/quarto 
Bundle requested Python version 3.8.13; using /opt/python/3.8.12/bin/python3.8 from Kubernetes::rstudio/dev-connect which has version 3.8.12

Verify deploy quarto

WITH your terminal working directory same as previously (bundles/quarto-project-py)

  1. Confirm that the help output contains the image option:
rsconnect deploy quarto --help
  1. execute:
rsconnect deploy quarto -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new .

Confirm that the automatic image was selected, by verifying the output is similar to:

Deployment log:
Building Quarto document...
Bundle created with Python version 3.8.13 and Quarto version 0.9.16 is compatible with environment Kubernetes::rstudio/dev-connect with Python version 3.8.12 from /opt/python/3.8.12/bin/python3.8 and Quarto version 0.9.16 from /opt/rstudio-connect/ext/quarto/bin/quarto 
Bundle requested Python version 3.8.13; using /opt/python/3.8.12/bin/python3.8 from Kubernetes::rstudio/dev-connect which has version 3.8.12
  1. execute:
rsconnect deploy quarto -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --image rstudio/dev-connect-duplicate --new .

Verify the output is similar to the following:

Deployment log:
Building Quarto document...
A target image was specified: rstudio/dev-connect-duplicate, checking if it is compatible...
Bundle created with Python version 3.8.13 and Quarto version 0.9.16 is compatible with environment Kubernetes::rstudio/dev-connect-duplicate with Python version 3.8.12 from /opt/python/3.8.12/bin/python3.8 and Quarto version 0.9.16 from /opt/rstudio-connect/ext/quarto/bin/quarto 
Bundle requested Python version 3.8.13; using /opt/python/3.8.12/bin/python3.8 from Kubernetes::rstudio/dev-connect-duplicate which has version 3.8.12

Validate changes for target: STREAMLIT

Verify write-manifest streamlit

WITH the venv active.. cd into your rstudio/connect-content repo.
From: rstudio/connect-content:

  1. Execute:
cd bundles/python-streamlit
rsconnect write-manifest streamlit --help

Confirm that --image and -m is listed in the help

# baseline the manifest w/ your virtual environment basics
rsconnect write-manifest streamlit --overwrite .
mv manifest.json manifest-original.json
rsconnect write-manifest streamlit --image rstudio/dev-connect-duplicate .
diff manifest.json manifest-original.json

Confirm that you see the environment/image path added in the new manifest. This will look something like the following

16,18d15
<   "environment": {
<     "image": "rstudio/dev-connect-duplicate"
<   },

Where the first section is the important verification (and the second is just an artifact that we added a file).

Verify deploy manifest

rsconnect deploy manifest -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new  ./manifest.json

Verify output is similar to:

Deployment log:
Building Streamlit application...
A target image was specified: rstudio/dev-connect-duplicate, checking if it is compatible...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect-duplicate with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect-duplicate which has version 3.8.8

Verify deploy streamlit

WITH your terminal working directory same as previously (bundles/python-streamlit)

  1. Confirm that the help output contains the image option:
rsconnect deploy streamlit --help
  1. execute:
rsconnect deploy streamlit -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --new .

Confirm that the automatic image was selected, by verifying the output is similar to:

Deployment log:
Building Streamlit application...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect with Python version 3.8.12 from /opt/python/3.8.12/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.12/bin/python3.8 from Kubernetes::rstudio/dev-connect which has version 3.8.12
  1. execute:
rsconnect deploy streamlit -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --image rstudio/dev-connect-duplicate --new .

Verify the output is similar to the following:

Deployment log:
Building Streamlit application...
A target image was specified: rstudio/dev-connect-duplicate, checking if it is compatible...
Bundle created with Python version 3.8.13 is compatible with environment Kubernetes::rstudio/dev-connect-duplicate with Python version 3.8.8 from /opt/python/3.8.8/bin/python3.8 
Bundle requested Python version 3.8.13; using /opt/python/3.8.8/bin/python3.8 from Kubernetes::rstudio/dev-connect-duplicate which has version 3.8.8

Confirm other commands do not accept --image param

deploy manifest

from the bundles/python-streamlit subdirectory

rsconnect deploy manifest -s http://localhost:3939 -k c7achTdggWVGtr851azThcyYDwH5JRgf --image rstudio/dev-connect-duplicate ./manifest.json

Confirm you see an error, similar to:

Usage: rsconnect deploy manifest [OPTIONS] FILE
Try 'rsconnect deploy manifest --help' for help.

Error: No such option: --image

Confirm help doesn't include image

rsconnect deploy manifest --help

It should not include a --image option

deploy other-content

from the bundles/python-streamlit subdirectory

rsconnect deploy other-content --image rstudio/dev-connect-duplicate ./manifest.json

Confirm you see an error, similar to:

Usage: rsconnect deploy manifest [OPTIONS] FILE
Try 'rsconnect deploy manifest --help' for help.

Error: No such option: --image

Confirm help doesn't include image

rsconnect deploy other-content --help

It should not include a --image option

@sagerb sagerb marked this pull request as ready for review May 12, 2022 16:31
@sagerb sagerb requested review from dbkegley and mmarchetti May 12, 2022 17:52
@sagerb sagerb self-assigned this May 12, 2022

def tearDown(self):
# clean up our temporary store
remove(self.server_store_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.remove doesn't handle directories. shutil.rmtree will handle non-empty directories.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed!

Copy link
Collaborator

@dbkegley dbkegley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm excited to see the type hints in here as well, I think it's really helpful to increase our confidence.

Do we need to document in the release notes that some of our interfaces are changing since we are removing some of the default parameters? I know that technically the CLI is supposed to be the only public interface, but the API docs page https://docs.rstudio.com/rsconnect-python does list the python APIs as well. Changing these signatures could break existing callers.

More generally, I'm not sure how I feel about adding a shorthand -m flag. I like to reserve shorthand flags for things that are extremely common, but that's just personal preference. Not sure how others feel about that.

"rsconnect write-manifest streamlit --help"
"rsconnect write-manifest fastapi --help"
"rsconnect deploy streamlit --help"
"rsconnect deploy fastapi --help"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an exhaustive list of commands that support --image?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ended up removing this script.. it wasn't complete and was only a start. I'm going to keep what I created locally, but I'll be working with Kevin to get integration tests which utilize a kubernetes launcher configuration.

ConfirmManifestDiff


# ConfirmHelp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bit of commented code in here, can it be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely! Thanks!

@mmarchetti
Copy link
Contributor

We've removed the API docs for now since they suggested that every function in the package was part of the API - it's currently still up on docs.rstudio.com because we haven't released since then. We still need to create a new "how to use the Python API" type of doc.

CHANGELOG.md Outdated
Comment on lines 22 to 23
optional value is only recognized by the RStudio Connect server it it is configured
to use off-host execution). This is only supported for the write-manifest commands
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"it it is configured...". Also I think this is missing a leading parenthesis.

So that we're a little more explicit about when this image is used by Connect, how about:

... command line option to specify the target image to be used on the RStudio Connect server during content execution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I’m combining the two changelog entries into one:

- An `image` command line option has been added to the `write-manifest` and
  `deploy` commands to specify the target image to be used on the RStudio Connect 
  server during content execution. This is only supported for the `api`, `bokeh`, `dash`, 
  `fastapi`, `notebook`, `quarto` and `streamlit` sub-commands. It is only 
  applicable if the RStudio Connect server is configured to use off-host execution.

and then all image helps will be:

Target image to be used during content execution (only applicable if the RStudio Connect server is configured to use off-host execution)

I've also switched the short help string to a capital I (-I) instead of the lowercase -m.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants