.gitlab-ci.yml 3.99 KB
Newer Older
Benni Mack's avatar
Benni Mack committed
1
stages:
2
  - maintenance
Benni Mack's avatar
Benni Mack committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  - lint
  - build
  - build-frontend
  - deploy

variables:
  ssh_hosts: "demo01.typo3server.ch"
  build_frontend_path: "src/webpack"
  # see https://getcomposer.org/doc/03-cli.md#composer-cache-dir
  COMPOSER_CACHE_DIR: ".composer-cache"
  composer_options:  "--no-progress --no-interaction"

# These files/folders are untracked, but should be kept between stages
cache:
  key: composer-cache-files
  paths:
    - "$COMPOSER_CACHE_DIR"
    - "$build_frontend_path/node_modules"

# Runs tests, currently it runs phpstan + php-cs-fixer
code-analysis:php:
  stage: lint
25
  image: composer:2.2
Benni Mack's avatar
Benni Mack committed
26
  before_script:
Benni Mack's avatar
Benni Mack committed
27
    - composer install $composer_options
Benni Mack's avatar
Benni Mack committed
28
29
  script:
    - if [ -e bin/phpstan ]; then php -d memory_limit=2G ./bin/phpstan analyse; fi
Benni Mack's avatar
Benni Mack committed
30
    - if [ -e bin/php-cs-fixer ]; then php -d memory_limit=2G ./bin/php-cs-fixer fix -v --dry-run --stop-on-violation --using-cache=no; fi
Benni Mack's avatar
Benni Mack committed
31
32
33
34
35


# Builds the artifacts for the production system (composer first)
build:php:
  stage: build
36
  image: composer:2.2
Benni Mack's avatar
Benni Mack committed
37
  script:
Benni Mack's avatar
Benni Mack committed
38
    - composer install --no-dev -o -a $composer_options
Benni Mack's avatar
Benni Mack committed
39
40
41
42
43
44
45
46
47
48
49
50
  artifacts:
    paths:
      - bin
      - web
      - src
      - config
      - vendor
      # needed to have the deployer tool available
      - build
    expire_in: '2h'
  only:
    - tags
51
    - main
52
    - develop
Benni Mack's avatar
Benni Mack committed
53
54
55
56

# compile and build JS / CSS
# should be used in conjunction with an artifact
.frontend_bootstrap: &frontend-bootstrap
57
  image: node:14.16-buster
Benni Mack's avatar
Benni Mack committed
58
59
60
61
62
63
64
  variables:
    node_path: src/webpack
  script:
    - cd $build_frontend_path
    - yarn install
    - yarn build-prod

65
66

.prepare_ssh: &prepare-ssh
Benni Mack's avatar
Benni Mack committed
67
68
69
70
71
72
73
  before_script:
    - apk add rsync --update
    - eval $(ssh-agent -s)
    - echo -e "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
    - mkdir -p ~/.ssh && chmod 700 ~/.ssh
    - ssh-keyscan "$ssh_hosts" >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
74
75
76
77

# rsyncs the artifacts to the target server via deployer
.deploy: &deploy
  <<: *prepare-ssh
78
79
  # deployer does not work with composer2.2 for the time being
  image: composer:2.0.8
80
81
82
83
  variables:
    # no git needed, only the artifacts are required
    GIT_STRATEGY: none
    TARGET_HOSTS: ""
Benni Mack's avatar
Benni Mack committed
84
  script:
85
    - composer global require deployer/deployer:6.8.0 deployer/recipes:6.2.2 --dev $composer_options
Benni Mack's avatar
Benni Mack committed
86
87
88
89
90
91
92
93
94
95
    - /tmp/vendor/bin/dep --file=./build/deploy.php deploy -vv --hosts=${TARGET_HOSTS}


# In the future, it would be great if this build step could run at the same time as the PHP build, which is not possible
# due to some dependencies from composer
build-frontend:
  <<: *frontend-bootstrap
  stage: build-frontend
  artifacts:
    paths:
96
      - bin
Benni Mack's avatar
Benni Mack committed
97
      - web
98
99
100
101
102
      - src
      - config
      - vendor
      # needed to have the deployer tool available
      - build
Benni Mack's avatar
Benni Mack committed
103
104
105
    expire_in: '2h'
  only:
    - tags
106
    - main
107
    - develop
Benni Mack's avatar
Benni Mack committed
108
109
110
111
112
113
114
115

deploy:production:
  <<: *deploy
  stage: deploy
  variables:
    TARGET_HOSTS: "main,contentmaster"
  only:
    - tags
116
    - main
117
118
  dependencies:
    - build-frontend
Benni Mack's avatar
Benni Mack committed
119
120
121
122
123
124
125
126

deploy:staging:
  <<: *deploy
  stage: deploy
  variables:
    TARGET_HOSTS: "staging"
  only:
    - develop
127
128
129
130

# Download database and fileadmin
Get dump for Content Master:
  <<: *prepare-ssh
131
  image: composer:2.2
132
  when: manual
133
  variables:
Jochen Roth's avatar
Jochen Roth committed
134
    GITLAB_RELEASE_VERSION: "1.0.0"
Jochen Roth's avatar
Jochen Roth committed
135
    PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/"
136
137
138
  stage: maintenance
  script:
    - mkdir dump
139
    - ssh demo-content@demo01.typo3server.ch -vvv "php ./content.demo.typo3.org/current/bin/typo3cms database:export -c Default -e 'cache_*' -e '[bf]e_sessions' -e 'be_users' -e 'sys_log' -e 'sys_history' -e 'sys_refindex' | gzip -9 -c" > ./dump/dump.sql.gz
140
    - rsync -avz --exclude='_processed_' demo-content@demo01.typo3server.ch:~/content.demo.typo3.org/shared/web/fileadmin/ ./dump/fileadmin
141
142
    - zip -r demo-data.zip dump
    - |
Jochen Roth's avatar
Jochen Roth committed
143
144
145
      curl --request DELETE --header "JOB-TOKEN: ${CI_JOB_TOKEN}" ${PACKAGE_REGISTRY_URL}/1
    - |
      curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ./demo-data.zip ${PACKAGE_REGISTRY_URL}/generic/site/${GITLAB_RELEASE_VERSION}/demo-data.zip