.gitlab-ci.yml 2.28 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
42
    # Make a symbolic link to newly copied files, then remove old tasks' files, and remove all broken symbolic links
    - 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 {} + && find -L ~/web/latest -type l -delete"
Jacek Lebioda's avatar
Jacek Lebioda committed
43
44
45
46
47
48


## Backups
Create the backup:
  stage: backup
  image: alpine:3.1
Jacek Lebioda's avatar
Jacek Lebioda committed
49
50
  only:
    - schedules
Jacek Lebioda's avatar
Jacek Lebioda committed
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:
60
61
    - ssh -p $SSHPORT $SSHCONNECT "mkdir -p ~/web ~/backups/; cd; tar -zcvf ~/backups/backup_$(date +'%Y_%m_%d').tar.gz web"
    - ssh -p $SSHPORT $SSHCONNECT "cd ~/backups/; ls -tr | head -n -3 | xargs --no-run-if-empty rm "