Release Elixir and frontend assets as part of the release

This commit is contained in:
Thomas Parisot 2020-12-21 16:56:38 +01:00
parent 89258bb41e
commit 4dff52bbe0
2 changed files with 80 additions and 1 deletions

1
.gitignore vendored
View file

@ -14,6 +14,7 @@ erl_crash.dump
# secrets files as long as you replace their contents by environment # secrets files as long as you replace their contents by environment
# variables. # variables.
/config/*.secret.exs /config/*.secret.exs
/config/releases.exs
/setup_db.psql /setup_db.psql

View file

@ -5,6 +5,7 @@ stages:
- test - test
- deploy - deploy
- docker - docker
- release
variables: variables:
MIX_ENV: "test" MIX_ENV: "test"
@ -20,6 +21,11 @@ variables:
MOBILIZON_DATABASE_HOST: $POSTGRES_HOST MOBILIZON_DATABASE_HOST: $POSTGRES_HOST
GEOLITE_CITIES_PATH: "/usr/share/GeoIP/GeoLite2-City.mmdb" GEOLITE_CITIES_PATH: "/usr/share/GeoIP/GeoLite2-City.mmdb"
MOBILIZON_INSTANCE_REGISTRATIONS_OPEN: "true" 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: cache:
key: ${CI_COMMIT_REF_SLUG} key: ${CI_COMMIT_REF_SLUG}
@ -81,7 +87,8 @@ exunit:
- mix deps.get - mix deps.get
- MIX_ENV=test mix ecto.create - MIX_ENV=test mix ecto.create
- MIX_ENV=test mix ecto.migrate - MIX_ENV=test mix ecto.migrate
dependencies: needs:
- deps
- lint-elixir - lint-elixir
script: script:
- mix coveralls - mix coveralls
@ -170,3 +177,74 @@ build-docker-tag:
- tags - tags
variables: variables:
DOCKER_IMAGE_NAME: framasoft/mobilizon:$CI_COMMIT_TAG 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