legendary-doc-site/.gitlab-ci.yml

160 lines
4.2 KiB
YAML
Raw Normal View History

2020-12-19 22:45:02 +00:00
stages:
- prebuild
- asset_dependencies
2020-12-19 22:45:02 +00:00
- test
- deploy_tags
2020-12-19 22:45:02 +00:00
- deploy
2020-07-03 15:34:19 +00:00
variables:
POSTGRES_PASSWORD: "postgres"
POSTGRES_USER: "postgres"
2020-07-03 15:34:19 +00:00
DATABASE_URL: "postgres"
MIX_ENV: "test"
DOCKER_TLS_CERTDIR: "/certs"
2020-12-19 18:51:02 +00:00
DOCKER_HOST: tcp://docker:2376
2021-03-26 22:31:54 +00:00
# fetch & clean the repo rather than completely cloning (faster)
GIT_STRATEGY: fetch
# Dependency stages-- fetch these first so that we can cache them and reuse them
# across jobs and pipelines. Note that elixir deps need to go first, because
# we need the phoenix and phoenix_html hex packages to install their JS.
fetch_application_dependencies:
stage: prebuild
2021-03-26 22:31:54 +00:00
image: "elixir:1.10"
cache:
key:
files:
- mix.lock
paths:
- _build/
- deps/
script:
- mix local.hex --force
- mix local.rebar --force
- mix deps.get
- mix deps.compile
- mix compile
2021-03-26 22:31:54 +00:00
# Make results available to other jobs
artifacts:
paths:
- deps/phoenix
- deps/phoenix_html
exclude:
- deps/
fetch_asset_dependencies:
stage: asset_dependencies
image: "node:15.0"
needs:
- fetch_application_dependencies
only:
- master
cache:
key:
files:
- apps/app/assets/package-lock.json
paths:
- apps/app/assets/node_modules/
script:
- cd apps/app/assets/ && npm install
# Make results available to other jobs
artifacts:
paths:
- apps/app/assets/node_modules
exclude:
- apps/app/assets/node_modules
2020-07-03 15:34:19 +00:00
2021-03-26 22:31:54 +00:00
# Test stage. Runs various tests and speculatively builds docker image in
# parallel, in case the build passes.
2020-12-18 20:21:07 +00:00
test:
2020-12-19 22:45:02 +00:00
stage: test
2021-03-26 22:31:54 +00:00
needs:
- prebuild
2021-02-27 01:11:22 +00:00
image: "elixir:1.10"
services:
- name: postgres:12
2021-03-26 22:31:54 +00:00
cache:
key:
files:
- mix.lock
paths:
- _build/
- deps/
2020-07-17 23:30:31 +00:00
script: script/cibuild
build_image_for_commit:
stage: test
2021-03-26 22:31:54 +00:00
needs:
- fetch_asset_dependencies
- prebuild
2021-03-26 22:31:54 +00:00
image: "docker:20.10"
2021-01-16 19:20:27 +00:00
only:
- master
services:
2021-03-26 22:31:54 +00:00
- name: docker:20.10-dind
cache:
key:
files:
- mix.lock
paths:
- _build/
- deps/
script:
2020-12-19 22:39:31 +00:00
- docker login "https://${CI_REGISTRY}" -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
- docker pull $CI_REGISTRY_IMAGE:latest || true
2021-03-26 22:31:54 +00:00
# This enables fast parallel builds
- export DOCKER_BUILDKIT=1
- docker build --cache-from $CI_REGISTRY_IMAGE:latest -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --build-arg BUILDKIT_INLINE_CACHE=1 .
# Push the commit SHA tagged version to registry. We will later choose to tag that as stable
# if everything passes.
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
2021-03-26 22:31:54 +00:00
# This copies the elixir build artifacts for deps and app so that we can cache them
- docker cp `docker create $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA`:/root/app/_build/prod _build
2021-03-26 22:31:54 +00:00
# If tests pass, tag the commit and update package versions
deploy_to_tags:
stage: deploy_tags
needs: ['test']
image: "node:15.0"
only:
- master
2021-03-26 22:31:54 +00:00
cache:
key:
files:
- package-lock.json
paths:
- node_modules/
script:
- npm install
- npx semantic-release --repository-url=$CI_REPOSITORY_URL
- script/generate-build-version
artifacts:
reports:
dotenv: build.env
2021-03-26 22:31:54 +00:00
# If the tests passed, we take the image for this SHA and tag it with the version
# and latest, so we can signal that it is ready for prod
deploy_commit_image_to_tag:
stage: deploy
needs:
- build_image_for_commit
- job: deploy_to_tags
artifacts: true
only:
- master
image: "docker:19.03.12"
services:
- name: docker:19.03.12-dind
2021-03-26 22:31:54 +00:00
variables:
GIT_STRATEGY: none # this job does not need the project files, only docker
script:
- echo "BUILD_VERSION is ${BUILD_VERSION}"
- docker login "https://${CI_REGISTRY}" -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
2020-12-22 20:36:13 +00:00
# Run the docker pull, but retry if it doesn't work at first because layers may be
# still be loading to storage
- for i in 1 2 3 4 5; do docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA && break || sleep 15; done
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$BUILD_VERSION
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:$BUILD_VERSION
- docker push $CI_REGISTRY_IMAGE:latest