.gitlab-ci.yml 2.4 KB
Newer Older
1
---
Simon's avatar
CI/CD  
Simon committed
2
stages:
3
  - lint
Simon's avatar
CI/CD  
Simon committed
4
  - build
Simon's avatar
Simon committed
5
  - deploy
Simon's avatar
CI/CD  
Simon committed
6
7
  - production

8
9
10
lint:
  stage: lint
  image:
Jan-Tarek Butt's avatar
Jan-Tarek Butt committed
11
    name: sdesbure/yamllint
12
13
14
  script:
    - ./.ci/yamllint.sh

Simon's avatar
CI/CD  
Simon committed
15
16
build:
  stage: build
Simon's avatar
Simon committed
17
  image:
Simon's avatar
Simon committed
18
    name: klakegg/hugo:ext-alpine
Simon's avatar
Simon committed
19
    entrypoint: ['']
20
  script:
Simon's avatar
Simon committed
21
    - hugo
22
23
24
25
  cache:
    key: ${CI_COMMIT_REF_SLUG}
    paths:
      - resources/
Simon's avatar
CI/CD  
Simon committed
26
27
  artifacts:
    paths:
28
      - public/
Simon's avatar
CI/CD  
Simon committed
29
30
    expire_in: 1 hour

Simon's avatar
Simon committed
31
32
deploy_review:
  stage: deploy
33
  image: instrumentisto/rsync-ssh
Simon's avatar
CI/CD  
Simon committed
34
35
36
  before_script:
    - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
37
    - echo "$SSH_PRIVATE_PRE" | base64 -d | tr -d '\r' | ssh-add -
Simon's avatar
CI/CD  
Simon committed
38
39
40
41
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  script:
Simon's avatar
Simon committed
42
    - echo "$SECRETS" > public/.env
43
    - rsync -av --delete public/ ffnw.de@ffnw.de:"$CI_ENVIRONMENT_SLUG"
Simon's avatar
CI/CD  
Simon committed
44
  environment:
45
    name: review/$CI_COMMIT_REF_NAME
Simon's avatar
Simon committed
46
    url: https://$CI_ENVIRONMENT_SLUG.pre.ffnw.de
Simon's avatar
CI/CD  
Simon committed
47
48
49
50
51
    on_stop: stop_review
  only:
    - branches

stop_review:
Simon's avatar
Simon committed
52
  stage: deploy
53
  image: instrumentisto/rsync-ssh
Simon's avatar
CI/CD  
Simon committed
54
55
56
  before_script:
    - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
57
    - echo "$SSH_PRIVATE_RM" | base64 -d | tr -d '\r' | ssh-add -
Simon's avatar
CI/CD  
Simon committed
58
59
60
61
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  script:
62
    - ssh ffnw.de@ffnw.de "$CI_ENVIRONMENT_SLUG"
Simon's avatar
CI/CD  
Simon committed
63
64
65
66
  variables:
    GIT_STRATEGY: none
  when: manual
  environment:
67
    name: review/$CI_COMMIT_REF_NAME
Simon's avatar
CI/CD  
Simon committed
68
69
    action: stop

Simon's avatar
Simon committed
70
production:
Simon's avatar
CI/CD  
Simon committed
71
  stage: production
72
  image: instrumentisto/rsync-ssh
Simon's avatar
CI/CD  
Simon committed
73
74
75
  before_script:
    - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
76
    - echo "$SSH_PRIVATE_PROD" | base64 -d | tr -d '\r' | ssh-add -
Simon's avatar
CI/CD  
Simon committed
77
78
79
80
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  script:
Simon's avatar
Simon committed
81
    - echo "$SECRETS" > public/.env
Simon's avatar
Simon committed
82
    - rsync -av --delete public/ ffnw.de@ffnw.de:""
Simon's avatar
CI/CD  
Simon committed
83
84
85
  environment:
    name: production
    url: https://ffnw.de
Simon's avatar
Simon committed
86
  allow_failure: true
Simon's avatar
Simon committed
87
88
89
90
91
92
  rules:
    - if: '$CI_COMMIT_BRANCH == "main" && $DEPLOY_PRODUCTION == "true"'
      when: always
    - if: '$CI_COMMIT_BRANCH == "main"'
      when: manual
    - when: never