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

Jacek Lebioda's avatar
Jacek Lebioda committed
4
5
6
7
8
stages:
  - build
  - deploy
  - backup

9
10
11
12
13
14
build the website:
  stage: build
  before_script:
  - gem install bundler -v2.0.2
  - bundle install && bundle update jekyll-theme-lcsb-default && bundle update jekyll-theme-lcsb-frozen-components
  script:
15
  - bundle exec jekyll build -d build --config "_config.yml,_config_staticpages.yml"
16
17
18
19
20
21
22
  - 'echo $CI_COMMIT_SHA > build/version'
  artifacts:
    expire_in: 3 days
    paths:
    - build
  variables:
    JEKYLL_ENV: production
Christophe Trefois's avatar
Christophe Trefois committed
23

24
25
26

## Deploys the website to a separate VM
Deploy to production:
Christophe Trefois's avatar
Christophe Trefois committed
27
  stage: deploy
28
29
30
31
32
33
34
35
36
  image: alpine:3.1
  before_script:
    - 'which ssh-agent || ( apk add --update openssh )'
    - eval $(ssh-agent -s)
    - echo "$SSHPRIVKEY" | 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
Christophe Trefois's avatar
Christophe Trefois committed
37
  script:
38
    # don't forget to create ~/web/latest folder manually in the initial configuration on the VM!
39
40
    - ssh -p $SSHPORT $SSHCONNECT "mkdir -p ~/web/r3lab_$CI_JOB_ID"
    - scp -P $SSHPORT -r build/* $SSHCONNECT:~/web/r3lab_$CI_JOB_ID
41
    - ssh -p $SSHPORT $SSHCONNECT "cd ~/web/latest && ln -fs ../r3lab_$CI_JOB_ID/* . && cd .. && find . -type d -name 'r3lab*' -not -newermt '-1 minutes' -exec rm -rf {} +"
Jacek Lebioda's avatar
Jacek Lebioda committed
42
43
44
45
46
47


## Backups
Create the backup:
  stage: backup
  image: alpine:3.1
Jacek Lebioda's avatar
Jacek Lebioda committed
48
49
  only:
    - schedules
Jacek Lebioda's avatar
Jacek Lebioda committed
50
51
52
53
54
55
56
57
58
59
  before_script:
    - 'which ssh-agent || ( apk add --update openssh )'
    - eval $(ssh-agent -s)
    - echo "$SSHPRIVKEY" | 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
  script:
    - ssh -p $SSHPORT $SSHCONNECT "mkdir -p ~/web/latest ~/backups/; cd ~/web/; tar -zchvf ~/backups/backup_$(date +'%Y_%m_%d').tar.gz latest"