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

110 lines
2.9 KiB
YAML
Raw Normal View History

2020-12-19 22:45:02 +00:00
stages:
- 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
# Test stage. Runs various tests and speculatively builds docker image in
# parallel, in case the build passes.
2021-06-10 20:25:40 +00:00
.test_template: &test_template
2020-12-19 22:45:02 +00:00
stage: test
2021-04-24 16:20:17 +00:00
cache:
paths:
- _build/
- deps/
services:
- name: postgres:12
2021-04-16 22:59:06 +00:00
script: script/cibuild
2021-06-10 20:25:40 +00:00
test:
<<: *test_template
image: "elixir:1.10.4-alpine"
test_1.11.4:
<<: *test_template
image: "elixir:1.11.4-alpine"
test_1.12.1:
<<: *test_template
image: "elixir:1.12.1-alpine"
build_image_for_commit:
stage: test
2021-03-26 22:31:54 +00:00
image: "docker:20.10"
2021-06-10 20:17:48 +00:00
only:
- master
2021-04-24 16:20:17 +00:00
cache:
paths:
- _build/
- deps/
services:
2021-03-26 22:31:54 +00:00
- name: docker:20.10-dind
2021-06-10 19:39:36 +00:00
before_script:
- apk add git
2021-06-10 19:26:56 +00:00
- script/ci-docker-prebuild
2021-06-10 19:39:36 +00:00
script:
2021-06-10 19:17:35 +00:00
- script/ci-docker-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
2021-05-21 18:24:08 +00:00
needs: ['test', 'build_image_for_commit']
image: "node:15.0"
only:
- master
2021-03-26 22:31:54 +00:00
cache:
key:
files:
- package-lock.json
paths:
- node_modules/
script:
- export GIT_AUTHOR_NAME=$GITLAB_USER_NAME
- export GIT_AUTHOR_EMAIL=$GITLAB_USER_EMAIL
- export GIT_COMMITTER_NAME=$GITLAB_USER_NAME
- export GIT_COMMITTER_EMAIL=$GITLAB_USER_EMAIL
- 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
parallel:
matrix:
- IMAGE_TYPE: ["", "-elixir-builder", "-asset-builder"]
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$IMAGE_TYPE && break || sleep 15; done
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA$IMAGE_TYPE $CI_REGISTRY_IMAGE:$BUILD_VERSION$IMAGE_TYPE
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA$IMAGE_TYPE $CI_REGISTRY_IMAGE:latest$IMAGE_TYPE
- docker push $CI_REGISTRY_IMAGE:$BUILD_VERSION$IMAGE_TYPE
- docker push $CI_REGISTRY_IMAGE:latest$IMAGE_TYPE