diff --git a/.circleci/config.yml b/.circleci/config.yml index 7f1a88c..1403889 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,76 +16,4 @@ jobs: POSTGRES_USER: postgres POSTGRES_HOST_AUTH_METHOD: trust environment: - BUNDLE_PATH: vendor/bundle - steps: - - checkout - - ruby/install-deps - - run: - name: "Set up DB" - command: | - bundle exec rails db:setup db:migrate - - run: - name: "Run tests" - command: script/ci/pipeline.sh tests "bundle exec rake" - - store_test_results: - path: tmp/test-results - - store_artifacts: - destination: test-results - path: tmp/test-results - prepare_app_image: - environment: - APP_NAMES: | - ci-pipeline - resource_class: medium - docker: - - image: cimg/base:stable - steps: - - heroku/install - - checkout - - setup_remote_docker: - version: default - docker_layer_caching: false - - - run: - name: "Checking if we should wait on an older build or cancel redundant ones" - command: script/ci/wait_on_older_build_and_cancel_redundant_ones.sh - - - run: - name: "Preparing app image" - command: | - script/ci/pipeline.sh prepare_image "script/ci/prepare_app_image.sh" - - - deploy_to_production: - resource_class: small - docker: - - image: cimg/base:stable - steps: - - heroku/install - - checkout - - run: - name: "Checking if we should wait on an older build or cancel redundant ones" - command: script/ci/wait_on_older_build_and_cancel_redundant_ones.sh - - run: - name: "Deploying to production" - command: | - script/ci/pipeline.sh deploy_production "script/ci/deploy.sh ci-pipeline" - -workflows: - version: 2 - test_and_deploy: - jobs: - - test: - context: shared-config - - prepare_app_image: - context: shared-config - - deploy_to_production: - context: shared-config - requires: - - test - - prepare_app_image - filters: - branches: - only: - - master diff --git a/script/ci/prepare_app_image.sh b/script/ci/prepare_app_image.sh deleted file mode 100755 index 380cf88..0000000 --- a/script/ci/prepare_app_image.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -set -e - -revision=$(git rev-parse HEAD) - -_main () { - make build_docker_image - - _log_into_registry - _push_to_registry -} - -_log_into_registry () { heroku auth:token 2> /dev/null | docker login --username=_ --password-stdin registry.heroku.com 2> /dev/null; } - -_push_to_registry () { - for app_name in $APP_NAMES - do - registry_path="registry.heroku.com/$app_name/app:$revision" - echo "Pushing to $app_name registry ..." - - docker tag "$CIRCLE_PROJECT_REPONAME" "$registry_path" - docker push "$registry_path" & - done - wait && echo "done" -} - -_main diff --git a/script/ci/wait_on_older_build_and_cancel_redundant_ones.sh b/script/ci/wait_on_older_build_and_cancel_redundant_ones.sh deleted file mode 100755 index 5c2c1c0..0000000 --- a/script/ci/wait_on_older_build_and_cancel_redundant_ones.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash - -set -e -set -o pipefail -shopt -s inherit_errexit # Command substitution inherits "set -e". - -pending_lifecycle='"queued","scheduled","not_run","not_running"' -base_url="https://circleci.com/api/v1.1/project/github/${CIRCLE_PROJECT_USERNAME:?}/${CIRCLE_PROJECT_REPONAME:?}" -builds_for_the_same_job_on_the_same_branch=". | map(select(.workflows.job_name == \"${CIRCLE_JOB:?}\" and .branch == \"${CIRCLE_BRANCH:?}\"))" - -_main () { - latest_build_num=$(_latest_build_num) - if [[ "${CIRCLE_BUILD_NUM:?}" = "${latest_build_num}" ]]; then - build_date=$(date) - echo "Current build is the latest build at ${build_date}" - - _wait_for_older_builds_to_finish - exit 0 - fi - - # Don't cancel the current build until we've had the time to cancel others. - _cancel_all_build_except_latest_and_current - - echo "Canceling ourselves since we're not the latest build" - _cancel_build "${CIRCLE_BUILD_NUM}" - - # Give the cancellation request time to process. Otherwise this script would exit and make the job succeed/fail before it can be canceled. - sleep 10 - - # If the request failed, fail the build. Otherwise we might continue e.g. to deploy when we shouldn't. - exit 1 -} - -_cancel_build () { - build_num=$1 - - if curl --silent --user "${CIRCLE_API_TOKEN:?}:" -X POST "${base_url}/${build_num}/cancel" > /dev/null; then - echo "Canceling build ${build_num}: Success" - else - echo "Canceling build ${build_num}: Failed" - fi -} - -_cancel_all_build_except_latest_and_current () { - for build_num in $(_latest_builds_in_current_project_json | jq "${builds_for_the_same_job_on_the_same_branch} | map(select(.lifecycle == (${pending_lifecycle}))) | [.[].build_num] | sort | .[0:-1] | .[]"); do - if [[ "${build_num}" = "${CIRCLE_BUILD_NUM}" ]]; then - continue - fi - - _cancel_build "${build_num}" & - done - wait -} - -_latest_build_num () { _latest_builds_in_current_project_json | jq "${builds_for_the_same_job_on_the_same_branch} | [.[].build_num] | max"; } -_latest_builds_in_current_project_json () { curl --silent --user "${CIRCLE_API_TOKEN:?}:" "${base_url}"; } - -_wait_for_older_builds_to_finish () { - printf 'Waiting for older builds to finish...' - - while true; do - older_running_builds=$(_latest_builds_in_current_project_json | jq "${builds_for_the_same_job_on_the_same_branch} | map(select(.lifecycle == \"running\")) | map(select(.build_num < ${CIRCLE_BUILD_NUM})) | [ .[].build_num ]") - if [[ "${older_running_builds}" = "[]" ]]; then - echo " Done" - break - fi - - printf '.' - sleep 1 - done -} - -_main