Git-Backed Content¶
Content may be deployed to RStudio Connect directly from a remote Git repository. Content will automatically fetch from the associated remote Git repository and re-deploy. This allows for integration with Git-centric workflows and continuous deployment automation.
NOTE: Support for Git-backed content is dependent on an acceptable version of Git being present in the RStudio Connect deployment environment, as described in the Admin Guide.
Git-backed content may be distinguished from other content by the presence of the text "from Git" in the content description as well as a Git metadata section in the content Settings -> Info panel.
Limitations¶
Git-backed content cannot be re-deployed or updated via other means, such as by publishing
from the RStudio IDE or rsconnect::deployApp
.
The current support for authenticating with private Git repositories is limited to a single set of credentials which must be configured on the Connect server. See the Admin guide for details.
NOTE: These instructions are limited to content using R, such as Shiny apps, reports, or static plots. Generating the appropriate manifest for Python content like Jupyter Notebooks or reticulated R and Python content is not readily available. Please contact support@rstudio.com if you're interested.
Publishing for the First Time¶
In order to deploy Git-backed content to RStudio Connect you'll follow a two step process:
- Create and commit a manifest file
- Link RStudio Connect to the Git repository
The first step is completed in the development environment, and the second step is accomplished from within RStudio Connect.
Creating a Manifest File¶
The first step is to create a manifest.json
file associated with the content
you want RStudio Connect to track and deploy. The manifest file tells RStudio
Connect how to deploy and host your content. This manifest includes information like
the content's environment dependencies. The manifest can be created by calling
the R function rsconnect::writeManifest
from within your project directory.
NOTE: Please use
rsconnect
version 0.8.15 or higher when generating a manifest file.
For example, if your project has a single app.R
file, the sequence would look like:
# In a directory with app.R
list.files()
# [1] "app.R"
# Create the manifest
rsconnect::writeManifest()
# Confirm manifest.json output
list.files()
# [1] "app.R" "manifest.json"
Calling rsconnect::writeManifest
repeatedly will update the manifest.json
file.
If your Git repository includes multiple directories, call the function from within the directory containing the content you wish to deploy. For example, if the project looks like:
Project Git Repository :
- README.md
- analysis (directory)
- prep.R
- experiments.Rmd
- results (directory)
- app.R
- supporting (directory)
If you want to deploy the shiny app in the results
directory, first make the results
directory your working directory and then call writeManifest
.
Project Git Repository:
- README.md
- analysis (directory)
- prep.R
- experiments.Rmd
- results (directory)
- app.R
- manifest.json
- supporting (directory)
In this case, do not call writeManifest
from the project's root directory. RStudio Connect will include everything in the results
directory and supporting
directory in the deployment.
The writeManifest
function does its best to infer the correct information about your content. In some cases you may wish to be more explicit and can include the following arguments:
appPrimaryDoc
: The primary file in cases where there are more then onecontentCategory
: The type of content in cases where it is unclear
Below are a two examples to show when you would need to use these explicit options:
- A directory containing multiple R Markdown documents
Your project directory may contain multiple R Markdown documents:
report.Rmd
email.Rmd
Use appPrimaryDoc
to specify which R Markdown is the entry point for RStudio Connect:
rsconnect::writeManifest(appPrimaryDoc = "report.Rmd")
- A directory containing HTML
Use contentCategory
to distinguish between a website and a plot. For instance, if the directory contains multiple HTML files for a website, use:
rsconnect::writeManifest(appPrimaryDoc = "index.html", contentCategory = "site")
Tracking the Manifest File¶
After the manifest.json
is generated, add and commit it to your local Git
working copy, and be sure to push to the remote Git repository so that Connect
can see the manifest.json
after fetching. This is roughly the equivalent done
in a terminal:
git add manifest.json
git commit -m 'Adding manifest.json for RStudio Connect deployment'
git push
Linking Git to RStudio Connect¶
Connect users must have at least the publisher
role in order to create new
content from a Git repository.
On the "Content" page, there is a button near the top labeled "Publish". Clicking on this button will expand a menu which contains an item called "Import from Git", which may be clicked to launch a new content wizard.
The new content wizard will first prompt for a Git repo URL, which may use
https://
(recommended) or http://
remotes.
NOTE: Repository URLs must not contain authorization. Private repository access requires configuration of
GitCredential.Host
,GitCredential.Username
, andGitCredential.Password
, as described in the Admin Guide.
Once the repository URL has been entered, the next step requires specifying a branch name. A selection of candidate branch names collected from the remote repository will be listed.
Once the branch name has been entered, the next step will require specifying a
target directory. The directory names listed will have been determined by
searching for directories containing a manifest.json
file.
Once the target directory has been entered, an initial deployment is triggered.
Updating Content¶
To update Git-backed content, make any necessary code changes and then call
rsconnect::writeManifest
. Commit both the updated code and the updated
manifest.json
file. Once the commit is made, you can either wait for RStudio
Connect to automatically deploy the changes or, from within the RStudio
Connect dashboard, manually tell Connect to "Update Now".
Option 1: Connect Automatic Update¶
Connect will periodically check all Git-backed content for updates. By default this check occurs every 15 minutes, but administrators can configure a different interval. If the updated repository is found to contain changes to the relevant branch and path specified, a new deployment will automatically be triggered. Such an update may be from new commit(s) pushed to the remote Git repository, or from another branch being merged into the target branch such as when merging a pull request.
Automatic updates may be disabled or enabled in the Git metadata section in the Settings -> Info panel.
Option 2: Connect Manual Update¶
Git-backed content may be immediately checked for updates and potentially redeployed by clicking the "Update Now" button in the content Settings -> Info panel.