stages: - application_dependencies - asset_dependencies - test - deploy_tags - deploy variables: POSTGRES_PASSWORD: "postgres" POSTGRES_USER: "postgres" DATABASE_URL: "postgres" MIX_ENV: "test" DOCKER_TLS_CERTDIR: "/certs" DOCKER_HOST: tcp://docker:2376 GIT_STRATEGY: fetch fetch_application_dependencies: stage: application_dependencies 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 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 artifacts: paths: - apps/app/assets/node_modules exclude: - apps/app/assets/node_modules test: stage: test needs: - fetch_application_dependencies image: "elixir:1.10" services: - name: postgres:12 cache: key: files: - mix.lock paths: - _build/ - deps/ script: script/cibuild build_image_for_commit: stage: test needs: - fetch_asset_dependencies - fetch_application_dependencies image: "docker:20.10" only: - master services: - name: docker:20.10-dind cache: key: files: - mix.lock paths: - _build/ - deps/ script: - docker login "https://${CI_REGISTRY}" -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD - docker pull $CI_REGISTRY_IMAGE:latest || true - 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 . - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - docker cp `docker create $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA`:/root/app/_build/prod _build deploy_to_tags: stage: deploy_tags needs: ['test'] image: "node:15.0" only: - master 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 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 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 # 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