Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

vibalre
Copy link
Member

@vibalre vibalre commented Mar 15, 2023

Changes

Related #350
Closes Appsilon Internal Task

  • Adds dot.gitlab-ci.yml template
  • Adds dot.gitlab-ci.Dockerfile template

How to test

@@ -0,0 +1,19 @@
# Use appropriate R version for runner
FROM rstudio/r-base:4.2.2-focal
Copy link
Member Author

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.

Comment on lines +18 to +19
# Build: docker build -f .gitlab-ci.Dockerfile -t your/image:latest .
# Push: docker push your/image:latest
Copy link
Member Author

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.

Comment on lines +4 to +5
# Install other app system dependencies here
RUN apt-get update && apt-get install --yes libcurl4-openssl-dev
Copy link
Member Author

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.

Comment on lines +1 to +10
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
Copy link
Member Author

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.

Comment on lines +14 to +15
# Use deployed image with .gitlab-ci.Dockerfile
image: your/image:latest
Copy link
Member Author

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.

Comment on lines +16 to +23
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}
Copy link
Member Author

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.

Comment on lines +25 to +36
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()"
Copy link
Member Author

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.

@vibalre vibalre changed the title Feat/adds gitlab ci Feat: Adds template for Gitlab CI Mar 15, 2023
@vibalre vibalre self-assigned this Mar 15, 2023
@vibalre vibalre requested a review from kamilzyla March 15, 2023 10:36
@jakubnowicki
Copy link
Member

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 examples directory and provide a documentation entry (a how-to guide) on how to set the CI for GitLab. @kamilzyla WDYT?

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.

2 participants