Created
November 22, 2019 18:53
-
-
Save yuvipanda/0544694ec8d12315f6d52fe1275f0d67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
description: "Build an image via hubploy" | |
parameters: | |
deployment: | |
type: string | |
push: | |
type: boolean | |
default: false | |
docker: | |
- image: python:3.7-slim-buster | |
working_directory: ~/repo | |
steps: | |
- checkout | |
- run: | |
name: Install git, git-crypt & curl | |
command: | | |
apt-get update && apt-get install --yes --no-install-recommends git curl git-crypt | |
- restore_cache: | |
keys: | |
- v3.7-dependencies-{{ checksum "requirements.txt" }} | |
# fallback to using the latest cache if no exact match is found | |
- v3.7-dependencies- | |
- run: | |
name: install dependencies | |
command: | | |
python3 -m venv venv | |
source venv/bin/activate | |
pip install --upgrade -r requirements.txt | |
echo 'export PATH="${HOME}/repo/venv/bin:$PATH"' >> ${BASH_ENV} | |
- unless: | |
condition: << parameters.push >> | |
steps: | |
- run: | |
name: Determine range of commits we are building | |
command: | | |
# CircleCI doesn't have equivalent to Travis' COMMIT_RANGE | |
COMMIT_RANGE=$(./.circleci/get-commit-range.py) | |
echo ${COMMIT_RANGE} | |
echo "export COMMIT_RANGE='${COMMIT_RANGE}'" >> ${BASH_ENV} | |
- when: | |
condition: << parameters.push >> | |
steps: | |
- run: | |
name: Install google cloud sdk | |
command: | | |
curl -sSL https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-265.0.0-linux-x86_64.tar.gz | tar -xzf - | |
# Be careful with quote ordering here. ${PATH} must not be expanded | |
# Don't use ~ here - bash can interpret PATHs containing ~, but most other things can't. | |
# Always use full PATHs in PATH! | |
echo 'export PATH="${HOME}/repo/google-cloud-sdk/bin:${PATH}"' >> ${BASH_ENV} | |
# Try to tell cloud sdk to use python3 | |
echo 'export CLOUDSDK_PYTHON=python3' >> ${BASH_ENV} | |
- run: | |
name: Install AWS CLI | |
command: | | |
cd /tmp | |
curl "https://d1vvhvl2y92vvt.cloudfront.net/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | |
unzip awscliv2.zip | |
./aws/install -i ${HOME}/awscli -b ${HOME}/awscli/bin | |
# Be careful with quote ordering here. ${PATH} must not be expanded | |
# Don't use ~ here - bash can interpret PATHs containing ~, but most other things can't. | |
# Always use full PATHs in PATH! | |
echo 'export PATH="${HOME}/awscli/bin:${PATH}"' >> ${BASH_ENV} | |
- setup_remote_docker | |
- save_cache: | |
paths: | |
- ./venv | |
key: v3.7-dependencies-{{ checksum "requirements.txt" }} | |
- when: | |
condition: << parameters.push >> | |
steps: | |
- run: | |
name: Unlock our secrets | |
command: | | |
echo "${GIT_CRYPT_KEY}" | base64 -d > ~/repo/key | |
git crypt unlock ~/repo/key | |
rm ~/repo/key | |
- run: | |
name: Build image if needed | |
command: | | |
if [ "<< parameters.push >>" == "true" ]; then | |
HUBPLOY_ARGS="--check-registry --push" | |
else | |
HUBPLOY_ARGS="--commit-range ${COMMIT_RANGE}" | |
fi | |
hubploy build << parameters.deployment >> ${HUBPLOY_ARGS} | |
no_output_timeout: 60m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment