Skip to content
Snippets Groups Projects
.gitlab-ci.yml 2.81 KiB
Newer Older
# In case something goes horribly wrong, you can fall back to `image: ruby:2.5`
image: git-r3lab.uni.lu:4567/r3/docker/jekyll-lcsb:1.4
Jacek Lebioda's avatar
Jacek Lebioda committed
stages:
  - build
  - generate_index
  - deploy

build_pages:
  stage: build
  variables:
    JEKYLL_ENV: production
    BUNDLER_VERSION: 2.0.2
Jacek Lebioda's avatar
Jacek Lebioda committed
  artifacts:
    expire_in: 1 day
    paths:
      - build
  before_script:
    - gem install bundler:$BUNDLER_VERSION && bundle install  
  script:
    # Generate the configuration for forks (will use Gitlab Pages on personal namespaces)
    - 'echo "url: https://$CI_PROJECT_NAMESPACE.$CI_PAGES_DOMAIN\nbaseurl: /$CI_PROJECT_NAME" >> _config_gitlab_pages.yml'

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

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

    # Run Jekyll with custom configuration
    - bundle exec jekyll build -d build --config "_config.yml,_config_$CI_COMMIT_REF_NAME.yml"
Jacek Lebioda's avatar
Jacek Lebioda committed

generate the search index:
  stage: generate_index
  image: node:13.8.0-slim
  variables:
    LUNR_VERSION: 2.3.8
    DIRECTORY: build
Jacek Lebioda's avatar
Jacek Lebioda committed
  script:
    - bash .ci/build_indices.sh
    - mv build processed_build
  artifacts:
    expire_in: 1 day
    paths:
      - processed_build
# Deploy to Gitlab Pages - to be run only by forks
Jacek Lebioda's avatar
Jacek Lebioda committed
  image: alpine:3.11.3
Jacek Lebioda's avatar
Jacek Lebioda committed
  rules:
    - if: '$CI_PROJECT_NAMESPACE != "R3" && $CI_PROJECT_NAMESPACE != "R3-core"'
    # For safety reasons:
    - sleep 3600 && exit -1
    - mv processed_buildXXXXX publicXXXX
    expire_in: 1 week

## Deploys the website to a separate VM
Deploy to production:
  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"'
    - if: '$CI_COMMIT_BRANCH == "16-deploy-to-staticpages-vm"'
  script:
    # Disable that for now
    - sleep 3600 && exit -1
    - ssh -p $SSHPORT $SSHCONNECT "mkdir -p ~/sources/$CI_COMMIT_BRANCH/$CI_JOB_ID ~/master ~/develop"
    - scp -P $SSHPORT -r processed_build/* $SSHCONNECT:~/sources/public/web_$CI_JOB_ID
    - ssh -p $SSHPORT $SSHCONNECT "cd ~/master && ln -fs ~/sources/public/web_$CI_JOB_ID/* . && cd ~/sources/public/ && find . -type d -not -newermt '-1 minutes' -exec rm -rf {} +;"