balena-supervisor/circle.yml
Felipe Lalanne 68d60d8aaa Add supervisor docker-compose
This will allow the supervisor service to be correctly named on the API

Change-type: patch
2021-09-29 22:07:32 -03:00

213 lines
7.9 KiB
YAML

---
defaults: &defaults
docker:
- image: library/docker:18-git
working_directory: /tmp/build
steps:
- setup_remote_docker:
version: 18.09.3
docker_layer_caching: true
- run:
name: Check docker is running and install dependencies
command: |
docker info
apk update && apk upgrade && apk add --no-cache \
make \
jq \
bash \
grep \
nodejs \
nodejs-npm \
openssh-client
- run:
name: Install balena CLI and test it
command: |
apk add --no-cache curl python3 g++ linux-headers && \
npm install balena-cli -g --production --unsafe-perm && \
balena version -v
- checkout
- run:
name: Initialize the submodules
command: |
git submodule update --init --recursive
git clean -fxd base-image
git submodule foreach --recursive git clean -fxd
- run:
name: Build $ARCH-supervisor
no_output_timeout: 10800
command: |
VERSION_TAG_NO_DEBUG=v$(jq --raw-output .version package.json)
GIT_TAG=$(git describe --tags | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' || echo "")
VERSION_TAG="${VERSION_TAG_NO_DEBUG}${DEBUG}"
AUTHOR=$(curl -s -H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/commits/${CIRCLE_SHA1}" \
| jq -r '.author.login')
COMMITTER=$(curl -s -H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/commits/${CIRCLE_SHA1}" \
| jq -r '.commit.committer.email')
if [ "${VERSION_TAG_NO_DEBUG}" = "${GIT_TAG}" ]; then
export EXTRA_TAG="${VERSION_TAG}"
fi
echo "Starting build.sh"
if [ "$DOCKER_PASSWORD" != "" ]; then
docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD
export PUSH_IMAGES=${PUSH_IMAGES}
else
export PUSH_IMAGES=false
fi
if [ "$PRODUCTION_API_TOKEN" != "" ]; then
balena login --token $PRODUCTION_API_TOKEN
export DEPLOY_TO_PRODUCTION=${DEPLOY_TO_PRODUCTION}
else
export DEPLOY_TO_PRODUCTION=false
fi
if [ "$STAGING_API_TOKEN" != "" ]; then
export DEPLOY_TO_PRODUCTION=${DEPLOY_TO_STAGING}
else
export DEPLOY_TO_STAGING=false
fi
# Create required env vars
export TAG=$(echo ${CIRCLE_BRANCH} | sed 's/[^a-z0-9A-Z_.-]/-/g')
export ARCH=${ARCH}
export PROJECT_NAME=${ARCH}-supervisor
export SERVICE_NAME=balena-supervisor
# start the build for this architecture
bash automation/build.sh
if [ "${CIRCLE_BRANCH}" = "master" ] && [ "${AUTHOR}" = "balena-ci" ] && [ "${COMMITTER}" = "versionbot@balena.io" ] && [ "${DEPLOY_TO_STAGING}" = "true" ]; then
echo "Deploying to balena API (staging)"
BALENARC_BALENA_URL=$STAGING_API_ENDPOINT balena login --token $STAGING_API_TOKEN
# Create a draft release first in case the second step fails
releaseId=$(BALENARC_BALENA_URL=$STAGING_API_ENDPOINT balena deploy ${BALENA_OS_ORG}/${PROJECT_NAME} \
--draft \
--projectName ${PROJECT_NAME} --tag ${TAG} \
--release-tag version ${VERSION_TAG} | sed -n 's/.*Release: //p')
echo "Successfully deployed release ${releaseId}"
# Set release_version as is still needed some places
curl -X PATCH -H "Content-type: application/json" -H "Authorization: Bearer ${STAGING_API_TOKEN}" \
"https://api.${STAGING_API_ENDPOINT}/v6/release?\$filter=commit%20eq%20'${releaseId}'%20and%20belongs_to__application/any(bta:bta/slug%20eq%20'${BALENA_OS_ORG}%2F${PROJECT_NAME}')" \
-d "{\"release_version\": \"${VERSION_TAG}\", \"is_final\": true}"
# Cleanup credentials just in case
rm ~/.balena/token
fi
if [ "${CIRCLE_BRANCH}" = "master" ] && [ "${AUTHOR}" = "balena-ci" ] && [ "${COMMITTER}" = "versionbot@balena.io" ] && [ "${DEPLOY_TO_PRODUCTION}" = "true" ]; then
echo "Deploying to balena API (production)"
BALENARC_BALENA_URL=$PRODUCTION_API_ENDPOINT balena login --token $PRODUCTION_API_TOKEN
# Create a draft release first in case the second step fails
releaseId=$(BALENARC_BALENA_URL=$PRODUCTION_API_ENDPOINT balena deploy ${BALENA_OS_ORG}/${PROJECT_NAME} \
--draft \
--projectName ${PROJECT_NAME} --tag ${TAG} \
--release-tag version ${VERSION_TAG} | sed -n 's/.*Release: //p')
# Set release_version as is still needed some places
curl -X PATCH -H "Content-type: application/json" -H "Authorization: Bearer ${PRODUCTION_API_TOKEN}" \
"https://api.${PRODUCTION_API_ENDPOINT}/v6/release?\$filter=commit%20eq%20'${releaseId}'%20and%20belongs_to__application/any(bta:bta/slug%20eq%20'${BALENA_OS_ORG}%2F${PROJECT_NAME}')" \
-d "{\"release_version\": \"${VERSION_TAG}\", \"is_final\": true}"
# Cleanup credentials just in case
rm ~/.balena/token
fi
version: 2
jobs:
generic:
docker:
- image: balenalib/amd64-alpine-node:12
steps:
- checkout
- run:
name: Install dependencies
command: |
apk add dbus-dev python3 make \
gcc libgcc libc-dev g++
- run:
name: Run tests
command: |
JOBS=max npm ci && npm test
environment:
DOCKER_USERNAME: travisciresin
ARCH: amd64
PUSH_IMAGES: 'true'
STAGING_API_ENDPOINT: balena-staging.com
PRODUCTION_API_ENDPOINT: balena-cloud.com
DEBUG: ''
amd64:
<<: *defaults
environment:
DOCKER_USERNAME: travisciresin
ARCH: amd64
PUSH_IMAGES: 'true'
STAGING_API_ENDPOINT: balena-staging.com
PRODUCTION_API_ENDPOINT: balena-cloud.com
DEPLOY_TO_PRODUCTION: 'true'
DEPLOY_TO_STAGING: 'true'
BALENA_OS_ORG: 'balena_os'
DEBUG: ''
i386:
<<: *defaults
environment:
DOCKER_USERNAME: travisciresin
ARCH: i386
PUSH_IMAGES: 'true'
STAGING_API_ENDPOINT: balena-staging.com
PRODUCTION_API_ENDPOINT: balena-cloud.com
DEPLOY_TO_PRODUCTION: 'true'
DEPLOY_TO_STAGING: 'true'
BALENA_OS_ORG: 'balena_os'
DEBUG: ''
armv7hf:
<<: *defaults
environment:
DOCKER_USERNAME: travisciresin
ARCH: armv7hf
PUSH_IMAGES: 'true'
STAGING_API_ENDPOINT: balena-staging.com
PRODUCTION_API_ENDPOINT: balena-cloud.com
DEPLOY_TO_PRODUCTION: 'true'
DEPLOY_TO_STAGING: 'true'
BALENA_OS_ORG: 'balena_os'
DEBUG: ''
aarch64:
<<: *defaults
environment:
DOCKER_USERNAME: travisciresin
ARCH: aarch64
PUSH_IMAGES: 'true'
STAGING_API_ENDPOINT: balena-staging.com
PRODUCTION_API_ENDPOINT: balena-cloud.com
DEPLOY_TO_PRODUCTION: 'true'
DEPLOY_TO_STAGING: 'true'
BALENA_OS_ORG: 'balena_os'
DEBUG: ''
rpi:
<<: *defaults
environment:
DOCKER_USERNAME: travisciresin
ARCH: rpi
PUSH_IMAGES: 'true'
STAGING_API_ENDPOINT: balena-staging.com
PRODUCTION_API_ENDPOINT: balena-cloud.com
DEPLOY_TO_PRODUCTION: 'true'
DEPLOY_TO_STAGING: 'true'
BALENA_OS_ORG: 'balena_os'
DEBUG: ''
workflows:
version: 2
build_and_maybe_deploy:
jobs:
- generic
- amd64:
requires:
- generic
- i386:
requires:
- generic
- rpi:
requires:
- generic
- armv7hf:
requires:
- generic
- aarch64:
requires:
- generic