.gitlab-ci.yml 2.24 KB
Newer Older
David Hrbáč's avatar
David Hrbáč committed
1 2 3 4 5 6
stages:
  - test
  - build
  - deploy
  - production

Lukáš Krupčík's avatar
Lukáš Krupčík committed
7 8 9 10 11
docs:
  stage: test
  image: davidhrbac/docker-mdcheck:latest
  allow_failure: true
  script:
David Hrbáč's avatar
David Hrbáč committed
12
  - mdl -r ~MD013 *.md docs.it4i/
Lukáš Krupčík's avatar
Lukáš Krupčík committed
13

David Hrbáč's avatar
David Hrbáč committed
14
mkdocs:
David Hrbáč's avatar
David Hrbáč committed
15
  stage: build
David Hrbáč's avatar
David Hrbáč committed
16 17 18
  image: davidhrbac/docker-mkdocscheck:latest
  script:
  - mkdocs build
David Hrbáč's avatar
David Hrbáč committed
19 20 21 22
  artifacts:
    paths:
    - site
    expire_in: 1 week
David Hrbáč's avatar
David Hrbáč committed
23

Lukáš Krupčík's avatar
Lukáš Krupčík committed
24 25 26
shellcheck:
  stage: test
  image: davidhrbac/docker-shellcheck:latest
David Hrbáč's avatar
David Hrbáč committed
27
  allow_failure: true
Lukáš Krupčík's avatar
Lukáš Krupčík committed
28 29 30
  script:
  - which shellcheck || apt-get update && apt-get install -y shellcheck
  - shellcheck *.sh
David Hrbáč's avatar
David Hrbáč committed
31

David Hrbáč's avatar
David Hrbáč committed
32 33 34 35
deploy to stage:
  environment: stage 
  stage: deploy
  image: ruby:latest
David Hrbáč's avatar
David Hrbáč committed
36 37 38
  before_script:
  # install ssh-agent 
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
David Hrbáč's avatar
David Hrbáč committed
39
  - 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
David Hrbáč's avatar
David Hrbáč committed
40 41 42 43 44 45
  # run ssh-agent
  - eval $(ssh-agent -s)
  # add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
  - ssh-add <(echo "$SSH_PRIVATE_KEY")
  # disable host key checking (NOTE: makes you susceptible to man-in-the-middle attacks)
  # WARNING: use only in docker container, if you use it with shell you will overwrite your user's ssh config
David Hrbáč's avatar
David Hrbáč committed
46
  - mkdir -p ~/.ssh
David Hrbáč's avatar
David Hrbáč committed
47
  - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
David Hrbáč's avatar
David Hrbáč committed
48
  - useradd -lM nginx
David Hrbáč's avatar
David Hrbáč committed
49
  script:
David Hrbáč's avatar
David Hrbáč committed
50
  - chown nginx:nginx site -R
David Hrbáč's avatar
David Hrbáč committed
51
  - rsync -av --delete site/ root@"$SSH_HOST_STAGE":/srv/docs.it4i.cz/devel/$CI_BUILD_REF_NAME/
David Hrbáč's avatar
David Hrbáč committed
52

David Hrbáč's avatar
David Hrbáč committed
53 54 55 56
deploy to production:
  environment: production
  stage: deploy
  image: ruby:latest
David Hrbáč's avatar
David Hrbáč committed
57 58 59 60 61 62 63 64 65 66 67 68
  before_script:
  # install ssh-agent 
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
  - 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
  # run ssh-agent
  - eval $(ssh-agent -s)
  # add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
  - ssh-add <(echo "$SSH_PRIVATE_KEY")
  # disable host key checking (NOTE: makes you susceptible to man-in-the-middle attacks)
  # WARNING: use only in docker container, if you use it with shell you will overwrite your user's ssh config
  - mkdir -p ~/.ssh
  - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config 
David Hrbáč's avatar
David Hrbáč committed
69
  - useradd -lM nginx
David Hrbáč's avatar
David Hrbáč committed
70
  script:
David Hrbáč's avatar
David Hrbáč committed
71
  - chown nginx:nginx site -R
David Hrbáč's avatar
David Hrbáč committed
72
  - rsync -av --delete site/ root@"$SSH_HOST_STAGE":/srv/docs.it4i.cz/site/
David Hrbáč's avatar
David Hrbáč committed
73 74 75
  only:
  - master
  when: manual