You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

345 lines
9.1 KiB

  1. image: tcitworld/mobilizon-ci
  2. stages:
  3. - install
  4. - check
  5. - build-js
  6. - test
  7. - docker
  8. - package
  9. - upload
  10. - deploy
  11. variables:
  12. MIX_ENV: "test"
  13. YARN_CACHE_FOLDER: "js/.yarn"
  14. # DB Variables for Postgres / Postgis
  15. POSTGRES_DB: mobilizon_test
  16. POSTGRES_USER: postgres
  17. POSTGRES_PASSWORD: postgres
  18. POSTGRES_HOST: postgres
  19. # DB Variables for Mobilizon
  20. MOBILIZON_DATABASE_USERNAME: $POSTGRES_USER
  21. MOBILIZON_DATABASE_PASSWORD: $POSTGRES_PASSWORD
  22. MOBILIZON_DATABASE_DBNAME: $POSTGRES_DB
  23. MOBILIZON_DATABASE_HOST: $POSTGRES_HOST
  24. GEOLITE_CITIES_PATH: "/usr/share/GeoIP/GeoLite2-City.mmdb"
  25. MOBILIZON_INSTANCE_REGISTRATIONS_OPEN: "true"
  26. # Release elements
  27. PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}"
  28. ARCH: "amd64"
  29. EXPORT_FORMATS: "csv,ods,pdf"
  30. APP_VERSION: "${CI_COMMIT_REF_NAME}"
  31. APP_ASSET: "${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}_${ARCH}.tar.gz"
  32. CYPRESS_INSTALL_BINARY: 0
  33. cache:
  34. key: "${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHORT_SHA}"
  35. paths:
  36. - ~/.cache/Cypress
  37. - cache/Cypress
  38. - deps/
  39. - _build/
  40. - js/node_modules
  41. - js/.yarn
  42. # Installed dependencies are cached across the pipeline
  43. # So there is no need to reinstall them all the time
  44. # It saves minutes during a pipeline build time
  45. install:
  46. stage: install
  47. script:
  48. - yarn --cwd "js" install --frozen-lockfile
  49. - mix deps.get
  50. - mix compile
  51. lint-elixir:
  52. stage: check
  53. before_script:
  54. - mix deps.get
  55. script:
  56. - export EXITVALUE=0
  57. - mix format --check-formatted --dry-run || export EXITVALUE=1
  58. - mix credo --strict -a || export EXITVALUE=1
  59. - mix sobelow --config || export EXITVALUE=1
  60. - exit $EXITVALUE
  61. lint-front:
  62. image: node:16
  63. stage: check
  64. before_script:
  65. - export EXITVALUE=0
  66. - yarn --cwd "js" install --frozen-lockfile
  67. script:
  68. - yarn --cwd "js" run lint || export EXITVALUE=1
  69. - yarn --cwd "js" run prettier -c . || export EXITVALUE=1
  70. - exit $EXITVALUE
  71. build-frontend:
  72. stage: build-js
  73. image: node:16
  74. before_script:
  75. - apt update
  76. - apt install -y --no-install-recommends python build-essential webp imagemagick gifsicle jpegoptim optipng pngquant
  77. script:
  78. - yarn --cwd "js" install --frozen-lockfile
  79. - yarn --cwd "js" run build
  80. artifacts:
  81. expire_in: 5 days
  82. paths:
  83. - priv/static
  84. needs:
  85. - lint-front
  86. deps:
  87. stage: check
  88. before_script:
  89. - mix deps.get
  90. script:
  91. - export EXITVALUE=0
  92. - mix hex.outdated || export EXITVALUE=1
  93. - yarn --cwd "js" outdated || export EXITVALUE=1
  94. - exit $EXITVALUE
  95. allow_failure: true
  96. needs:
  97. - install
  98. exunit:
  99. stage: test
  100. services:
  101. - name: postgis/postgis:13-3.1
  102. alias: postgres
  103. variables:
  104. MIX_ENV: test
  105. before_script:
  106. - mix deps.get && mix tz_world.update
  107. - mix ecto.create
  108. - mix ecto.migrate
  109. script:
  110. - mix coveralls
  111. artifacts:
  112. when: always
  113. reports:
  114. junit:
  115. - test-junit-report.xml
  116. expire_in: 30 days
  117. jest:
  118. stage: test
  119. needs:
  120. - lint-front
  121. before_script:
  122. - yarn --cwd "js" install --frozen-lockfile
  123. script:
  124. - yarn --cwd "js" run test:unit --no-color --ci --reporters=default --reporters=jest-junit
  125. artifacts:
  126. when: always
  127. paths:
  128. - js/coverage
  129. reports:
  130. junit:
  131. - js/junit.xml
  132. expire_in: 30 days
  133. # cypress:
  134. # stage: test
  135. # services:
  136. # - name: postgis/postgis:13.3
  137. # alias: postgres
  138. # variables:
  139. # MIX_ENV=e2e
  140. # script:
  141. # - mix ecto.create
  142. # - mix ecto.migrate
  143. # - mix run priv/repo/e2e.seed.exs
  144. # - mix phx.server &
  145. # - cd js
  146. # - npx wait-on http://localhost:4000
  147. # - if [ -z "$CYPRESS_KEY" ]; then npx cypress run; else npx cypress run --record --parallel --key $CYPRESS_KEY; fi
  148. # artifacts:
  149. # expire_in: 2 day
  150. # paths:
  151. # - js/tests/e2e/screenshots/**/*.png
  152. # - js/tests/e2e/videos/**/*.mp4
  153. pages:
  154. stage: deploy
  155. script:
  156. - mkdir public
  157. - mix deps.get
  158. - mix docs
  159. - mv doc public/backend
  160. # #- yarn run --cwd "js" styleguide:build
  161. # #- mv js/styleguide public/frontend
  162. rules:
  163. - if: '$CI_COMMIT_BRANCH == "master"'
  164. artifacts:
  165. expire_in: 1 hour
  166. paths:
  167. - public
  168. .docker: &docker
  169. stage: docker
  170. image: docker:stable
  171. variables:
  172. DOCKER_TLS_CERTDIR: "/certs"
  173. DOCKER_HOST: tcp://docker:2376
  174. DOCKER_TLS_VERIFY: 1
  175. DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
  176. DOCKER_DRIVER: overlay2
  177. services:
  178. - docker:stable-dind
  179. cache: {}
  180. before_script:
  181. # Install buildx
  182. - wget https://github.com/docker/buildx/releases/download/v0.6.3/buildx-v0.6.3.linux-amd64
  183. - mkdir -p ~/.docker/cli-plugins/
  184. - mv buildx-v0.6.3.linux-amd64 ~/.docker/cli-plugins/docker-buildx
  185. - chmod a+x ~/.docker/cli-plugins/docker-buildx
  186. # Create env
  187. - docker context create tls-environment
  188. - docker buildx create --use tls-environment
  189. # Install qemu/binfmt
  190. - docker pull tonistiigi/binfmt:latest
  191. - docker run --rm --privileged tonistiigi/binfmt:latest --install all
  192. # Login to DockerHub
  193. - mkdir -p ~/.docker
  194. - echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$CI_REGISTRY_AUTH\",\"email\":\"$CI_REGISTRY_EMAIL\"}}}" > ~/.docker/config.json
  195. script:
  196. - >
  197. docker buildx build
  198. --push
  199. --platform linux/amd64,linux/arm64,linux/arm
  200. -t $DOCKER_IMAGE_NAME
  201. -f docker/production/Dockerfile .
  202. tags:
  203. - "privileged"
  204. timeout: 3 hours
  205. build-docker-master:
  206. <<: *docker
  207. rules:
  208. - if: '$CI_PROJECT_NAMESPACE != "framasoft"'
  209. when: never
  210. - if: '$CI_PIPELINE_SOURCE == "schedule"'
  211. variables:
  212. DOCKER_IMAGE_NAME: framasoft/mobilizon:master
  213. build-docker-tag:
  214. <<: *docker
  215. rules: &tag-rules
  216. - if: '$CI_PROJECT_NAMESPACE != "framasoft"'
  217. when: never
  218. - if: $CI_COMMIT_TAG
  219. variables:
  220. DOCKER_IMAGE_NAME: framasoft/mobilizon:$CI_COMMIT_TAG
  221. # Packaging app for amd64
  222. package-app:
  223. stage: package
  224. variables: &release-variables
  225. MIX_ENV: "prod"
  226. script: &release-script
  227. - mix local.hex --force
  228. - mix local.rebar --force
  229. - mix deps.get
  230. - mix phx.digest
  231. - mix release --path release/mobilizon
  232. - cd release/mobilizon && ln -s lib/mobilizon-*/priv priv && cd ../../
  233. - du -sh release/
  234. - 'echo "Artifact: ${APP_ASSET}"'
  235. - tar czf ${APP_ASSET} -C release mobilizon
  236. - du -sh ${APP_ASSET}
  237. only:
  238. - tags@framasoft/mobilizon
  239. artifacts:
  240. expire_in: 30 days
  241. paths:
  242. - ${APP_ASSET}
  243. package-app-dev:
  244. stage: package
  245. variables: *release-variables
  246. script: *release-script
  247. except:
  248. - tags@framasoft/mobilizon
  249. artifacts:
  250. expire_in: 2 days
  251. paths:
  252. - ${APP_ASSET}
  253. # Packaging app for multi-arch
  254. multi-arch-release:
  255. stage: package
  256. image: docker:stable
  257. variables:
  258. DOCKER_TLS_CERTDIR: "/certs"
  259. DOCKER_HOST: tcp://docker:2376
  260. DOCKER_TLS_VERIFY: 1
  261. DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
  262. DOCKER_DRIVER: overlay2
  263. APP_ASSET: "${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}_${ARCH}.tar.gz"
  264. services:
  265. - docker:stable-dind
  266. cache: {}
  267. before_script:
  268. # Install buildx
  269. - wget https://github.com/docker/buildx/releases/download/v0.6.3/buildx-v0.6.3.linux-amd64
  270. - mkdir -p ~/.docker/cli-plugins/
  271. - mv buildx-v0.6.3.linux-amd64 ~/.docker/cli-plugins/docker-buildx
  272. - chmod a+x ~/.docker/cli-plugins/docker-buildx
  273. # Create env
  274. - docker context create tls-environment
  275. - docker buildx create --use tls-environment
  276. # Install qemu/binfmt
  277. - docker pull tonistiigi/binfmt:latest
  278. - docker run --rm --privileged tonistiigi/binfmt:latest --install all
  279. script:
  280. - docker buildx build --platform linux/${ARCH} --output type=local,dest=releases --build-arg APP_ASSET=${APP_ASSET} -f docker/multiarch/Dockerfile .
  281. - ls -alh releases/mobilizon/
  282. - du -sh releases/mobilizon/${APP_ASSET}
  283. tags:
  284. - "privileged"
  285. artifacts:
  286. expire_in: 30 days
  287. paths:
  288. - releases/mobilizon/${APP_ASSET}
  289. parallel:
  290. matrix:
  291. - ARCH: ["arm", "arm64"]
  292. rules:
  293. - if: '$CI_PROJECT_NAMESPACE != "framasoft"'
  294. when: never
  295. - if: '$CI_PIPELINE_SOURCE == "schedule"'
  296. - if: $CI_COMMIT_TAG
  297. # Release
  298. release-upload:
  299. stage: upload
  300. image: framasoft/yakforms-assets-deploy:latest
  301. rules: *tag-rules
  302. script:
  303. - eval `ssh-agent -s`
  304. - ssh-add <(echo "${DEPLOYEMENT_KEY}" | base64 --decode -i)
  305. - echo "put -r mobilizon_*.tar.gz" | sftp -o "VerifyHostKeyDNS yes" ${DEPLOYEMENT_USER}@${DEPLOYEMENT_HOST}:public/
  306. artifacts:
  307. expire_in: 1 day
  308. when: on_success
  309. paths:
  310. - mobilizon_*.tar.gz
  311. release-create:
  312. stage: deploy
  313. image: registry.gitlab.com/gitlab-org/release-cli:latest
  314. rules: *tag-rules
  315. before_script:
  316. - apk --no-cache add gawk sed grep
  317. script: |
  318. CHANGELOG=$(awk -v version="$APP_VERSION" '/^## / { printit = $2 == version }; printit' CHANGELOG.md | grep -v "## $APP_VERSION" | sed '1{/^$/d}')
  319. ENDPOINT="https://packages.joinmobilizon.org"
  320. release-cli create --name "$CI_COMMIT_TAG" \
  321. --description "$CHANGELOG" \
  322. --tag-name "$CI_COMMIT_TAG" \
  323. --assets-link "{\"name\":\"${APP_ASSET}\",\"url\":\"${ENDPOINT}/${APP_ASSET}\"}"