# Notes - Gitlab
###### tags: `Gitlab`
:::info
## Book no ar! :D
:::
## Tentativa 1 - Colocar template gitbook
- ### Configuração do `.gitlab-ci.yml`:
```
# requiring the environment of NodeJS 10
image: node:10
# add 'node_modules' to cache for speeding up builds
cache:
paths:
- node_modules/ # Node modules and dependencies
before_script:
- npm install gitbook-cli -g # install gitbook
- gitbook fetch 3.2.3 # fetch final stable version
- gitbook install # add any requested plugins in book.json
test:
stage: test
script:
- gitbook build . public # build to public path
rules:
- if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH
# the 'pages' job will deploy and build your site to the 'public' path
pages:
stage: deploy
script:
- gitbook build . public # build to public path
artifacts:
paths:
- public
expire_in: 1 week
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
```
:::danger
**Resultado:** Gera a página do Gitbook, mas não constrói o Bookdown
:::
## Tentativa 2 - Seguir tutorial do Lesur pro Bookdown
- **Livro com orientações:**
https://rlesur.gitlab.io/bookdown-gitlab-pages/index.html#host-a-project-on-gitlab
- **Repositório no Gitlab:**
https://gitlab.com/RLesur/bookdown-gitlab-pages/-/tree/master/
- ### Configuração do `.gitlab-ci.yml`:
```
image: rocker/verse:4.0.2
.bookdown:
stage: deploy
script:
- Rscript -e "bookdown::render_book('index.Rmd', 'all', output_dir = 'public')"
artifacts:
paths:
- public
pages:
extends: .bookdown
only:
- master
mr-review:
extends: .bookdown
after_script:
- echo "ENVIRONMENT_URL=https://$CI_PROJECT_NAMESPACE.$CI_PAGES_DOMAIN/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html" >> deploy.env
artifacts:
reports:
dotenv: deploy.env
environment:
name: review/$CI_COMMIT_REF_NAME
url: $ENVIRONMENT_URL
only:
- merge_requests
```
:::danger
**Resultado:** Dá erro em todas as fases e na pipeline aparece que não conseguiu identificar o pacote.
:::
## Tentativa 3 - Adaptações de código
:::info
`index.Rmd` - Cópia do código original
:::
```
---
title: "Glossário do Corte Aberta e BI"
author: "STF/SGE"
date: "`r paste('Última atualização:', format(Sys.Date(), '%d/%m/%Y'))`"
site: bookdown::bookdown_site
documentclass: book
bibliography: [book.bib, packages.bib]
# url: your book url like https://bookdown.org/yihui/bookdown
# cover-image: path to the social sharing image like images/cover.jpg
description: |
This is a minimal example of using the bookdown package to write a book.
The HTML output format for this example is bookdown::gitbook,
set in the _output.yml file.
link-citations: yes
github-repo: rstudio/bookdown-demo
---
```
### Outras configurações
https://gitlab.com/RLesur/bookdown-gitlab-pages/-/blob/master/01-details.Rmd
#### Docker image
```
image <-
readLines("./.gitlab-ci.yml") %>%
stringr::str_subset("rocker") %T>%
cat() %>%
yaml::yaml.load() %$%
image %>%
stringr::str_split(":") %>%
unlist()
```
### Jobs definition
Os trabalhos são definidos pelas linhas restantes do arquivo `.gitlab-ci.yml`:
```
readChar("./.gitlab-ci.yml", 1e5) %>%
strsplit("(?=\\n\\.bookdown:)", perl = TRUE) %>%
unlist() %>%
stringr::str_subset("\\.bookdown") %>%
cat()
```
## Fontes interessantes:
- https://environments.rstudio.com/docker
- https://colinfay.me/docker-r-reproducibility/
- https://www.youtube.com/watch?v=JOIKy_89c-o