You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cartodb/script/ci/cloudbuild-build-master.yaml

126 lines
5.8 KiB

steps:
# Cancel previous job on the same branch
- name: gcr.io/cloud-builders/gcloud
entrypoint: /bin/bash
args:
- '-c'
- 'gcloud builds list --ongoing --filter="buildTriggerId=70299e98-eed0-4fc6-943b-b8a5e0cf2aca AND substitutions.BRANCH_NAME=${_BRANCH_TAG} AND id!=${BUILD_ID}" --format="get(ID)" > jobs_to_cancel'
- name: gcr.io/cloud-builders/gcloud
entrypoint: /bin/bash
args:
- '-c'
- 'gcloud builds cancel $(cat jobs_to_cancel | xargs) || true'
# Decrypt github key
- name: gcr.io/cloud-builders/gcloud
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
# Set up git with key and domain
- name: 'gcr.io/cloud-builders/git'
entrypoint: 'bash'
args:
- '-c'
- |
chmod 600 /root/.ssh/id_rsa
cat <<EOF >/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
# Clean working directory
- name: alpine
args: ['sh', '-c', 'rm -rf .* | true && rm -rf *']
# Checkout repo with submodules
- name: 'gcr.io/cloud-builders/git'
entrypoint: 'sh'
args: ['-c', 'git clone git@github.com:CartoDB/cartodb -b "${BRANCH_NAME}" --depth 1 --recursive .']
volumes:
- name: 'ssh'
path: /root/.ssh
# Copy files to the right directories to run the tests
- name: ubuntu
entrypoint: /bin/bash
args:
- -c
- |
cp private/Dockerfil* .
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
# Build and push image
- name: gcr.io/cloud-builders/docker
entrypoint: /bin/bash
args:
- -c
- |
set -x
docker pull gcr.io/cartodb-on-gcp-main-artifacts/builder:${_BRANCH_TAG}
if [ "$?" -ne 0 ]
then
docker pull gcr.io/cartodb-on-gcp-main-artifacts/builder:latest
docker tag gcr.io/cartodb-on-gcp-main-artifacts/builder:latest gcr.io/cartodb-on-gcp-main-artifacts/builder:${_BRANCH_TAG}
fi
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 gcr.io/cartodb-on-gcp-main-artifacts/builder:latest -t gcr.io/cartodb-on-gcp-main-artifacts/builder:${_BRANCH_TAG} -t gcr.io/cartodb-on-gcp-main-artifacts/builder:${SHORT_SHA} -t gcr.io/cartodb-on-gcp-main-artifacts/builder:${_BRANCH_TAG}--${SHORT_SHA} --cache-from gcr.io/cartodb-on-gcp-main-artifacts/builder:${_BRANCH_TAG} .
docker build --label="org.opencontainers.image.created=$$(date --rfc-3339=seconds)" --label=org.opencontainers.image.revision=${COMMIT_SHA} -t gcr.io/cartodb-on-gcp-main-artifacts/builder-resque:latest -t gcr.io/cartodb-on-gcp-main-artifacts/builder-resque:${_BRANCH_TAG} -t gcr.io/cartodb-on-gcp-main-artifacts/builder-resque:${SHORT_SHA} -t gcr.io/cartodb-on-gcp-main-artifacts/builder-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 gcr.io/cartodb-on-gcp-main-artifacts/builder-subscriber:latest -t gcr.io/cartodb-on-gcp-main-artifacts/builder-subscriber:${_BRANCH_TAG} -t gcr.io/cartodb-on-gcp-main-artifacts/builder-subscriber:${SHORT_SHA} -t gcr.io/cartodb-on-gcp-main-artifacts/builder-subscriber:${_BRANCH_TAG}--${SHORT_SHA} -f Dockerfile.subscriber .
echo 'Pushing builder image...'
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder:${_BRANCH_TAG}
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder:${SHORT_SHA}
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder:${_BRANCH_TAG}--${SHORT_SHA}
echo 'Pushing builder-resque image...'
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder-resque:${_BRANCH_TAG}
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder-resque:${SHORT_SHA}
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder-resque:${_BRANCH_TAG}--${SHORT_SHA}
echo 'Pushing builder-subscriber image...'
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder-subscriber:${_BRANCH_TAG}
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder-subscriber:${SHORT_SHA}
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder-subscriber:${_BRANCH_TAG}--${SHORT_SHA}
if [ "${_BRANCH_TAG}" == 'master' ]
then
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder:latest
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder-resque:latest
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder-subscriber:latest
fi
if [ ! -z "${TAG_NAME}" ]
then
echo "Tagging image with git tag: $TAG_NAME ..."
docker tag gcr.io/cartodb-on-gcp-main-artifacts/builder:${SHORT_SHA} gcr.io/cartodb-on-gcp-main-artifacts/builder:${TAG_NAME}
docker tag gcr.io/cartodb-on-gcp-main-artifacts/builder-resque:${SHORT_SHA} gcr.io/cartodb-on-gcp-main-artifacts/builder-resque:${TAG_NAME}
docker tag gcr.io/cartodb-on-gcp-main-artifacts/builder-subscriber:${SHORT_SHA} gcr.io/cartodb-on-gcp-main-artifacts/builder-subscriber:${TAG_NAME}
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder:${TAG_NAME}
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder-resque:${TAG_NAME}
docker push gcr.io/cartodb-on-gcp-main-artifacts/builder-subscriber:${TAG_NAME}
fi
substitutions:
_BRANCH_TAG: ${BRANCH_NAME//\//-}
timeout: 1800s