.gitlab-ci.yml 4.48 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
Jacek Lebioda's avatar
Jacek Lebioda committed
6
  - build
7
  - generate
Jacek Lebioda's avatar
Jacek Lebioda committed
8
9
  - deploy

Laurent Heirendt's avatar
Laurent Heirendt committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# prepare
# ------------------------------------------------------------------------------------

prepare:index:
  image: python
  stage: prepare
  rules:
    - if: $CI_COMMIT_BRANCH
    - if: $CI_MERGE_REQUEST_ID
  script:
    - python .ci/generateIndex.py
    - mkdir .tmp
    - cp index.md .tmp/.
  artifacts:
    expire_in: 1 day
    paths:
      - .tmp

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
prepare:commitIndex:
  image:
    name: alpine/git:latest
    entrypoint: [""]
  stage: deploy
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_MESSAGE !~ /tmpBranch/ && $CI_COMMIT_MESSAGE !~ /Update index/'
  before_script:
    - 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:
    - cp .tmp/index.md .
    - git branch -D tmpBranch || true
    - git checkout -b tmpBranch
    - git add --all
    - git commit -m "Update index"
    - git checkout $CI_COMMIT_REF_NAME
    - git pull origin $CI_COMMIT_REF_NAME
    - git merge tmpBranch --ff
    - git push origin $CI_COMMIT_REF_NAME || true
    - git branch -D tmpBranch

53
54
# build
# ------------------------------------------------------------------------------------
Jacek Lebioda's avatar
Jacek Lebioda committed
55

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

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

    # Display, which configuration is used
81
    - 'echo "Configuration: " && cat ".ci/_config_$CI_COMMIT_REF_NAME.yml"'
82
83

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

86
87
# generate
# ------------------------------------------------------------------------------------
Jacek Lebioda's avatar
Jacek Lebioda committed
88

89
90
generate:searchIndex:
  stage: generate
Jacek Lebioda's avatar
Jacek Lebioda committed
91
  image: node:13.8.0-slim
92
93
  variables:
    LUNR_VERSION: 2.3.8
94
    DIRECTORY: build
Jacek Lebioda's avatar
Jacek Lebioda committed
95
  script:
Laurent Heirendt's avatar
Laurent Heirendt committed
96
    - bash .ci/build_indices.sh
97
    - mv build processed_build
98
99
100
  rules:
    - if: $CI_COMMIT_BRANCH
    - if: $CI_MERGE_REQUEST_ID
Jacek Lebioda's avatar
Jacek Lebioda committed
101
102
103
  artifacts:
    expire_in: 1 day
    paths:
104
      - processed_build
105

106
107
108
109
110
# deploy
# ------------------------------------------------------------------------------------

# Deploy to Gitlab Pages - to be run only by forks
pages:
Jacek Lebioda's avatar
Jacek Lebioda committed
111
  image: alpine:3.11.3
112
  stage: deploy
Jacek Lebioda's avatar
Jacek Lebioda committed
113
  rules:
114
    - if: '$CI_PROJECT_NAMESPACE != "R3" && $CI_PROJECT_NAMESPACE != "R3-core"'
115
    - if: $CI_MERGE_REQUEST_ID
116
  script:
117
    - mv processed_build public
118
  artifacts:
119
    expire_in: 1 week
120
    paths:
121
      - public
Jacek Lebioda's avatar
Jacek Lebioda committed
122
123

## Deploys the website to a separate VM
124
deploy:vm:
Jacek Lebioda's avatar
Jacek Lebioda committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
  stage: deploy
  image: alpine:3.1
  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:
    - if: '$CI_COMMIT_BRANCH == "develop" && $CI_PROJECT_PATH == "R3/howto-cards"'
    - if: '$CI_COMMIT_BRANCH == "master" && $CI_PROJECT_PATH == "R3/howto-cards"'
  script:
Jacek Lebioda's avatar
Jacek Lebioda committed
139
    - ssh -p $SSHPORT $SSHCONNECT "mkdir -p ~/$CI_COMMIT_BRANCH/sources/public/$CI_JOB_ID ~/$CI_COMMIT_BRANCH/public"
140
    - scp -P $SSHPORT -r processed_build/* $SSHCONNECT:~/$CI_COMMIT_BRANCH/sources/public/$CI_JOB_ID
Jacek Lebioda's avatar
Jacek Lebioda committed
141
    - ssh -p $SSHPORT $SSHCONNECT "cd ~/$CI_COMMIT_BRANCH/public && ln -fs ../sources/public/$CI_JOB_ID/* . && cd ~/$CI_COMMIT_BRANCH/sources/public/ && find . -type d -not -newermt '-1 minutes' -exec rm -rf {} +;"
Jacek Lebioda's avatar
Jacek Lebioda committed
142