.gitlab-ci.yml 3.24 KB
Newer Older
1 2
stages:
  - build_docker_image
3 4
  - generate
  - commit
5 6
  - build
  - deploy
Christophe Benz's avatar
Christophe Benz committed
7

Christophe Benz's avatar
fixup!  
Christophe Benz committed
8
variables:
9 10 11 12 13
  CI_DOCKER_IMAGE: $CI_REGISTRY_IMAGE:latest
  CI_REPOSITORY_SSH_USER: git
  CI_REPOSITORY_DOMAIN: git.opendatafrance.net
  CI_REPOSITORY_SSH_URL: ${CI_REPOSITORY_SSH_USER}@${CI_REPOSITORY_DOMAIN}:${CI_PROJECT_PATH}.git
  LC_ALL: fr_FR.UTF-8
Christophe Benz's avatar
fixup!  
Christophe Benz committed
14
  PDF_FILE: Socle Commun des Données Locales.pdf
15
  TZ: Europe/Paris
16

17
Build Docker image:
18
  stage: build_docker_image
19 20 21 22 23
  only:
    changes:
      - Dockerfile.ci
    refs:
      - master
24 25 26
  except:
    variables:
      - $GENERATE_ASSETS
27 28 29 30 31 32 33 34 35
  image: docker:stable
  services:
    - docker:dind
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
  before_script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
  script:
36 37
    - docker build -t $CI_DOCKER_IMAGE -f Dockerfile.ci .
    - docker push $CI_DOCKER_IMAGE
38 39
  tags:
    - docker-privileged
Christophe Benz's avatar
fixup!  
Christophe Benz committed
40

41 42 43 44 45 46 47 48 49 50 51 52 53
Generate assets:
  stage: generate
  only:
    variables:
      - $GENERATE_ASSETS
  image: $CI_DOCKER_IMAGE
  variables:
    CATALOG_URL: https://git.opendatafrance.net/scdl/catalog/raw/master/catalog.json
  before_script:
    - pip3 install --requirement requirements.txt
  script:
    - mkdir schemas templates
    - python3 ./scripts/generate_assets_from_schema_catalog.py "$CATALOG_URL" schemas templates
54
        docs.template/SUMMARY.j2 SUMMARY.md
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
  artifacts:
    name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
    paths:
      - SUMMARY.md
      - schemas/
      - templates/

Commit generated assets:
  stage: commit
  only:
    variables:
      - $GENERATE_ASSETS
  image: $CI_DOCKER_IMAGE
  before_script:
    - eval $(ssh-agent -s)
    - ssh-add <(echo "$COMMIT_SSH_PRIVATE_KEY")
    - mkdir -p ~/.ssh
    - ssh-keyscan -t rsa $CI_REPOSITORY_DOMAIN >> ~/.ssh/known_hosts
    - git config --global user.name "GitLab Continuous Integration"
    - git config --global user.email "<>"
  script:
    - git clone --branch $CI_COMMIT_REF_NAME $CI_REPOSITORY_SSH_URL
    - rm -rf $CI_PROJECT_NAME/docs/schemas $CI_PROJECT_NAME/docs/templates
    - mv SUMMARY.md schemas templates $CI_PROJECT_NAME/docs/
    - cp $CI_PROJECT_NAME/docs.template/schemas/README.md $CI_PROJECT_NAME/docs/schemas
    - cd $CI_PROJECT_NAME
    - git add -A
    - git commit -m "Update generated assets" || true
    - git push

Build Gitbook:
Christophe Benz's avatar
Christophe Benz committed
86
  stage: build
87 88 89 90
  except:
    variables:
      - $GENERATE_ASSETS
  image: $CI_DOCKER_IMAGE
91
  script:
92
    - ./scripts/build_gitbook.sh
93
  artifacts:
94
    name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
95 96
    paths:
      - _book/
Christophe Benz's avatar
fixup!  
Christophe Benz committed
97
      - "$PDF_FILE"
98

99
.Deploy Gitbook template:
100
  stage: deploy
101 102 103
  except:
    variables:
      - $GENERATE_ASSETS
104
  only:
105 106 107 108 109 110
    variables:
      - $SERVER_DIRECTORY
  image: $CI_DOCKER_IMAGE
  variables:
    SERVER_HOST: go.validata.fr
    SERVER_USER: validata
111 112
  before_script:
    - eval $(ssh-agent -s)
113
    - ssh-add <(echo "$DEPLOY_SSH_PRIVATE_KEY")
114
    - mkdir -p ~/.ssh
115
    - ssh-keyscan -t rsa $SERVER_HOST >> ~/.ssh/known_hosts
Christophe Benz's avatar
Christophe Benz committed
116
  script:
117 118 119 120 121
    - rsync -avz --delete _book/ "$PDF_FILE" ${SERVER_USER}@${SERVER_HOST}:${SERVER_DIRECTORY}/

Deploy Gitbook next:
  extends: .Deploy Gitbook template
  only:
Christophe Benz's avatar
Christophe Benz committed
122
    - master
123 124 125 126 127
  variables:
    SERVER_DIRECTORY: scdl-documentation-static-next
  environment:
    name: next
    url: https://scdl.opendatafrance.net/docs-next/