.gitlab-ci.yml 4.82 KB
Newer Older
1
# In case something goes horribly wrong, you can fall back to `image: ruby:2.5`
Laurent Heirendt's avatar
Laurent Heirendt committed
2
image: git-r3lab.uni.lu:4567/r3/docker/jekyll-lcsb:1.6
3

Jacek Lebioda's avatar
Jacek Lebioda committed
4
stages:
Laurent Heirendt's avatar
Laurent Heirendt committed
5
  - prepare
Laurent Heirendt's avatar
Laurent Heirendt committed
6
  - save
Jacek Lebioda's avatar
Jacek Lebioda committed
7
  - build
8
  - generate
Jacek Lebioda's avatar
Jacek Lebioda committed
9 10
  - deploy

Laurent Heirendt's avatar
Laurent Heirendt committed
11 12 13 14 15 16 17
# prepare
# ------------------------------------------------------------------------------------

prepare:index:
  image: python
  stage: prepare
  rules:
Laurent Heirendt's avatar
Laurent Heirendt committed
18
    - if: $CI_COMMIT_REF_NAME
19
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_MESSAGE !~ /tmpBranch/ && $CI_COMMIT_MESSAGE !~ /Update index/'
Laurent Heirendt's avatar
Laurent Heirendt committed
20 21 22 23 24 25 26 27 28
  script:
    - python .ci/generateIndex.py
    - mkdir .tmp
    - cp index.md .tmp/.
  artifacts:
    expire_in: 1 day
    paths:
      - .tmp

Laurent Heirendt's avatar
Laurent Heirendt committed
29 30 31 32
# save
# ------------------------------------------------------------------------------------

save:commitIndex:
33 34 35
  image:
    name: alpine/git:latest
    entrypoint: [""]
Laurent Heirendt's avatar
Laurent Heirendt committed
36
  stage: save
37 38 39
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_MESSAGE !~ /tmpBranch/ && $CI_COMMIT_MESSAGE !~ /Update index/'
  before_script:
Laurent Heirendt's avatar
Laurent Heirendt committed
40
    - apk add git-lfs
41 42 43 44 45 46
    - git fetch --all
    - url_host=`git remote get-url origin | sed -e "s/https:\/\/gitlab-ci-token:.*@//g"`
    - git remote set-url origin "https://$GIT_ACCESS_USER:$GIT_ACCESS_TOKEN@${url_host}"
    - git config user.name $GIT_ACCESS_USER
    - git config user.email $GIT_ACCESS_EMAIL
  script:
Laurent Heirendt's avatar
Laurent Heirendt committed
47
    # copy the index and remove the temporary directory
48
    - cp .tmp/index.md .
Laurent Heirendt's avatar
Laurent Heirendt committed
49 50 51
    - rm -rf .tmp

    # commit
52
    - git branch -D tmpBranch || true
53 54 55 56
    - git checkout -b tmpBranch || true
    - git add --all || true
    - git commit -m "Update index" || true
    - git checkout $CI_COMMIT_REF_NAME || true
57
    - git pull origin $CI_COMMIT_REF_NAME
58
    - git merge tmpBranch --ff || true
59
    - git push origin $CI_COMMIT_REF_NAME || true
60
    - git branch -D tmpBranch || true
61

62 63
# build
# ------------------------------------------------------------------------------------
Jacek Lebioda's avatar
Jacek Lebioda committed
64

65
build:pages:
Jacek Lebioda's avatar
Jacek Lebioda committed
66 67 68 69 70 71 72
  stage: build
  variables:
    JEKYLL_ENV: production
    BUNDLER_VERSION: 2.0.2
  artifacts:
    expire_in: 1 day
    paths:
73
      - build
74
  rules:
Laurent Heirendt's avatar
Laurent Heirendt committed
75
    - if: $CI_COMMIT_REF_NAME
76
    - if: $CI_MERGE_REQUEST_ID
77
  before_script:
Laurent Heirendt's avatar
Laurent Heirendt committed
78 79
    - apt-get -qq update
    - apt-get install -y -qq git-lfs
80
    - gem install bundler:$BUNDLER_VERSION && bundle install
81 82
  script:
    # Generate the configuration for forks (will use Gitlab Pages on personal namespaces)
83 84
    - 'echo "url: https://$CI_PROJECT_NAMESPACE.$CI_PAGES_DOMAIN" >> .ci/_config_gitlab_pages.yml'
    - 'echo "baseurl: /$CI_PROJECT_NAME" >> .ci/_config_gitlab_pages.yml'
85 86

    # If there is no config for the current branch, use the one for Gitlab Pages
87
    - 'if [ ! -f ".ci/_config_$CI_COMMIT_REF_NAME.yml" ]; then mv .ci/_config_gitlab_pages.yml .ci/_config_$CI_COMMIT_REF_NAME.yml; fi'
88 89

    # Display, which configuration is used
90
    - 'echo "Configuration: " && cat ".ci/_config_$CI_COMMIT_REF_NAME.yml"'
91 92

    # Run Jekyll with custom configuration
93
    - bundle exec jekyll build -d build --config "_config.yml,.ci/_config_$CI_COMMIT_REF_NAME.yml"
94

95 96
# generate
# ------------------------------------------------------------------------------------
Jacek Lebioda's avatar
Jacek Lebioda committed
97

98 99
generate:searchIndex:
  stage: generate
Jacek Lebioda's avatar
Jacek Lebioda committed
100
  image: node:13.8.0-slim
101 102
  variables:
    LUNR_VERSION: 2.3.8
103
    DIRECTORY: build
Jacek Lebioda's avatar
Jacek Lebioda committed
104
  script:
Laurent Heirendt's avatar
Laurent Heirendt committed
105
    - bash .ci/build_indices.sh
106
    - mv build processed_build
Jacek Lebioda's avatar
Jacek Lebioda committed
107 108 109
  artifacts:
    expire_in: 1 day
    paths:
110
      - processed_build
111

112 113 114 115 116
# deploy
# ------------------------------------------------------------------------------------

# Deploy to Gitlab Pages - to be run only by forks
pages:
Jacek Lebioda's avatar
Jacek Lebioda committed
117
  image: alpine:3.11.3
118
  stage: deploy
Jacek Lebioda's avatar
Jacek Lebioda committed
119
  rules:
Laurent Heirendt's avatar
Laurent Heirendt committed
120
    - if: '$CI_MERGE_REQUEST_ID && $CI_PROJECT_NAMESPACE != "R3" && $CI_PROJECT_NAMESPACE != "R3-core"'
121
  script:
122
    - mv processed_build public
123
  artifacts:
124
    expire_in: 1 week
125
    paths:
126
      - public
Jacek Lebioda's avatar
Jacek Lebioda committed
127 128

## Deploys the website to a separate VM
129
deploy:vm:
Jacek Lebioda's avatar
Jacek Lebioda committed
130 131
  stage: deploy
  image: alpine:3.1
Laurent Heirendt's avatar
Laurent Heirendt committed
132 133
  rules:
    - if: $CI_COMMIT_REF_NAME
Jacek Lebioda's avatar
Jacek Lebioda committed
134 135 136 137 138 139 140 141 142
  before_script:
    - 'which ssh-agent || ( apk add --update openssh )'
    - eval $(ssh-agent -s)
    - echo "$B64SSHPRIVKEY" | base64 -d | tr -d '\r' | ssh-add - > /dev/null
    - mkdir -p ~/.ssh && chmod 700 ~/.ssh
    - 'echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    - echo "$KNOWNHOSTS" > ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
  rules:
Laurent Heirendt's avatar
Laurent Heirendt committed
143 144
    - if: '$CI_COMMIT_REF_NAME == "develop" && $CI_PROJECT_PATH == "R3/howto-cards"'
    - if: '$CI_COMMIT_REF_NAME == "master" && $CI_PROJECT_PATH == "R3/howto-cards"'
Jacek Lebioda's avatar
Jacek Lebioda committed
145
  script:
Laurent Heirendt's avatar
Laurent Heirendt committed
146 147 148
    - ssh -p $SSHPORT $SSHCONNECT "mkdir -p ~/$CI_COMMIT_REF_NAME/sources/public/$CI_JOB_ID ~/$CI_COMMIT_REF_NAME/public"
    - scp -P $SSHPORT -r processed_build/* $SSHCONNECT:~/$CI_COMMIT_REF_NAME/sources/public/$CI_JOB_ID
    - ssh -p $SSHPORT $SSHCONNECT "cd ~/$CI_COMMIT_REF_NAME/public && ln -fs ../sources/public/$CI_JOB_ID/* . && cd ~/$CI_COMMIT_REF_NAME/sources/public/ && find . -type d -not -newermt '-1 minutes' -exec rm -rf {} +;"
Jacek Lebioda's avatar
Jacek Lebioda committed
149