.gitlab-ci.yml 4.57 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 5 6 7 8
stages:
  - build
  - generate_index
  - deploy

Jacek Lebioda's avatar
Jacek Lebioda committed
9 10 11
# !!!!!!!      README      !!!!!
# We are in the transition period - and the website is deployed two times - to gitlab pages and to a separate VM
# In order to migrate to a new deployment:
Jacek Lebioda's avatar
Jacek Lebioda committed
12 13
#  1) remove "Old deployment" section - build_pages, generate the search index and pages tasks
#  2) rename "new pages" to "pages" in the new deployment section, and "new_public" to "public"; you might also rename directories (skip "new" part)
Jacek Lebioda's avatar
Jacek Lebioda committed
14 15 16 17 18
#  3) remove ".ci/deploy.sh", ".ci/build_indices.sh"


# Old deployment =================================================================

Jacek Lebioda's avatar
Jacek Lebioda committed
19 20
build_pages:
  stage: build
Jacek Lebioda's avatar
Jacek Lebioda committed
21 22 23
  before_script:
    - apt-get -qq update
    - apt-get install -y -qq git-lfs
24
    - gem install bundler:2.0.2 && bundle install
Jacek Lebioda's avatar
Jacek Lebioda committed
25 26
  script:
    - bash .ci/deploy.sh
Jacek Lebioda's avatar
Jacek Lebioda committed
27 28 29 30 31 32
  variables:
    JEKYLL_ENV: production
  artifacts:
    expire_in: 1 day
    paths:
      - build
Jacek Lebioda's avatar
Jacek Lebioda committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73


generate the search index:
  stage: generate_index
  image: node:13.8.0-slim
  rules:
    - if: $CI_COMMIT_BRANCH == "master"
    - if: $CI_COMMIT_BRANCH == "develop"
  script:
    - bash .ci/build_indices.sh
    - mv build processed_build
  artifacts:
    expire_in: 1 day
    paths:
      - processed_build

pages:
  image: alpine:3.11.3
  stage: deploy
  rules:
    - if: $CI_COMMIT_BRANCH == "master"
    - if: $CI_COMMIT_BRANCH == "develop"
  script:
    - mv processed_build public
  artifacts:
    expire_in: 1 week
    paths:
      - public


# New deployment ==================================================================

build pages for VM deployment:
  stage: build
  variables:
    JEKYLL_ENV: production
    BUNDLER_VERSION: 2.0.2
  artifacts:
    expire_in: 1 day
    paths:
      - new_build
74 75 76
  rules:
    - if: $CI_COMMIT_BRANCH
    - 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
Jacek Lebioda's avatar
Jacek Lebioda committed
93
    - bundle exec jekyll build -d new_build --config "_config.yml,.ci/_config_$CI_COMMIT_REF_NAME.yml"
94

Jacek Lebioda's avatar
Jacek Lebioda committed
95

Jacek Lebioda's avatar
Jacek Lebioda committed
96
generate the search index for VM deployment:
Jacek Lebioda's avatar
Jacek Lebioda committed
97 98
  stage: generate_index
  image: node:13.8.0-slim
99 100
  variables:
    LUNR_VERSION: 2.3.8
Jacek Lebioda's avatar
Jacek Lebioda committed
101
    DIRECTORY: new_build
Jacek Lebioda's avatar
Jacek Lebioda committed
102
  script:
Jacek Lebioda's avatar
Jacek Lebioda committed
103
    - bash .ci/build_indices_new.sh
Jacek Lebioda's avatar
Jacek Lebioda committed
104
    - mv new_build new_processed_build
105 106 107
  rules:
    - if: $CI_COMMIT_BRANCH
    - if: $CI_MERGE_REQUEST_ID
Jacek Lebioda's avatar
Jacek Lebioda committed
108 109 110
  artifacts:
    expire_in: 1 day
    paths:
Jacek Lebioda's avatar
Jacek Lebioda committed
111
      - new_processed_build
112

Jacek Lebioda's avatar
Jacek Lebioda committed
113 114
# Deploy to Gitlab Pages - to be run only by forks; change to pages once it's ready
new pages:
Jacek Lebioda's avatar
Jacek Lebioda committed
115
  image: alpine:3.11.3
116
  stage: deploy
Jacek Lebioda's avatar
Jacek Lebioda committed
117
  rules:
118
    - if: '$CI_PROJECT_NAMESPACE != "R3" && $CI_PROJECT_NAMESPACE != "R3-core"'
119
    - if: $CI_MERGE_REQUEST_ID
120
  script:
Jacek Lebioda's avatar
Jacek Lebioda committed
121
    - mv new_processed_build new_public
122
  artifacts:
123
    expire_in: 1 week
124
    paths:
Jacek Lebioda's avatar
Jacek Lebioda committed
125
      - new_public
Jacek Lebioda's avatar
Jacek Lebioda committed
126 127

## Deploys the website to a separate VM
Jacek Lebioda's avatar
Jacek Lebioda committed
128
deploy to production:
Jacek Lebioda's avatar
Jacek Lebioda committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142
  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
143 144 145
    - ssh -p $SSHPORT $SSHCONNECT "mkdir -p ~/$CI_COMMIT_BRANCH/sources/public/$CI_JOB_ID ~/$CI_COMMIT_BRANCH/public"
    - scp -P $SSHPORT -r new_processed_build/* $SSHCONNECT:~/$CI_COMMIT_BRANCH/sources/public/$CI_JOB_ID
    - 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
146