farmbot_os/.circleci/config.yml

501 lines
18 KiB
YAML

version: 2.0
defaults: &defaults
docker:
- image: nervesproject/nerves_system_br:1.6.8
environment:
ELIXIR_VERSION: 1.8.1
install_elixir: &install_elixir
run:
name: Install Elixir
command: |
wget https://github.com/elixir-lang/elixir/releases/download/v1.8.1/Precompiled.zip
unzip -d /usr/local/elixir Precompiled.zip
echo 'export PATH=/usr/local/elixir/bin:$PATH' >> $BASH_ENV
install_hex_archives: &install_hex_archives
run:
name: Install archives
command: |
cd /tmp
mix local.hex --force
mix local.rebar --force
mix archive.install hex nerves_bootstrap "~> 1.2" --force
fetch_and_compile_deps: &fetch_and_compile_deps
run:
name: Fetch and compile Elixir dependencies
command: |
mix deps.get
mix compile
install_arduino: &install_arduino
run:
name: Run setup script
command: bash .circleci/setup-arduino.sh
install_slack_helpers: &install_slack_helpers
run:
name: Install Slack Helpers
command: |
wget https://gist.githubusercontent.com/ConnorRigby/03e722be4be70f8588f5ed74420e4eaa/raw/28a51d8f52ec7d569e8f7f20b83349816ddf63cf/slack_message.ex
install_ghr: &install_ghr
run:
name: Install ghr (Github Releases)
command: |
wget https://github.com/tcnksm/ghr/releases/download/v0.9.0/ghr_v0.9.0_linux_amd64.tar.gz
tar xf ghr_v0.9.0_linux_amd64.tar.gz
ln -sf ghr_v0.9.0_linux_amd64/ghr .
install_jq: &install_jq
run:
name: Install jq
command: |
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
chmod +x ./jq-linux64
build_firmware_steps: &build_firmware_steps
steps:
- checkout
- run: git submodule update --init --recursive
- run:
name: Setup ENV
command: |
echo $MIX_TARGET > MIX_TARGET
echo $MIX_ENV > MIX_ENV
cp mix.lock MIX_LOCK
- restore_cache:
key: v9-fbos-{{ checksum "MIX_TARGET" }}-{{ checksum "MIX_ENV" }}-dependency-cache-{{ checksum "MIX_LOCK" }}
- restore_cache:
key: v9-fbos-host-test-dependency-cache-{{ checksum "mix.lock" }}
- <<: *install_elixir
- <<: *install_hex_archives
- run:
name: Build Farmbot OS Firmware
command: |
mix deps.get
mix compile --force
mix firmware
- run:
name: Create artifact dir
command: mkdir -p /nerves/deploy/system/artifacts
- run:
name: Create artifacts
command: |
cp _build/${MIX_TARGET}_${MIX_ENV}/nerves/images/farmbot.fw /nerves/deploy/system/artifacts/farmbot-${MIX_TARGET}-$(cat VERSION).fw
- save_cache:
key: v9-fbos-{{ checksum "MIX_TARGET" }}-{{ checksum "MIX_ENV" }}-dependency-cache-{{ checksum "MIX_LOCK" }}
paths:
- _build/
- deps/
- ~/.nerves/
- save_cache:
key: nerves/deploy/system-{{ checksum "MIX_TARGET" }}-{{ .Branch }}-{{ .Revision }}-{{ .Environment.CIRCLE_TAG }}
paths:
- "/nerves/deploy/system"
deploy_nerves_hub_firmware_steps: &deploy_nerves_hub_firmware_steps
steps:
- checkout
- run: git submodule update --init --recursive
- run:
name: Setup ENV
command: |
echo $MIX_TARGET > MIX_TARGET
echo $MIX_ENV > MIX_ENV
cp mix.lock MIX_LOCK
- restore_cache:
key: v9-fbos-{{ checksum "MIX_TARGET" }}-{{ checksum "MIX_ENV" }}-dependency-cache-{{ checksum "MIX_LOCK" }}
- restore_cache:
key: nerves/deploy/system-{{ checksum "MIX_TARGET" }}-{{ .Branch }}-{{ .Revision }}-{{ .Environment.CIRCLE_TAG }}
- <<: *install_elixir
- <<: *install_hex_archives
- run:
name: Sign Image
command: mix nerves_hub.firmware sign --key notreal /nerves/deploy/system/artifacts/farmbot-${MIX_TARGET}-$(cat VERSION).fw
- run:
name: Publish to NervesHub
command: mix nerves_hub.firmware publish --deploy ${NERVES_HUB_DEPLOY} ${NERVES_HUB_TTL} /nerves/deploy/system/artifacts/farmbot-${MIX_TARGET}-$(cat VERSION).fw
jobs:
################################################################################
# TEST #
################################################################################
test:
<<: *defaults
environment:
MIX_ENV: test
MIX_TARGET: host
ELIXIR_VERSION: 1.8.1
steps:
- checkout
- run: git submodule update --init --recursive
- restore_cache:
key: v9-fbos-host-test-dependency-cache-{{ checksum "mix.lock" }}
- <<: *install_elixir
- <<: *install_hex_archives
- run:
name: Test Farmbot OS
command: |
mix deps.get
mix compile
- save_cache:
key: v9-fbos-host-test-dependency-cache-{{ checksum "mix.lock" }}
paths:
- _build/host_test
- deps
################################################################################
# target=rpi app_env=prod #
################################################################################
build_rpi_prod:
<<: *defaults
environment:
MIX_TARGET: rpi
MIX_ENV: prod
<<: *build_firmware_steps
################################################################################
# target=rpi3 app_env=prod #
################################################################################
build_rpi3_prod:
<<: *defaults
environment:
MIX_TARGET: rpi3
MIX_ENV: prod
<<: *build_firmware_steps
################################################################################
# target=rpi app_env=prod channel=stable #
################################################################################
deploy_rpi_prod_stable:
<<: *defaults
environment:
MIX_TARGET: rpi
MIX_ENV: prod
NERVES_HUB_DEPLOY: rpi-prod-stable
<<: *deploy_nerves_hub_firmware_steps
################################################################################
# target=rpi3 app_env=prod channel=stable #
################################################################################
deploy_rpi3_prod_stable:
<<: *defaults
environment:
MIX_TARGET: rpi3
MIX_ENV: prod
NERVES_HUB_DEPLOY: rpi3-prod-stable
<<: *deploy_nerves_hub_firmware_steps
################################################################################
# target=rpi app_env=prod channel=beta #
################################################################################
deploy_rpi_prod_beta:
<<: *defaults
environment:
MIX_TARGET: rpi
MIX_ENV: prod
NERVES_HUB_DEPLOY: rpi-prod-beta
NERVES_HUB_TTL: "--ttl 3600"
<<: *deploy_nerves_hub_firmware_steps
################################################################################
# target=rpi3 app_env=prod channel=beta #
################################################################################
deploy_rpi3_prod_beta:
<<: *defaults
environment:
MIX_TARGET: rpi3
MIX_ENV: prod
NERVES_HUB_DEPLOY: rpi3-prod-beta
NERVES_HUB_TTL: "--ttl 3600"
<<: *deploy_nerves_hub_firmware_steps
################################################################################
# target=rpi app_env=prod channel=staging #
################################################################################
deploy_rpi_prod_staging:
<<: *defaults
environment:
MIX_TARGET: rpi
MIX_ENV: prod
NERVES_HUB_DEPLOY: rpi-prod-staging
NERVES_HUB_TTL: "--ttl 3600"
<<: *deploy_nerves_hub_firmware_steps
################################################################################
# target=rpi3 app_env=prod channel=staging #
################################################################################
deploy_rpi3_prod_staging:
<<: *defaults
environment:
MIX_TARGET: rpi3
MIX_ENV: prod
NERVES_HUB_DEPLOY: rpi3-prod-staging
NERVES_HUB_TTL: "--ttl 3600"
<<: *deploy_nerves_hub_firmware_steps
################################################################################
# TARGET FIRMWARE NERVES GITHUB RELEASE BETA #
################################################################################
publish_prod_firmware_beta_release:
<<: *defaults
environment:
MIX_ENV: prod
ELIXIR_VERSION: 1.8.1
steps:
- checkout
- run:
name: Setup ENV
command: |
echo rpi3 > MIX_TARGET_RPI3
cp mix.lock MIX_LOCK_RPI3
# echo rpi > MIX_TARGET_RPI
# cp mix.lock.rpi MIX_LOCK_RPI
echo $MIX_ENV > MIX_ENV
- restore_cache:
key: nerves/deploy/system-{{ checksum "MIX_TARGET_RPI3" }}-{{ .Branch }}-{{ .Revision }}-{{ .Environment.CIRCLE_TAG }}
# - restore_cache:
# key: nerves/deploy/system-{{ checksum "MIX_TARGET_RPI" }}-{{ .Branch }}-{{ .Revision }}-{{ .Environment.CIRCLE_TAG }}
- <<: *install_elixir
- <<: *install_hex_archives
- <<: *install_ghr
- <<: *install_slack_helpers
- <<: *install_jq
- add_ssh_keys:
fingerprints:
- "97:92:32:5d:d7:96:e1:fa:f3:6b:f3:bd:d6:aa:84:c6"
- run: grep -Pazo "(?s)(?<=# $(cat VERSION))[^#]+" CHANGELOG.md > RELEASE_NOTES
- run: echo $FWUP_KEY_BASE64 | base64 --decode --ignore-garbage > $NERVES_FW_PRIV_KEY
- run:
name: Sign rpi3 Firmware
command: |
mv /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION).fw /tmp/farmbot-rpi3-$(cat VERSION).fw
fwup -S -s $NERVES_FW_PRIV_KEY -i /tmp/farmbot-rpi3-$(cat VERSION).fw -o /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION)-beta.fw
fwup -a -t complete -i /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION)-beta.fw -d /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION)-beta.img
sha256sum /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION)-beta.img > /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION)-beta.sha256
# - run:
# name: Sign rpi Firmware
# command: |
# mv /nerves/deploy/system/artifacts/farmbot-rpi-$(cat VERSION).fw /tmp/farmbot-rpi-$(cat VERSION).fw
# fwup -S -s $NERVES_FW_PRIV_KEY -i /tmp/farmbot-rpi-$(cat VERSION).fw -o /nerves/deploy/system/artifacts/farmbot-rpi-$(cat VERSION)-beta.fw
# fwup -a -t complete -i /nerves/deploy/system/artifacts/farmbot-rpi-$(cat VERSION)-beta.fw -d /nerves/deploy/system/artifacts/farmbot-rpi-$(cat VERSION)-beta.img
- run:
name: Publish Github Release
command: ./ghr -t $GITHUB_TOKEN -u farmbot -r farmbot_os -prerelease -recreate -prerelease -b "$(cat RELEASE_NOTES)" -c $(git rev-parse --verify HEAD) "v$(cat VERSION)-beta" /nerves/deploy/system/artifacts/
- run:
name: Slack message
command: |
export OTA_URL=$(wget https://api.github.com/repos/farmbot/farmbot_os/releases -qO- | ./jq-linux64 '.[0].url' | sed -e 's/^"//' -e 's/"$//')
export SLACK_MESSAGE="New Farmbot Beta: $OTA_URL"
elixir slack_message.ex $SLACK_MESSAGE
################################################################################
# TARGET FIRMWARE NERVES GITHUB RELEASE MASTER #
################################################################################
publish_prod_firmware_master_release:
<<: *defaults
environment:
MIX_ENV: prod
ELIXIR_VERSION: 1.8.1
steps:
- checkout
- run:
name: Setup ENV
command: |
echo rpi3 > MIX_TARGET_RPI3
cp mix.lock MIX_LOCK_RPI3
# echo rpi > MIX_TARGET_RPI
# cp mix.lock.rpi MIX_LOCK_RPI
echo $MIX_ENV > MIX_ENV
- restore_cache:
key: nerves/deploy/system-{{ checksum "MIX_TARGET_RPI3" }}-{{ .Branch }}-{{ .Revision }}-{{ .Environment.CIRCLE_TAG }}
# - restore_cache:
# key: nerves/deploy/system-{{ checksum "MIX_TARGET_RPI" }}-{{ .Branch }}-{{ .Revision }}-{{ .Environment.CIRCLE_TAG }}
- <<: *install_elixir
- <<: *install_hex_archives
- <<: *install_ghr
- <<: *install_slack_helpers
- add_ssh_keys:
fingerprints:
- "97:92:32:5d:d7:96:e1:fa:f3:6b:f3:bd:d6:aa:84:c6"
- run: grep -Pazo "(?s)(?<=# $(cat VERSION))[^#]+" CHANGELOG.md > RELEASE_NOTES
- run: echo $FWUP_KEY_BASE64 | base64 --decode --ignore-garbage > $NERVES_FW_PRIV_KEY
- run:
name: Sign rpi3 Firmware and create image
command: |
mv /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION).fw /tmp/farmbot-rpi3-$(cat VERSION).fw
fwup -S -s $NERVES_FW_PRIV_KEY -i /tmp/farmbot-rpi3-$(cat VERSION).fw -o /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION).fw
fwup -a -t complete -i /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION).fw -d /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION).img
sha256sum /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION).img > /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION).sha256
# - run:
# name: Sign rpi Firmware and create image
# command: |
# mv /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION).fw /tmp/farmbot-rpi3-$(cat VERSION).fw
# fwup -S -s $NERVES_FW_PRIV_KEY -i /tmp/farmbot-rpi3-$(cat VERSION).fw -o /nerves/deploy/system/artifacts/farmbot-rpi3-$(cat VERSION).fw
# fwup -a -t complete -i /nerves/deploy/system/artifacts/farmbot-rpi-$(cat VERSION).fw -d /nerves/deploy/system/artifacts/farmbot-rpi-$(cat VERSION).img
- run:
name: Publish Github Release
command: ./ghr -t $GITHUB_TOKEN -u farmbot -r farmbot_os -recreate -prerelease -draft -delete -b "$(cat RELEASE_NOTES)" -c $(git rev-parse --verify HEAD) "v$(cat VERSION)" /nerves/deploy/system/artifacts
- run:
name: Send Slack Message
command: elixir slack_message.ex "New Farmbot Prod release $(cat VERSION)"
workflows:
version: 2
test:
jobs:
- test:
context: org-global
filters:
branches:
ignore:
# Merging is blocked on these branches until tests pass.
- beta
- master
- staging
# master branch to staging.farmbot.io
nerves_hub_prod_stable_staging:
jobs:
# - build_rpi_prod:
# context: farmbot-staging
# filters:
# branches:
# only:
# - master
- build_rpi3_prod:
context: farmbot-staging
filters:
branches:
only:
- master
# - deploy_rpi_prod_stable:
# context: farmbot-staging
# requires:
# - build_rpi_prod
- deploy_rpi3_prod_stable:
context: farmbot-staging
requires:
- build_rpi3_prod
# master branch to my.farmbot.io
nerves_hub_prod_stable_production:
jobs:
# - build_rpi_prod:
# context: farmbot-production
# filters:
# branches:
# only:
# - master
- build_rpi3_prod:
context: farmbot-production
filters:
branches:
only:
- master
# - deploy_rpi_prod_stable:
# context: farmbot-production
# requires:
# - build_rpi_prod
- deploy_rpi3_prod_stable:
context: farmbot-production
requires:
- build_rpi3_prod
- publish_prod_firmware_master_release:
context: org-global
requires:
# - build_rpi_prod
- build_rpi3_prod
# beta branch to staging.farmbot.io
nerves_hub_prod_beta_staging:
jobs:
# - build_rpi_prod:
# context: farmbot-staging
# filters:
# branches:
# only:
# - beta
- build_rpi3_prod:
context: farmbot-staging
filters:
branches:
only:
- beta
# - deploy_rpi_prod_beta:
# context: farmbot-staging
# requires:
# - build_rpi_prod
- deploy_rpi3_prod_beta:
context: farmbot-staging
requires:
- build_rpi3_prod
# beta branch to my.farmbot.io
nerves_hub_prod_beta_production:
jobs:
# - build_rpi_prod:
# context: farmbot-production
# filters:
# branches:
# only:
# - beta
- build_rpi3_prod:
context: farmbot-production
filters:
branches:
only:
- beta
# - deploy_rpi_prod_beta:
# context: farmbot-production
# requires:
# - build_rpi_prod
- deploy_rpi3_prod_beta:
context: farmbot-production
requires:
- build_rpi3_prod
- publish_prod_firmware_beta_release:
context: org-global
requires:
# - build_rpi_prod
- build_rpi3_prod
# # staging branch to staging.farmbot.io
# nerves_hub_rpi_prod_staging_staging:
# jobs:
# # - build_rpi_prod:
# # context: farmbot-staging
# # filters:
# # branches:
# # only:
# # - staging
# - build_rpi3_prod:
# context: farmbot-staging
# filters:
# branches:
# only:
# - staging
# # - deploy_rpi_prod_staging:
# # context: farmbot-staging
# # requires:
# # - build_rpi_prod
# - deploy_rpi3_prod_staging:
# context: farmbot-staging
# requires:
# - build_rpi3_prod