.gitlab-ci.yml 7.29 KB
Newer Older
rinpatch's avatar
rinpatch committed
1
image: elixir:1.8.1
lain's avatar
lain committed
2

3
variables: &global_variables
lain's avatar
lain committed
4
  POSTGRES_DB: pleroma_test
Roger Braun's avatar
Roger Braun committed
5
6
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: postgres
lain's avatar
lain committed
7
  DB_HOST: postgres
8
  MIX_ENV: test
9

10
cache: &global_cache_policy
11
  key: ${CI_COMMIT_REF_SLUG}
rinpatch's avatar
rinpatch committed
12
13
  paths:
          - deps
Rin Toshaka's avatar
Rin Toshaka committed
14
          - _build
lain's avatar
lain committed
15
stages:
16
  - build
lain's avatar
lain committed
17
  - test
lain's avatar
lain committed
18
  - benchmark
19
  - deploy
rinpatch's avatar
rinpatch committed
20
  - release
lain's avatar
lain committed
21
22

before_script:
lain's avatar
lain committed
23
24
  - mix local.hex --force
  - mix local.rebar --force
lain's avatar
lain committed
25

26
27
build:
  stage: build
lain's avatar
lain committed
28
  script:
rinpatch's avatar
huh    
rinpatch committed
29
  - mix deps.get
30
  - mix compile --force
rinpatch's avatar
rinpatch committed
31

lain's avatar
lain committed
32
33
benchmark:
  stage: benchmark
lain's avatar
lain committed
34
  when: manual
lain's avatar
lain committed
35
36
37
  variables:
    MIX_ENV: benchmark
  services:
38
  - name: postgres:9.6
lain's avatar
lain committed
39
40
41
42
43
44
    alias: postgres
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
  script:
    - mix deps.get
    - mix ecto.create
    - mix ecto.migrate
lain's avatar
lain committed
45
    - mix pleroma.load_testing
rinpatch's avatar
rinpatch committed
46

47
48
unit-testing:
  stage: test
49
50
51
52
  cache: &testing_cache_policy
    <<: *global_cache_policy
    policy: pull

53
  services:
54
  - name: postgres:9.6
55
    alias: postgres
56
57
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
  script:
58
    - mix deps.get
59
60
    - mix ecto.create
    - mix ecto.migrate
rinpatch's avatar
rinpatch committed
61
    - mix coveralls --preload-modules
62

63
64
federated-testing:
  stage: test
65
  cache: *testing_cache_policy
66
  services:
67
  - name: minibikini/postgres-with-rum:12
68
69
70
71
72
73
    alias: postgres
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
  script:
    - mix deps.get
    - mix ecto.create
    - mix ecto.migrate
lain's avatar
lain committed
74
    - epmd -daemon
75
76
    - mix test --trace --only federated

lain's avatar
lain committed
77
unit-testing-rum:
78
  stage: test
79
  cache: *testing_cache_policy
lain's avatar
lain committed
80
  services:
81
  - name: minibikini/postgres-with-rum:12
82
    alias: postgres
lain's avatar
lain committed
83
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
84
  variables:
85
    <<: *global_variables
86
    RUM_ENABLED: "true"
lain's avatar
lain committed
87
88
89
90
91
  script:
    - mix deps.get
    - mix ecto.create
    - mix ecto.migrate
    - "mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/"
rinpatch's avatar
rinpatch committed
92
    - mix test --preload-modules
lain's avatar
lain committed
93

94
95
lint:
  stage: test
96
  cache: *testing_cache_policy
97
98
99
100
101
  script:
    - mix format --check-formatted

analysis:
  stage: test
102
  cache: *testing_cache_policy
103
  script:
rinpatch's avatar
rinpatch committed
104
    - mix deps.get
105
106
    - mix credo --strict --only=warnings,todo,fixme,consistency,readability

107
docs-deploy:
108
  stage: deploy
109
  cache: *testing_cache_policy
110
  image: alpine:latest
rinpatch's avatar
rinpatch committed
111
  only:
112
  - stable@pleroma/pleroma
rinpatch's avatar
rinpatch committed
113
114
  - develop@pleroma/pleroma
  before_script:
115
  - apk add curl
rinpatch's avatar
rinpatch committed
116
  script:
117
  - curl -X POST -F"token=$DOCS_PIPELINE_TRIGGER" -F'ref=master' -F"variables[BRANCH]=$CI_COMMIT_REF_NAME" https://git.pleroma.social/api/v4/projects/673/trigger/pipeline
lain's avatar
lain committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
review_app:
  image: alpine:3.9
  stage: deploy
  before_script:
    - apk update && apk add openssh-client git
  when: manual
  environment:
    name: review/$CI_COMMIT_REF_NAME
    url: https://$CI_ENVIRONMENT_SLUG.pleroma.online/
    on_stop: stop_review_app
  only:
    - branches
  except:
    - master
    - develop
  script:
    - echo "$CI_ENVIRONMENT_SLUG"
    - mkdir -p ~/.ssh
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
    - (ssh -t dokku@pleroma.online -- apps:create "$CI_ENVIRONMENT_SLUG") || true
140
    - (ssh -t dokku@pleroma.online -- git:set "$CI_ENVIRONMENT_SLUG" keep-git-dir true) || true
lain's avatar
lain committed
141
142
143
144
    - ssh -t dokku@pleroma.online -- config:set "$CI_ENVIRONMENT_SLUG" APP_NAME="$CI_ENVIRONMENT_SLUG" APP_HOST="$CI_ENVIRONMENT_SLUG.pleroma.online" MIX_ENV=dokku
    - (ssh -t dokku@pleroma.online -- postgres:create $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db) || true
    - (ssh -t dokku@pleroma.online -- postgres:link $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db "$CI_ENVIRONMENT_SLUG") || true
    - (ssh -t dokku@pleroma.online -- certs:add "$CI_ENVIRONMENT_SLUG" /home/dokku/server.crt /home/dokku/server.key) || true
lain's avatar
lain committed
145
    - git push -f dokku@pleroma.online:$CI_ENVIRONMENT_SLUG $CI_COMMIT_SHA:refs/heads/master
lain's avatar
lain committed
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

stop_review_app:
  image: alpine:3.9
  stage: deploy
  before_script:
    - apk update && apk add openssh-client git
  when: manual
  environment:
    name: review/$CI_COMMIT_REF_NAME
    action: stop
  script:
    - echo "$CI_ENVIRONMENT_SLUG"
    - mkdir -p ~/.ssh
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
    - ssh -t dokku@pleroma.online -- --force apps:destroy "$CI_ENVIRONMENT_SLUG"
    - ssh -t dokku@pleroma.online -- --force postgres:destroy $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db
rinpatch's avatar
rinpatch committed
164
165

amd64:
166
  stage: release
rinpatch's avatar
rinpatch committed
167
168
169
  # TODO: Replace with upstream image when 1.9.0 comes out
  image: rinpatch/elixir:1.9.0-rc.0
  only: &release-only
170
  - stable@pleroma/pleroma
rinpatch's avatar
rinpatch committed
171
  - develop@pleroma/pleroma
172
  - /^maint/.*$/@pleroma/pleroma
173
  - /^release/.*$/@pleroma/pleroma
rinpatch's avatar
rinpatch committed
174
175
176
177
  artifacts: &release-artifacts
    name: "pleroma-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
    paths:
      - release/*
rinpatch's avatar
rinpatch committed
178
179
180
181
182
183
    # Ideally it would be never for master branch and with the next commit for develop,
    # but Gitlab does not support neither `only` for artifacts
    # nor setting it to never from .gitlab-ci.yml
    # nor expiring with the next commit
    expire_in: 42 yrs

rinpatch's avatar
rinpatch committed
184
185
186
187
188
189
190
191
192
193
194
195
196
  cache: &release-cache
    key: $CI_COMMIT_REF_NAME-$CI_JOB_NAME
    paths:
          - deps
  variables: &release-variables
    MIX_ENV: prod
  before_script: &before-release
  - echo "import Mix.Config" > config/prod.secret.exs
  - mix local.hex --force
  - mix local.rebar --force
  script: &release
    - mix deps.get --only prod
    - mkdir release
rinpatch's avatar
rinpatch committed
197
    - export PLEROMA_BUILD_BRANCH=$CI_COMMIT_REF_NAME
rinpatch's avatar
rinpatch committed
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
    - mix release --path release


amd64-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  # TODO: Replace with upstream image when 1.9.0 comes out
  image: rinpatch/elixir:1.9.0-rc.0-alpine
  cache: *release-cache
  variables: *release-variables
  before_script: &before-release-musl
  - apk add git gcc g++ musl-dev make
  - echo "import Mix.Config" > config/prod.secret.exs
  - mix local.hex --force
  - mix local.rebar --force
  script: *release

arm:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm32
  # TODO: Replace with upstream image when 1.9.0 comes out
  image: rinpatch/elixir:1.9.0-rc.0-arm
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release
  script: *release

arm-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm32
  # TODO: Replace with upstream image when 1.9.0 comes out
  image: rinpatch/elixir:1.9.0-rc.0-arm-alpine
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release-musl
  script: *release

arm64:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm
  # TODO: Replace with upstream image when 1.9.0 comes out
  image: rinpatch/elixir:1.9.0-rc.0-arm64
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release
  script: *release

arm64-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm
  # TODO: Replace with upstream image when 1.9.0 comes out
  image: rinpatch/elixir:1.9.0-rc.0-arm64-alpine
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release-musl
  script: *release