Export PLEROMA_BUILD_BRANCH
[akkoma] / .gitlab-ci.yml
1 image: elixir:1.8.1
2
3 variables:
4 POSTGRES_DB: pleroma_test
5 POSTGRES_USER: postgres
6 POSTGRES_PASSWORD: postgres
7 DB_HOST: postgres
8 MIX_ENV: test
9
10 cache:
11 key: ${CI_COMMIT_REF_SLUG}
12 paths:
13 - deps
14 - _build
15 stages:
16 - build
17 - test
18 - deploy
19 - release
20
21 before_script:
22 - mix local.hex --force
23 - mix local.rebar --force
24
25 build:
26 stage: build
27 script:
28 - mix deps.get
29 - mix compile --force
30
31 docs-build:
32 stage: build
33 only:
34 - master@pleroma/pleroma
35 - develop@pleroma/pleroma
36 variables:
37 MIX_ENV: dev
38 script:
39 - mix deps.get
40 - mix compile
41 - mix docs
42 artifacts:
43 paths:
44 - priv/static/doc
45
46
47 unit-testing:
48 stage: test
49 services:
50 - name: lainsoykaf/postgres-with-rum
51 alias: postgres
52 command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
53 script:
54 - mix deps.get
55 - mix ecto.create
56 - mix ecto.migrate
57 - mix coveralls --trace --preload-modules
58
59 unit-testing-rum:
60 stage: test
61 services:
62 - name: lainsoykaf/postgres-with-rum
63 alias: postgres
64 command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
65 variables:
66 RUM_ENABLED: "true"
67 script:
68 - mix deps.get
69 - mix ecto.create
70 - mix ecto.migrate
71 - "mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/"
72 - mix test --trace --preload-modules
73
74 lint:
75 stage: test
76 script:
77 - mix format --check-formatted
78
79 analysis:
80 stage: test
81 script:
82 - mix deps.get
83 - mix credo --strict --only=warnings,todo,fixme,consistency,readability
84
85 docs-deploy:
86 stage: deploy
87 image: alpine:3.9
88 only:
89 - master@pleroma/pleroma
90 - develop@pleroma/pleroma
91 before_script:
92 - apk update && apk add openssh-client rsync
93 script:
94 - mkdir -p ~/.ssh
95 - echo "${SSH_HOST_KEY}" > ~/.ssh/known_hosts
96 - eval $(ssh-agent -s)
97 - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
98 - rsync -hrvz --delete -e "ssh -p ${SSH_PORT}" priv/static/doc/ "${SSH_USER_HOST_LOCATION}/${CI_COMMIT_REF_NAME}"
99
100 review_app:
101 image: alpine:3.9
102 stage: deploy
103 before_script:
104 - apk update && apk add openssh-client git
105 when: manual
106 environment:
107 name: review/$CI_COMMIT_REF_NAME
108 url: https://$CI_ENVIRONMENT_SLUG.pleroma.online/
109 on_stop: stop_review_app
110 only:
111 - branches
112 except:
113 - master
114 - develop
115 script:
116 - echo "$CI_ENVIRONMENT_SLUG"
117 - mkdir -p ~/.ssh
118 - eval $(ssh-agent -s)
119 - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
120 - ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
121 - (ssh -t dokku@pleroma.online -- apps:create "$CI_ENVIRONMENT_SLUG") || true
122 - 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
123 - (ssh -t dokku@pleroma.online -- postgres:create $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db) || true
124 - (ssh -t dokku@pleroma.online -- postgres:link $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db "$CI_ENVIRONMENT_SLUG") || true
125 - (ssh -t dokku@pleroma.online -- certs:add "$CI_ENVIRONMENT_SLUG" /home/dokku/server.crt /home/dokku/server.key) || true
126 - git push -f dokku@pleroma.online:$CI_ENVIRONMENT_SLUG $CI_COMMIT_SHA:refs/heads/master
127
128 stop_review_app:
129 image: alpine:3.9
130 stage: deploy
131 before_script:
132 - apk update && apk add openssh-client git
133 when: manual
134 environment:
135 name: review/$CI_COMMIT_REF_NAME
136 action: stop
137 script:
138 - echo "$CI_ENVIRONMENT_SLUG"
139 - mkdir -p ~/.ssh
140 - eval $(ssh-agent -s)
141 - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
142 - ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
143 - ssh -t dokku@pleroma.online -- --force apps:destroy "$CI_ENVIRONMENT_SLUG"
144 - ssh -t dokku@pleroma.online -- --force postgres:destroy $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db
145
146 amd64:
147 stage: release
148 # TODO: Replace with upstream image when 1.9.0 comes out
149 image: rinpatch/elixir:1.9.0-rc.0
150 only: &release-only
151 - master@pleroma/pleroma
152 - develop@pleroma/pleroma
153 artifacts: &release-artifacts
154 name: "pleroma-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
155 paths:
156 - release/*
157 # Ideally it would be never for master branch and with the next commit for develop,
158 # but Gitlab does not support neither `only` for artifacts
159 # nor setting it to never from .gitlab-ci.yml
160 # nor expiring with the next commit
161 expire_in: 42 yrs
162
163 cache: &release-cache
164 key: $CI_COMMIT_REF_NAME-$CI_JOB_NAME
165 paths:
166 - deps
167 variables: &release-variables
168 MIX_ENV: prod
169 before_script: &before-release
170 - echo "import Mix.Config" > config/prod.secret.exs
171 - mix local.hex --force
172 - mix local.rebar --force
173 script: &release
174 - mix deps.get --only prod
175 - mkdir release
176 - export PLEROMA_BUILD_BRANCH=$CI_COMMIT_REF_NAME
177 - mix release --path release
178
179
180 amd64-musl:
181 stage: release
182 artifacts: *release-artifacts
183 only: *release-only
184 # TODO: Replace with upstream image when 1.9.0 comes out
185 image: rinpatch/elixir:1.9.0-rc.0-alpine
186 cache: *release-cache
187 variables: *release-variables
188 before_script: &before-release-musl
189 - apk add git gcc g++ musl-dev make
190 - echo "import Mix.Config" > config/prod.secret.exs
191 - mix local.hex --force
192 - mix local.rebar --force
193 script: *release
194
195 arm:
196 stage: release
197 artifacts: *release-artifacts
198 only: *release-only
199 tags:
200 - arm32
201 # TODO: Replace with upstream image when 1.9.0 comes out
202 image: rinpatch/elixir:1.9.0-rc.0-arm
203 cache: *release-cache
204 variables: *release-variables
205 before_script: *before-release
206 script: *release
207
208 arm-musl:
209 stage: release
210 artifacts: *release-artifacts
211 only: *release-only
212 tags:
213 - arm32
214 # TODO: Replace with upstream image when 1.9.0 comes out
215 image: rinpatch/elixir:1.9.0-rc.0-arm-alpine
216 cache: *release-cache
217 variables: *release-variables
218 before_script: *before-release-musl
219 script: *release
220
221 arm64:
222 stage: release
223 artifacts: *release-artifacts
224 only: *release-only
225 tags:
226 - arm
227 # TODO: Replace with upstream image when 1.9.0 comes out
228 image: rinpatch/elixir:1.9.0-rc.0-arm64
229 cache: *release-cache
230 variables: *release-variables
231 before_script: *before-release
232 script: *release
233
234 arm64-musl:
235 stage: release
236 artifacts: *release-artifacts
237 only: *release-only
238 tags:
239 - arm
240 # TODO: Replace with upstream image when 1.9.0 comes out
241 image: rinpatch/elixir:1.9.0-rc.0-arm64-alpine
242 cache: *release-cache
243 variables: *release-variables
244 before_script: *before-release-musl
245 script: *release