-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Adds template for Gitlab CI #445
base: main
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,19 @@ | |||
# Use appropriate R version for runner | |||
FROM rstudio/r-base:4.2.2-focal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This template will only work if the gitlab-runner has a docker executor.
I was hesitant to provide a dockerfile template to create an image that will set-up the app system dependencies. However, after some tests, I realized that installing the dependencies took a lot of time.
For rhino-showcase, system dependencies took ~1.5mins to install, nodejs took ~1.5mins, but cypress took ~12.5mins. The fastest I managed to get the CI to complete was ~12mins with all dependencies installed in the pipeline.
I also could not figure out how to extract the R Version from renv.lock
then use the appropriate R image in the pipeline, so I just decided to let the users specify their appropriate R image in this template.
# Build: docker build -f .gitlab-ci.Dockerfile -t your/image:latest . | ||
# Push: docker push your/image:latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are instructions on how to deploy their app environment images.
# Install other app system dependencies here | ||
RUN apt-get update && apt-get install --yes libcurl4-openssl-dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users should update this based on the dependencies of their app.
variables: | ||
# For caching renv library | ||
RENV_PATHS_CACHE: ${CI_PROJECT_DIR}/cache | ||
RENV_PATHS_LIBRARY: ${CI_PROJECT_DIR}/renv/library | ||
# Cache .rhino | ||
DOT_RHINO_PATH: ${CI_PROJECT_DIR}/.rhino | ||
# Necessary for cypress to run. | ||
# https://docs.cypress.io/guides/references/error-messages#A-Cached-Cypress-Binary-Could-not-be-found | ||
# https://docs.cypress.io/guides/continuous-integration/introduction#Caching | ||
CYPRESS_CACHE_FOLDER: ${CI_PROJECT_DIR}/.cache/Cypress |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These cache paths help speed up the pipeline after the first run. Without this, the pipeline will take >20mins to complete each run.
Cypress requires caching the binary. Without this, cypress throws an error.
# Use deployed image with .gitlab-ci.Dockerfile | ||
image: your/image:latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users should use the image they built and pushed using the .gitlab-ci.Dockerfile
template.
cache: | ||
# This key needs to be constant so all jobs in all branches will share the same cache | ||
key: rhino-ci | ||
paths: | ||
- ${RENV_PATHS_CACHE} | ||
- ${RENV_PATHS_LIBRARY} | ||
- ${DOT_RHINO_PATH} | ||
- ${CYPRESS_CACHE_FOLDER} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just specifies all the paths that need to be cached. The key
needs to be constant for all branches to have access to the cache. Users can change this depending on how they want to share caches.
Runs linters and tests: | ||
before_script: | ||
# Restores renv when cache is not available. | ||
- R -e "options(renv.config.cache.symlinks = FALSE); renv::restore(clean = TRUE);" | ||
script: | ||
- R -e "rhino::lint_r()" | ||
- R -e "rhino::lint_sass()" | ||
- R -e "rhino::lint_js()" | ||
- R -e "rhino::build_sass()" | ||
- R -e "rhino::build_js()" | ||
- R -e "rhino::test_r()" | ||
- R -e "rhino::test_e2e()" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted for a single job pipeline instead of a multi-job pipeline.
While a multi-job pipeline looks neater, the fastest I was able to achieve with it using the docker image was about ~10mins.
For a single job pipeline, the CI runs ~2-3 mins for rhino-showcase. The pipeline page is not as informative as the multi-job pipeline because it only shows one job. If the pipeline throws an error, it is not apparent which step failed, but reading the logs actually shows which step failed or encountered an error, so this might not be that much of a downside.
I also performed tests to ensure that the pipeline catches errors in lint r, lint sass, lint js, build sass, and r unit tests. I could not test build js because I can't find a way to make the lint js pass and build js fail. For cypress, I encountered fails when I was doing tests with cypress cache.
Since the complexity of this is higher than in the case of GitHub Actions (mainly, the Docker setup), my recommendation is to move files to the |
Changes
Related #350
Closes Appsilon Internal Task
dot.gitlab-ci.yml
templatedot.gitlab-ci.Dockerfile
templateHow to test