diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f5298c73903a289af1b5ca18388e16921f828eac..3a836bbceaad4ae3e035e3de68d2c0aecfddebfc 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,64 +1,37 @@
-# test config
-image: rocker/tidyverse
+include:
+  - local: '/gitlab-ci/rules.gitlab-ci.yml'	                # generic rules to be used for main branch or others
+  - local: '/gitlab-ci/image.gitlab-ci.yml'                 # image to be used for main branch or others
+  - local: '/gitlab-ci/before_script.gitlab-ci.yml'
+  - local: '/gitlab-ci/build_binary.gitlab-ci.yml'
+  - local: '/gitlab-ci/documentation.gitlab-ci.yml'
+  - local: '/gitlab-ci/check.gitlab-ci.yml'
+  - local: '/gitlab-ci/build_images_docker.gitlab-ci.yml'		# building docker images
 
 stages: # List of stages for jobs, and their order of execution
   - build
   - document
   - check
   - covr
+  - build_images
   
 variables:
   R_LIBS_USER: "$CI_PROJECT_DIR/ci/lib"
   CHECK_DIR: "$CI_PROJECT_DIR/ci/logs"
   BUILD_DIR: "$CI_PROJECT_DIR/ci/build"
   BUILD_LOGS_DIR: "$CI_PROJECT_DIR/ci/logs/$CI_PROJECT_NAME.Rcheck"
+  r_image_path: "registry.forgemia.inra.fr/stacomi/stacomi_db"
+  r_image_name: "r4stacomi"
+  r_image_tagdev: "4.x-dev"
+  docker_version: "20.10"
+cache:
+  key: $CI_COMMIT_REF_SLUG
+  paths:
+    - ${R_LIBS_USER}/
 
-# the .Renviron in the document folder contains the path to the libraries in the form R_LIBS=$CI_PROJECT_DIR/ci/lib
-# there are three lines added there so the uploaded packages will end up there
-before_script:
-  - apt-get update
-  - apt-get install -y qpdf
-  - mkdir -p $R_LIBS_USER $BUILD_LOGS_DIR $BUILD_DIR
-  - echo 'R_LIBS=$R_LIBS_USER' > .Renviron
-  - echo 'R_LIBS_USER=$R_LIBS_USER' >> .Renviron
-  - echo 'R_LIBS_SITE=$R_LIBS_USER' >> .Renviron
-
-# below CI_COMMIT_REF_SLUG is CI_COMMIT_REF_NAME The branch or tag name for which project is built, in lowercase, shortened to 63 bytes  
-buildbinary:
-  stage: build
-  script:
-   # dependencies =TRUE only supports one 
-    - R -e 'install.packages(pkgs=c("testthat"), dependencies = TRUE, repos ="https://pbil.univ-lyon1.fr/CRAN/")'
-    - R -e 'install.packages(pkgs=c("devtools"), dependencies = TRUE, repos ="https://pbil.univ-lyon1.fr/CRAN/")'
-    # below TRUE is shorthand for "Depends", "Imports", "LinkingTo" and "Suggests". 
-    - R -e 'devtools::install_deps(dependencies = TRUE, lib = Sys.getenv("R_LIBS_USER"))'    
-    - R -e 'devtools::build(binary = TRUE, path=Sys.getenv("BUILD_DIR"), vignettes=FALSE, manual=FALSE)'  
-  cache:
-    key: "$CI_COMMIT_REF_SLUG"
-    paths:
-      - "$R_LIBS_USER"
-  artifacts:
-    paths:
-      - "$BUILD_DIR"
-
-documentation:
-  stage: document
-  script:
-    - R -e 'devtools::document()'
-    
-checkerrors:
-  stage: check
-  script:
-   - R -e 'devtools::check(check_dir = Sys.getenv("CHECK_DIR"), document = FALSE, args = "--no-tests")'
-   - R -e 'if (length(devtools::check_failures(path = Sys.getenv("BUILD_LOGS_DIR"), note = FALSE)) > 0) stop()'
-  cache:
-    paths:
-    - $R_LIBS_USER
-    
 coverage:
   stage: covr
+  extends:
+    - .rules_shut_down
   script:
   - R -e 'install.packages(pkgs=c("covr"), dependencies = TRUE, repos ="https://pbil.univ-lyon1.fr/CRAN/")'
-  - R -e 'covr::package_coverage(Sys.getenv("CI_PROJECT_DIR"))'  
-
- 
\ No newline at end of file
+  - R -e 'covr::package_coverage(Sys.getenv("CI_PROJECT_DIR"))'  
\ No newline at end of file
diff --git a/DESCRIPTION b/DESCRIPTION
index bc69275de0e03f66aa31b2f4d658fe21143fcaef..5650813921a7c075a4b7f47608945d7c33d0c915 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -26,7 +26,8 @@ Imports:
     dplyr,
     rlang,
     shinybusy,
-    magrittr
+    magrittr,
+    ggthemes
 Encoding: UTF-8
 LazyData: true
 RoxygenNote: 7.2.1
@@ -39,8 +40,8 @@ Language: en-US
 URL: https://forgemia.inra.fr/stacomi/stacoshiny
 BugReports: https://forgemia.inra.fr/stacomi/stacoshiny/issues
 Remotes: 
-    git::git@forgemia.inra.fr:stacomi/stacomirtools.git,
-    git::git@forgemia.inra.fr:stacomi/stacomir.git
+    git::https://forgemia.inra.fr/stacomi/stacomirtools.git,
+    git::https://forgemia.inra.fr/stacomi/stacomir.git
 VignetteBuilder: knitr
 Depends: 
     R (>= 2.10)
diff --git a/gitlab-ci/before_script.gitlab-ci.yml b/gitlab-ci/before_script.gitlab-ci.yml
new file mode 100644
index 0000000000000000000000000000000000000000..171bab9de054eb5004093e1db2221913e02ab694
--- /dev/null
+++ b/gitlab-ci/before_script.gitlab-ci.yml
@@ -0,0 +1,6 @@
+# the .Renviron in the document folder contains the path to the libraries in the form R_LIBS=$CI_PROJECT_DIR/ci/lib
+# there are three lines added there so the uploaded packages will end up there
+before_script:
+  - apt-get update
+  - mkdir -p ${R_LIBS_USER} ${BUILD_LOGS_DIR} ${BUILD_DIR}
+  - echo 'R_LIBS_USER=${R_LIBS_USER}' >> .Renviron
\ No newline at end of file
diff --git a/gitlab-ci/build_binary.gitlab-ci.yml b/gitlab-ci/build_binary.gitlab-ci.yml
new file mode 100644
index 0000000000000000000000000000000000000000..7e85fa8b6f1676a0126fd7419c517d19ccd6247a
--- /dev/null
+++ b/gitlab-ci/build_binary.gitlab-ci.yml
@@ -0,0 +1,13 @@
+buildbinary:
+  stage: build
+  extends:
+    - .image-dev
+    - .rules_other
+  script:
+    - echo "install packages"
+    - R -e 'remotes::install_deps(upgrade = "never")'    
+    - R -e 'devtools::build(binary = TRUE, path=Sys.getenv("BUILD_DIR"), vignettes=FALSE, manual=FALSE)'  
+    - cp --recursive /usr/local/lib/R/site-library ${R_LIBS_USER}
+  artifacts:
+    paths:
+      - ${BUILD_DIR}
\ No newline at end of file
diff --git a/gitlab-ci/build_images_docker.gitlab-ci.yml b/gitlab-ci/build_images_docker.gitlab-ci.yml
new file mode 100644
index 0000000000000000000000000000000000000000..f34dc684954e58bcd00e332c138bfb5367b2e015
--- /dev/null
+++ b/gitlab-ci/build_images_docker.gitlab-ci.yml
@@ -0,0 +1,32 @@
+# build docker images
+
+#######################
+# for any branch, but main
+build_stacoshiny-dev:
+  image: docker:$docker_version
+  stage: build_images
+  services:
+    - docker:$docker_version_dind
+  extends:
+    - .rules_shut_down 
+  script:
+    - echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
+    - docker build -t $CI_REGISTRY_IMAGE/${stacoshiny_image_name}:${stacoshiny_version}-$tag_dev -f stacoshiny.dockerfile .
+    - docker push --all-tags $CI_REGISTRY_IMAGE/${stacoshiny_image_name}
+
+#######################            
+# for main banch only
+build_stacoshiny-prod:
+  image: docker:$docker_version
+  stage: build_images
+  services:
+    - docker:$docker_version_dind
+  extends:
+    - .rules_shut_down
+  when: manual
+  script:
+    - echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
+    - docker build -t $CI_REGISTRY_IMAGE/${stacoshiny_image_name}:${stacoshiny_version} -f stacoshiny.dockerfile .
+    - docker tag $CI_REGISTRY_IMAGE/${stacoshiny_image_name}:${stacoshiny_version}  $CI_REGISTRY_IMAGE/${stacoshiny_image_name}:latest
+    - docker push --all-tags $CI_REGISTRY_IMAGE/${stacoshiny_image_name}
+    
\ No newline at end of file
diff --git a/gitlab-ci/check.gitlab-ci.yml b/gitlab-ci/check.gitlab-ci.yml
new file mode 100644
index 0000000000000000000000000000000000000000..e83d0fdffeeae82c610ac79edb2a6bc39f3b4b63
--- /dev/null
+++ b/gitlab-ci/check.gitlab-ci.yml
@@ -0,0 +1,9 @@
+checkerrors:
+  stage: check
+  extends:
+    - .image-dev
+    - .rules_other
+  script:
+    - echo 'R_LIBS=$R_LIBS_USER' > .Renviron
+    - Rscript -e 'devtools::check(check_dir = Sys.getenv("CHECK_DIR"), document = FALSE, args = "--no-tests")'
+    - Rscript -e 'if (length(devtools::check_failures(path = Sys.getenv("BUILD_LOGS_DIR"), note = FALSE)) > 0) stop()'
\ No newline at end of file
diff --git a/gitlab-ci/documentation.gitlab-ci.yml b/gitlab-ci/documentation.gitlab-ci.yml
new file mode 100644
index 0000000000000000000000000000000000000000..206678cb505e7813983250775eaf9d1ad32fcb25
--- /dev/null
+++ b/gitlab-ci/documentation.gitlab-ci.yml
@@ -0,0 +1,8 @@
+documentation:
+  stage: document
+  extends:
+    - .image-dev
+    - .rules_other
+  script:
+    - echo 'R_LIBS=$R_LIBS_USER' > .Renviron
+    - R -e 'devtools::document()'
\ No newline at end of file
diff --git a/gitlab-ci/image.gitlab-ci.yml b/gitlab-ci/image.gitlab-ci.yml
new file mode 100644
index 0000000000000000000000000000000000000000..d4b43ea8e11af7b852cfbeff45325654c3295ce7
--- /dev/null
+++ b/gitlab-ci/image.gitlab-ci.yml
@@ -0,0 +1,13 @@
+# to use the right docker db image
+
+#######################
+# for any branch, but main
+.image-dev:   
+  image: 
+    name: ${r_image_path}/${r_image_name}:${r_image_tagdev}
+    entrypoint: ["/usr/sbin/init"]
+      
+#######################
+# for main banch only
+.image-prod:   
+  image: ${r_image_path}/${r_image_name}:latest
\ No newline at end of file
diff --git a/gitlab-ci/rules.gitlab-ci.yml b/gitlab-ci/rules.gitlab-ci.yml
new file mode 100644
index 0000000000000000000000000000000000000000..f58f8389fdcf34661fb447daac60db9916b3219a
--- /dev/null
+++ b/gitlab-ci/rules.gitlab-ci.yml
@@ -0,0 +1,19 @@
+# generic rules to be used for main branch or others
+
+#######################
+# for any branch, but main
+.rules_other:
+  rules:
+    - if: '$CI_COMMIT_BRANCH != "main"'				# only if there is changes in branch other than main
+
+#######################            
+# for main banch only
+.rules_main:
+  rules:
+    - if: '$CI_COMMIT_BRANCH == "main"'				# only if there is changes in the main branch
+
+#######################            
+# for shutting down the job
+.rules_shut_down:
+  rules:
+    - when: never				# only if there is changes in the main branch
\ No newline at end of file