steps: # Cancel previous job on the same branch - name: gcr.io/cloud-builders/gcloud id: list-builds entrypoint: /bin/bash args: - '-c' - 'gcloud builds list --ongoing --filter="buildTriggerId=e460656e-80d0-4886-b3ec-2098cadbb3a0 AND substitutions.BRANCH_NAME=${BRANCH_NAME} AND id!=${BUILD_ID}" --format="get(ID)" > jobs_to_cancel' - name: gcr.io/cloud-builders/gcloud id: cancel-builds entrypoint: /bin/bash args: - '-c' - 'gcloud builds cancel $(cat jobs_to_cancel | xargs) || true' waitFor: ['list-builds'] # Decrypt github key - name: gcr.io/cloud-builders/gcloud id: decrypt-key args: - kms - decrypt - --ciphertext-file=script/ci/.id_github_cartofante.enc - --plaintext-file=/root/.ssh/id_rsa - --location=global - --keyring=keyring-github-ci - --key=github-key volumes: - name: 'ssh' path: /root/.ssh waitFor: ['cancel-builds'] # Set up git with key and domain - name: 'gcr.io/cloud-builders/git' id: setup-git entrypoint: 'bash' args: - '-c' - | chmod 600 /root/.ssh/id_rsa cat </root/.ssh/config Hostname github.com IdentityFile /root/.ssh/id_rsa EOF mv script/ci/known_hosts /root/.ssh/known_hosts volumes: - name: 'ssh' path: /root/.ssh waitFor: ['decrypt-key'] # Clean working directory - name: alpine id: cleanup args: ['sh', '-c', 'rm -rf .* | true && rm -rf *'] waitFor: ['setup-git'] # Checkout repo with submodules - name: 'gcr.io/cloud-builders/git' id: checkout-cartodb entrypoint: 'sh' args: ['-c', 'git clone git@github.com:CartoDB/${_REPO} -b "${BRANCH_NAME}" --depth 1 --recursive cartodb'] volumes: - name: 'ssh' path: /root/.ssh waitFor: ['cleanup'] # Checkout db-connectors - name: 'gcr.io/cloud-builders/git' id: checkout-db-connectors entrypoint: 'sh' args: ['-c', 'git clone git@github.com:CartoDB/db-connectors --depth 1 cartodb/private_gears/db-connectors'] volumes: - name: 'ssh' path: /root/.ssh waitFor: ['checkout-cartodb'] # Copy files to the right directories to run the tests - name: ubuntu id: copy-private-files dir: /workspace/cartodb entrypoint: /bin/bash args: - -cx - | cp private/Dockerfil* . cp config/unicorn.conf.rb.sample config/unicorn.conf.rb cp config/app_config.yml.sample config/app_config.yml cp config/database.yml.sample config/database.yml cp lib/assets/javascripts/cdb/secrets.example.json lib/assets/javascripts/cdb/secrets.json cp config/grunt_development.json config/grunt_production.json sed -i 's|false|true|g' config/grunt_production.json waitFor: ['checkout-db-connectors'] # Copy repo folder to isolate onprem build context - name: ubuntu id: copy-cartodb-repo entrypoint: /bin/bash args: - -c - | cp -r cartodb cartodb-onprem waitFor: ['copy-private-files'] # Build image - name: gcr.io/cloud-builders/docker id: build-cartodb dir: /workspace/cartodb entrypoint: /bin/bash args: - -cx - | docker pull ${_DOCKER_IMAGE_NAME}:${_BRANCH_TAG} if [ $? -ne 0 ] then docker pull ${_DOCKER_IMAGE_NAME}:latest fi set -e docker build --label="org.opencontainers.image.created=$$(date --rfc-3339=seconds)" --label=org.opencontainers.image.revision=${COMMIT_SHA} --build-arg COMPILE_ASSETS=true --build-arg BUNDLE_JOBS=4 -t ${_DOCKER_IMAGE_NAME}:latest -t ${_DOCKER_IMAGE_NAME}:${_BRANCH_TAG} -t ${_DOCKER_IMAGE_NAME}:${SHORT_SHA} -t ${_DOCKER_IMAGE_NAME}:${_BRANCH_TAG}--${SHORT_SHA} --cache-from ${_DOCKER_IMAGE_NAME}:${_BRANCH_TAG} --cache-from ${_DOCKER_IMAGE_NAME}:latest . docker build --label="org.opencontainers.image.created=$$(date --rfc-3339=seconds)" --label=org.opencontainers.image.revision=${COMMIT_SHA} -t ${_DOCKER_IMAGE_NAME}-resque:latest -t ${_DOCKER_IMAGE_NAME}-resque:${_BRANCH_TAG} -t ${_DOCKER_IMAGE_NAME}-resque:${SHORT_SHA} -t ${_DOCKER_IMAGE_NAME}-resque:${_BRANCH_TAG}--${SHORT_SHA} -f Dockerfile.resque . docker build --label="org.opencontainers.image.created=$$(date --rfc-3339=seconds)" --label=org.opencontainers.image.revision=${COMMIT_SHA} -t ${_DOCKER_IMAGE_NAME}-subscriber:latest -t ${_DOCKER_IMAGE_NAME}-subscriber:${_BRANCH_TAG} -t ${_DOCKER_IMAGE_NAME}-subscriber:${SHORT_SHA} -t ${_DOCKER_IMAGE_NAME}-subscriber:${_BRANCH_TAG}--${SHORT_SHA} -f Dockerfile.subscriber . waitFor: ['copy-cartodb-repo'] # Checkout onprem licensing gear - name: 'gcr.io/cloud-builders/git' id: checkout-licensing-gear dir: /workspace/cartodb-onprem entrypoint: 'sh' args: ['-c', 'git clone git@github.com:CartoDB/onpremises_licensing_gear --depth 1 private_gears/onpremises_licensing_gear'] volumes: - name: 'ssh' path: /root/.ssh waitFor: ['build-cartodb'] # Build onprem image - name: gcr.io/cloud-builders/docker id: build-cartodb-onprem dir: /workspace/cartodb-onprem entrypoint: /bin/bash args: - -cex - | docker build --label="org.opencontainers.image.created=$$(date --rfc-3339=seconds)" --label=org.opencontainers.image.revision=${COMMIT_SHA} --build-arg GRUNT_ENV=production --build-arg COMPILE_ASSETS=true --build-arg CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE="/maps-v2/user/{user}" --build-arg BUNDLE_JOBS=4 -t ${_DOCKER_IMAGE_NAME}-onprem:latest -t ${_DOCKER_IMAGE_NAME}-onprem:${_BRANCH_TAG} -t ${_DOCKER_IMAGE_NAME}-onprem:${SHORT_SHA} -t ${_DOCKER_IMAGE_NAME}-onprem:${_BRANCH_TAG}--${SHORT_SHA} --cache-from ${_DOCKER_IMAGE_NAME}:${_BRANCH_TAG} --cache-from ${_DOCKER_IMAGE_NAME}:latest . waitFor: ['checkout-licensing-gear'] # Build onprem cron image - name: gcr.io/cloud-builders/docker id: build-cartodb-onprem-cron dir: /workspace/cartodb entrypoint: /bin/bash args: - -cex - | docker build --label="org.opencontainers.image.created=$$(date --rfc-3339=seconds)" --label=org.opencontainers.image.revision=${COMMIT_SHA} -t ${_DOCKER_IMAGE_NAME}-onprem-cron:latest -t ${_DOCKER_IMAGE_NAME}-onprem-cron:${_BRANCH_TAG} -t ${_DOCKER_IMAGE_NAME}-onprem-cron:${SHORT_SHA} -t ${_DOCKER_IMAGE_NAME}-onprem-cron:${_BRANCH_TAG}--${SHORT_SHA} -f Dockerfile.cron . waitFor: ['build-cartodb-onprem'] timeout: 3600s images: - ${_DOCKER_IMAGE_NAME}:${_BRANCH_TAG}--${SHORT_SHA} - ${_DOCKER_IMAGE_NAME}:${_BRANCH_TAG} - ${_DOCKER_IMAGE_NAME}:${SHORT_SHA} - ${_DOCKER_IMAGE_NAME}-onprem:${_BRANCH_TAG}--${SHORT_SHA} - ${_DOCKER_IMAGE_NAME}-onprem:${_BRANCH_TAG} - ${_DOCKER_IMAGE_NAME}-onprem:${SHORT_SHA} - ${_DOCKER_IMAGE_NAME}-onprem-cron:${_BRANCH_TAG}--${SHORT_SHA} - ${_DOCKER_IMAGE_NAME}-onprem-cron:${_BRANCH_TAG} - ${_DOCKER_IMAGE_NAME}-onprem-cron:${SHORT_SHA} - ${_DOCKER_IMAGE_NAME}-resque:${_BRANCH_TAG}--${SHORT_SHA} - ${_DOCKER_IMAGE_NAME}-resque:${_BRANCH_TAG} - ${_DOCKER_IMAGE_NAME}-resque:${SHORT_SHA} - ${_DOCKER_IMAGE_NAME}-subscriber:${_BRANCH_TAG}--${SHORT_SHA} - ${_DOCKER_IMAGE_NAME}-subscriber:${_BRANCH_TAG} - ${_DOCKER_IMAGE_NAME}-subscriber:${SHORT_SHA} substitutions: _BRANCH_TAG: ${BRANCH_NAME//\//-} _DOCKER_IMAGE_NAME: gcr.io/cartodb-on-gcp-main-artifacts/builder _REPO: cartodb options: machineType: 'E2_HIGHCPU_32'