mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-02 20:16:47 +00:00
Merge pull request #1796 from balena-os/circle-ci-experiments
Use balena CLI for deploying to balenaCloud in CircleCI
This commit is contained in:
commit
1a3bdc2516
@ -9,7 +9,6 @@
|
|||||||
# * TAG: The default will be the current branch name
|
# * TAG: The default will be the current branch name
|
||||||
# * PUSH_IMAGES
|
# * PUSH_IMAGES
|
||||||
# * CLEANUP
|
# * CLEANUP
|
||||||
# * MIXPANEL_TOKEN: default key to inject in the supervisor image
|
|
||||||
# * EXTRA_TAG: when PUSH_IMAGES is true, additional tag to push to the registries
|
# * EXTRA_TAG: when PUSH_IMAGES is true, additional tag to push to the registries
|
||||||
#
|
#
|
||||||
# Builds the supervisor for the architecture defined by $ARCH.
|
# Builds the supervisor for the architecture defined by $ARCH.
|
||||||
@ -45,12 +44,12 @@ if ! [ -x "$(command -v npx)" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
PROJECT_NAME="${PROJECT_NAME:-${ARCH}-supervisor}"
|
||||||
|
SERVICE_NAME="${SERVICE_NAME:-main}"
|
||||||
|
|
||||||
# This is the supervisor image we will produce
|
# This is the supervisor image we will produce
|
||||||
TARGET_IMAGE=balena/$ARCH-supervisor:$TAG
|
TARGET_IMAGE=balena/$ARCH-supervisor:$TAG
|
||||||
TARGET_BUILD_IMAGE=balena/$ARCH-supervisor:$TAG-build
|
|
||||||
|
|
||||||
MASTER_IMAGE=balena/$ARCH-supervisor:master
|
MASTER_IMAGE=balena/$ARCH-supervisor:master
|
||||||
MASTER_BUILD_IMAGE=balena/$ARCH-supervisor:master-build
|
|
||||||
|
|
||||||
CACHE_FROM=""
|
CACHE_FROM=""
|
||||||
function useCache() {
|
function useCache() {
|
||||||
@ -88,25 +87,50 @@ function processDockerfile() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deviceType() {
|
||||||
|
case ${ARCH} in
|
||||||
|
aarch64)
|
||||||
|
echo "raspberrypi4-64"
|
||||||
|
;;
|
||||||
|
armv7hf)
|
||||||
|
echo "raspberrypi3"
|
||||||
|
;;
|
||||||
|
rpi)
|
||||||
|
echo "raspberry-pi"
|
||||||
|
;;
|
||||||
|
i386)
|
||||||
|
echo "qemux86"
|
||||||
|
;;
|
||||||
|
amd64)
|
||||||
|
echo "intel-nuc"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "unrecognized architecture ${ARCH}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
export ARCH
|
export ARCH
|
||||||
|
|
||||||
useCache "${TARGET_IMAGE}"
|
useCache "${TARGET_IMAGE}"
|
||||||
useCache "${TARGET_BUILD_IMAGE}"
|
|
||||||
useCache "${MASTER_IMAGE}"
|
useCache "${MASTER_IMAGE}"
|
||||||
useCache "${MASTER_BUILD_IMAGE}"
|
|
||||||
|
|
||||||
# Wait for our cache to be downloaded
|
# Wait for our cache to be downloaded
|
||||||
wait
|
wait
|
||||||
|
|
||||||
BUILD_ARGS="$CACHE_FROM --build-arg ARCH=${ARCH}"
|
BUILD_ARGS="$CACHE_FROM --buildArg ARCH=$ARCH"
|
||||||
# Try to build the first stage
|
|
||||||
processDockerfile | docker build -f - -t "${TARGET_BUILD_IMAGE}" --target BUILD ${BUILD_ARGS} .
|
|
||||||
|
|
||||||
# Now try to build the final stage
|
# Make a copy of the file to match the architecture
|
||||||
processDockerfile | docker build -f - -t "${TARGET_IMAGE}" ${BUILD_ARGS} .
|
processDockerfile > Dockerfile.${ARCH}
|
||||||
|
|
||||||
|
# Build the image
|
||||||
|
balena build --deviceType $(deviceType) --arch ${ARCH} --dockerfile ./Dockerfile.${ARCH} \
|
||||||
|
--projectName ${PROJECT_NAME} --tag ${TAG} ${BUILD_ARGS}
|
||||||
|
|
||||||
if [ "${PUSH_IMAGES}" == "true" ]; then
|
if [ "${PUSH_IMAGES}" == "true" ]; then
|
||||||
retryImagePush "${TARGET_BUILD_IMAGE}" &
|
# Tag the CLI generated image with the target
|
||||||
|
docker tag "${PROJECT_NAME}_${SERVICE_NAME}:${TAG}" ${TARGET_IMAGE}
|
||||||
retryImagePush "${TARGET_IMAGE}" &
|
retryImagePush "${TARGET_IMAGE}" &
|
||||||
|
|
||||||
if [ -n "${EXTRA_TAG}" ]; then
|
if [ -n "${EXTRA_TAG}" ]; then
|
||||||
@ -121,7 +145,6 @@ wait
|
|||||||
if [ "$CLEANUP" = "true" ]; then
|
if [ "$CLEANUP" = "true" ]; then
|
||||||
docker rmi \
|
docker rmi \
|
||||||
"${TARGET_IMAGE}" \
|
"${TARGET_IMAGE}" \
|
||||||
"${TARGET_BUILD_IMAGE}" \
|
"${MASTER_IMAGE}"
|
||||||
"${MASTER_IMAGE}" \
|
|
||||||
"${MASTER_BUILD_IMAGE}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
6
balena.yml
Normal file
6
balena.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
name: balena-supervisor
|
||||||
|
description: >-
|
||||||
|
Balena Supervisor: balena's agent on devices.
|
||||||
|
joinable: false
|
||||||
|
type: sw.application
|
||||||
|
version: 12.10.10
|
98
circle.yml
98
circle.yml
@ -8,7 +8,7 @@ defaults: &defaults
|
|||||||
version: 18.09.3
|
version: 18.09.3
|
||||||
docker_layer_caching: true
|
docker_layer_caching: true
|
||||||
- run:
|
- run:
|
||||||
name: Check docker is running and install git
|
name: Check docker is running and install dependencies
|
||||||
command: |
|
command: |
|
||||||
docker info
|
docker info
|
||||||
apk update && apk upgrade && apk add --no-cache \
|
apk update && apk upgrade && apk add --no-cache \
|
||||||
@ -19,9 +19,15 @@ defaults: &defaults
|
|||||||
nodejs \
|
nodejs \
|
||||||
nodejs-npm \
|
nodejs-npm \
|
||||||
openssh-client
|
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
|
- checkout
|
||||||
- run:
|
- run:
|
||||||
name: Initialize the submodules (yocto layers)
|
name: Initialize the submodules
|
||||||
command: |
|
command: |
|
||||||
git submodule update --init --recursive
|
git submodule update --init --recursive
|
||||||
git clean -fxd base-image
|
git clean -fxd base-image
|
||||||
@ -43,15 +49,54 @@ defaults: &defaults
|
|||||||
else
|
else
|
||||||
export PUSH_IMAGES=false
|
export PUSH_IMAGES=false
|
||||||
fi
|
fi
|
||||||
# start the build for this architecture
|
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 TAG=$(echo ${CIRCLE_BRANCH} | sed 's/[^a-z0-9A-Z_.-]/-/g')
|
||||||
export ARCH=${ARCH}
|
export ARCH=${ARCH}
|
||||||
bash automation/build.sh
|
export PROJECT_NAME=${ARCH}-supervisor
|
||||||
if [ "${CIRCLE_BRANCH}" = "master" ] && [ "${DEPLOY_TO_BALENA}" = "true" ]; then
|
export SERVICE_NAME=main
|
||||||
|
# start the build for this architecture
|
||||||
|
bash -x automation/build.sh
|
||||||
|
if [ "${CIRCLE_BRANCH}" = "master" ] && [ "${DEPLOY_TO_STAGING}" = "true" ]; then
|
||||||
echo "Deploying to balena API (staging)"
|
echo "Deploying to balena API (staging)"
|
||||||
ARCH=${ARCH} TAG=$VERSION_TAG API_KEY=$STAGING_API_KEY API_ENDPOINT=$STAGING_API_ENDPOINT node automation/deploy-to-balena-cloud.js
|
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 gh_branch ${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" ] && [ "${DEPLOY_TO_PRODUCTION}" = "true" ]; then
|
||||||
echo "Deploying to balena API (production)"
|
echo "Deploying to balena API (production)"
|
||||||
ARCH=${ARCH} TAG=$VERSION_TAG API_KEY=$PRODUCTION_API_KEY API_ENDPOINT=$PRODUCTION_API_ENDPOINT node automation/deploy-to-balena-cloud.js
|
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 gh_branch ${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
|
fi
|
||||||
|
|
||||||
version: 2
|
version: 2
|
||||||
@ -74,8 +119,8 @@ jobs:
|
|||||||
DOCKER_USERNAME: travisciresin
|
DOCKER_USERNAME: travisciresin
|
||||||
ARCH: amd64
|
ARCH: amd64
|
||||||
PUSH_IMAGES: 'true'
|
PUSH_IMAGES: 'true'
|
||||||
STAGING_API_ENDPOINT: https://api.balena-staging.com
|
STAGING_API_ENDPOINT: balena-staging.com
|
||||||
PRODUCTION_API_ENDPOINT: https://api.balena-cloud.com
|
PRODUCTION_API_ENDPOINT: balena-cloud.com
|
||||||
DEBUG: ''
|
DEBUG: ''
|
||||||
amd64:
|
amd64:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
@ -83,8 +128,11 @@ jobs:
|
|||||||
DOCKER_USERNAME: travisciresin
|
DOCKER_USERNAME: travisciresin
|
||||||
ARCH: amd64
|
ARCH: amd64
|
||||||
PUSH_IMAGES: 'true'
|
PUSH_IMAGES: 'true'
|
||||||
STAGING_API_ENDPOINT: https://api.balena-staging.com
|
STAGING_API_ENDPOINT: balena-staging.com
|
||||||
PRODUCTION_API_ENDPOINT: https://api.balena-cloud.com
|
PRODUCTION_API_ENDPOINT: balena-cloud.com
|
||||||
|
DEPLOY_TO_PRODUCTION: 'true'
|
||||||
|
DEPLOY_TO_STAGING: 'true'
|
||||||
|
BALENA_OS_ORG: 'balena_os'
|
||||||
DEBUG: ''
|
DEBUG: ''
|
||||||
i386:
|
i386:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
@ -92,8 +140,11 @@ jobs:
|
|||||||
DOCKER_USERNAME: travisciresin
|
DOCKER_USERNAME: travisciresin
|
||||||
ARCH: i386
|
ARCH: i386
|
||||||
PUSH_IMAGES: 'true'
|
PUSH_IMAGES: 'true'
|
||||||
STAGING_API_ENDPOINT: https://api.balena-staging.com
|
STAGING_API_ENDPOINT: balena-staging.com
|
||||||
PRODUCTION_API_ENDPOINT: https://api.balena-cloud.com
|
PRODUCTION_API_ENDPOINT: balena-cloud.com
|
||||||
|
DEPLOY_TO_PRODUCTION: 'true'
|
||||||
|
DEPLOY_TO_STAGING: 'true'
|
||||||
|
BALENA_OS_ORG: 'balena_os'
|
||||||
DEBUG: ''
|
DEBUG: ''
|
||||||
armv7hf:
|
armv7hf:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
@ -101,8 +152,11 @@ jobs:
|
|||||||
DOCKER_USERNAME: travisciresin
|
DOCKER_USERNAME: travisciresin
|
||||||
ARCH: armv7hf
|
ARCH: armv7hf
|
||||||
PUSH_IMAGES: 'true'
|
PUSH_IMAGES: 'true'
|
||||||
STAGING_API_ENDPOINT: https://api.balena-staging.com
|
STAGING_API_ENDPOINT: balena-staging.com
|
||||||
PRODUCTION_API_ENDPOINT: https://api.balena-cloud.com
|
PRODUCTION_API_ENDPOINT: balena-cloud.com
|
||||||
|
DEPLOY_TO_PRODUCTION: 'true'
|
||||||
|
DEPLOY_TO_STAGING: 'true'
|
||||||
|
BALENA_OS_ORG: 'balena_os'
|
||||||
DEBUG: ''
|
DEBUG: ''
|
||||||
aarch64:
|
aarch64:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
@ -110,8 +164,11 @@ jobs:
|
|||||||
DOCKER_USERNAME: travisciresin
|
DOCKER_USERNAME: travisciresin
|
||||||
ARCH: aarch64
|
ARCH: aarch64
|
||||||
PUSH_IMAGES: 'true'
|
PUSH_IMAGES: 'true'
|
||||||
STAGING_API_ENDPOINT: https://api.balena-staging.com
|
STAGING_API_ENDPOINT: balena-staging.com
|
||||||
PRODUCTION_API_ENDPOINT: https://api.balena-cloud.com
|
PRODUCTION_API_ENDPOINT: balena-cloud.com
|
||||||
|
DEPLOY_TO_PRODUCTION: 'true'
|
||||||
|
DEPLOY_TO_STAGING: 'true'
|
||||||
|
BALENA_OS_ORG: 'balena_os'
|
||||||
DEBUG: ''
|
DEBUG: ''
|
||||||
rpi:
|
rpi:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
@ -119,8 +176,11 @@ jobs:
|
|||||||
DOCKER_USERNAME: travisciresin
|
DOCKER_USERNAME: travisciresin
|
||||||
ARCH: rpi
|
ARCH: rpi
|
||||||
PUSH_IMAGES: 'true'
|
PUSH_IMAGES: 'true'
|
||||||
STAGING_API_ENDPOINT: https://api.balena-staging.com
|
STAGING_API_ENDPOINT: balena-staging.com
|
||||||
PRODUCTION_API_ENDPOINT: https://api.balena-cloud.com
|
PRODUCTION_API_ENDPOINT: balena-cloud.com
|
||||||
|
DEPLOY_TO_PRODUCTION: 'true'
|
||||||
|
DEPLOY_TO_STAGING: 'true'
|
||||||
|
BALENA_OS_ORG: 'balena_os'
|
||||||
DEBUG: ''
|
DEBUG: ''
|
||||||
|
|
||||||
workflows:
|
workflows:
|
||||||
|
Loading…
Reference in New Issue
Block a user