From 4dff52bbe0d8fab61a6e4e65dbd4fc397bb5a513 Mon Sep 17 00:00:00 2001 From: Thomas Parisot Date: Mon, 21 Dec 2020 16:56:38 +0100 Subject: [PATCH] Release Elixir and frontend assets as part of the release --- .gitignore | 1 + .gitlab-ci.yml | 80 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2c09e1644..8791c51f5 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ erl_crash.dump # secrets files as long as you replace their contents by environment # variables. /config/*.secret.exs +/config/releases.exs /setup_db.psql diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 73ba72c52..cc6f55fd0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,6 +5,7 @@ stages: - test - deploy - docker + - release variables: MIX_ENV: "test" @@ -20,6 +21,11 @@ variables: MOBILIZON_DATABASE_HOST: $POSTGRES_HOST GEOLITE_CITIES_PATH: "/usr/share/GeoIP/GeoLite2-City.mmdb" MOBILIZON_INSTANCE_REGISTRATIONS_OPEN: "true" + # Release elements + PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${PACKAGE_VERSION}" + ELIXIR_ASSET: "${CI_PROJECT_NAME}-standalone-${CI_COMMIT_TAG}.tar.gz" + FRONTEND_ASSET: "${CI_PROJECT_NAME}-frontend-${CI_COMMIT_TAG}.tar.gz" + cache: key: ${CI_COMMIT_REF_SLUG} @@ -81,7 +87,8 @@ exunit: - mix deps.get - MIX_ENV=test mix ecto.create - MIX_ENV=test mix ecto.migrate - dependencies: + needs: + - deps - lint-elixir script: - mix coveralls @@ -170,3 +177,74 @@ build-docker-tag: - tags variables: DOCKER_IMAGE_NAME: framasoft/mobilizon:$CI_COMMIT_TAG + +build-release-frontend: + stage: release + image: node:14-alpine + before_script: + - apk add --no-cache python build-base libwebp-tools bash imagemagick ncurses + script: + - yarn --cwd "js" install + - yarn --cwd "js" run build + artifacts: + expire_in: 1 day + paths: + - priv/static + + +build-release-elixir: + stage: release + image: elixir:alpine + before_script: + - apk add --no-cache build-base git cmake + variables: + MIX_ENV: "prod" + script: + - mix local.hex --force + - mix local.rebar --force + - mix deps.get + - cp docker/production/releases.exs ./config/ + - mix phx.digest + - mix release + needs: + - build-release-frontend + artifacts: + expire_in: 1 day + paths: + - _build/prod/rel + +build-release-upload: + stage: release + image: curlimages/curl:latest + # rules: + # - if: $CI_COMMIT_TAG + script: | + ls -R _build + tar czf /tmp/${ELIXIR_ASSET} -C _build/prod/rel mobilizon + tar czf /tmp/${FRONTEND_ASSET} -C priv/static . + ls -al /tmp/*.tar.gz + + curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file "_build/${ELIXIR_ASSET}" ${PACKAGE_REGISTRY_URL}/${ELIXIR_ASSET} + curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file "_build/${FRONTEND_ASSET}" ${PACKAGE_REGISTRY_URL}/${FRONTEND_ASSET} + artifacts: + expire_in: 1 day + when: on_success + paths: + - _build/${ELIXIR_ASSET} + - _build/${FRONTEND_ASSET} + needs: + - build-release-elixir + +build-release-create: + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + rules: + - if: $CI_COMMIT_TAG + script: | + release-cli create --name "Release $CI_COMMIT_SHA" \ + --tag-name "$CI_COMMIT_TAG" \ + --assets-link "{\"name\":\"${ELIXIR_ASSET}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${ELIXIR_ASSET}\"}" \ + --assets-link "{\"name\":\"${FRONTEND_ASSET}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${FRONTEND_ASSET}\"}" + needs: + - build-release-upload +