farmbot_os/.circleci/config.yml

418 lines
14 KiB
YAML
Raw Normal View History

2017-12-13 12:11:00 -07:00
version: 2.0
defaults: &defaults
docker:
2018-11-21 17:20:11 -07:00
- image: nervesproject/nerves_system_br:1.5.2
2017-12-11 20:28:35 -07:00
2017-12-13 12:11:00 -07:00
install_elixir: &install_elixir
run:
name: Install Elixir
command: |
wget https://github.com/elixir-lang/elixir/releases/download/v1.7.3/Precompiled.zip
2017-12-13 12:11:00 -07:00
unzip -d /usr/local/elixir Precompiled.zip
echo 'export PATH=/usr/local/elixir/bin:$PATH' >> $BASH_ENV
2017-12-11 20:28:35 -07:00
2018-01-03 17:09:13 -07:00
install_hex_archives: &install_hex_archives
run:
name: Install archives
2018-01-03 17:10:34 -07:00
command: |
2018-01-26 10:23:56 -07:00
cd /tmp
2018-01-03 17:10:34 -07:00
mix local.hex --force
mix local.rebar --force
mix archive.install hex nerves_bootstrap "~> 1.2" --force
2018-01-03 17:09:13 -07:00
fetch_and_compile_deps: &fetch_and_compile_deps
run:
name: Fetch and compile Elixir dependencies
2018-01-03 17:10:34 -07:00
command: |
mix deps.get
mix compile
2018-01-03 17:09:13 -07:00
2018-01-05 11:46:58 -07:00
install_arduino: &install_arduino
2018-01-05 11:48:19 -07:00
run:
name: Run setup script
command: bash .circleci/setup-arduino.sh
2018-01-05 11:46:58 -07:00
install_slack_helpers: &install_slack_helpers
run:
name: Install Slack Helpers
command: |
wget https://gist.githubusercontent.com/ConnorRigby/03e722be4be70f8588f5ed74420e4eaa/raw/28a51d8f52ec7d569e8f7f20b83349816ddf63cf/slack_message.ex
2018-11-21 17:20:11 -07:00
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
2018-12-13 09:54:50 -07:00
build_deploy_firmware_nerves_hub_steps: &build_deploy_firmware_nerves_hub_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_TARGET MIX_LOCK
- restore_cache:
key: v8-fbos-{{ checksum "MIX_TARGET" }}-{{ checksum "MIX_ENV" }}-dependency-cache-{{ checksum "MIX_LOCK" }}
- restore_cache:
key: v8-fbos-host-test-dependency-cache-{{ checksum "mix.lock.host" }}
- <<: *install_elixir
- <<: *install_hex_archives
- <<: *install_ghr
- 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: v8-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" }}-{{ .Revision }}-{{ .Environment.CIRCLE_TAG }}
paths:
- "/nerves/deploy/system"
- run:
name: NervesHub race condition
command: sleep $((1 + RANDOM % 15))
- 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
2017-12-13 12:11:00 -07:00
jobs:
2018-11-23 15:37:05 -07:00
################################################################################
# TEST #
################################################################################
2017-12-13 12:11:00 -07:00
test:
<<: *defaults
2017-12-31 18:42:26 -07:00
environment:
MIX_ENV: test
2018-01-03 16:48:16 -07:00
MIX_TARGET: host
2018-11-21 17:20:11 -07:00
ELIXIR_VERSION: 1.7.3
SKIP_ARDUINO_BUILD: 1
2017-12-11 20:28:35 -07:00
steps:
2018-01-05 12:35:47 -07:00
- checkout
2018-01-05 12:27:12 -07:00
- run: git submodule update --init --recursive
2018-01-05 12:11:12 -07:00
- restore_cache:
2018-12-13 09:54:50 -07:00
key: v8-fbos-host-test-dependency-cache-{{ checksum "mix.lock.host" }}
2018-11-21 17:20:11 -07:00
- <<: *install_elixir
2018-01-03 17:09:13 -07:00
- <<: *install_hex_archives
2018-11-21 17:20:11 -07:00
- run:
name: Test Farmbot OS
command: |
mix deps.get
mix compile
- save_cache:
2018-12-13 09:54:50 -07:00
key: v8-fbos-host-test-dependency-cache-{{ checksum "mix.lock.host" }}
paths:
- _build/host
- deps/host
2018-11-23 15:37:05 -07:00
2018-12-13 09:54:50 -07:00
rpi_prod_stable:
2017-12-13 12:11:00 -07:00
<<: *defaults
2017-12-13 11:51:27 -07:00
environment:
2018-11-21 17:20:11 -07:00
ELIXIR_VERSION: 1.7.3
SKIP_ARDUINO_BUILD: 1
2018-11-23 15:37:05 -07:00
MIX_TARGET: rpi
2018-01-03 16:48:16 -07:00
MIX_ENV: prod
2018-12-13 09:54:50 -07:00
NERVES_HUB_DEPLOY: rpi-prod-stable
<<: *build_deploy_firmware_nerves_hub_steps
2018-11-23 15:37:05 -07:00
2018-12-13 09:54:50 -07:00
rpi3_prod_stable:
2018-11-23 15:37:05 -07:00
<<: *defaults
environment:
ELIXIR_VERSION: 1.7.3
SKIP_ARDUINO_BUILD: 1
2018-12-13 09:54:50 -07:00
MIX_TARGET: rpi3
MIX_ENV: prod
NERVES_HUB_DEPLOY: rpi3-prod-stable
<<: *build_deploy_firmware_nerves_hub_steps
2018-11-23 15:37:05 -07:00
2018-12-13 09:54:50 -07:00
rpi_prod_beta:
2018-11-21 17:20:11 -07:00
<<: *defaults
environment:
ELIXIR_VERSION: 1.7.3
SKIP_ARDUINO_BUILD: 1
2018-12-13 09:54:50 -07:00
MIX_TARGET: rpi
MIX_ENV: prod
NERVES_HUB_DEPLOY: rpi-prod-beta
NERVES_HUB_TTL: "--ttl 3600"
<<: *build_deploy_firmware_nerves_hub_steps
2018-11-23 15:37:05 -07:00
2018-12-13 09:54:50 -07:00
rpi3_prod_beta:
2018-11-23 15:37:05 -07:00
<<: *defaults
environment:
ELIXIR_VERSION: 1.7.3
SKIP_ARDUINO_BUILD: 1
2018-12-13 09:54:50 -07:00
MIX_TARGET: rpi3
MIX_ENV: prod
NERVES_HUB_DEPLOY: rpi3-prod-beta
NERVES_HUB_TTL: "--ttl 3600"
<<: *build_deploy_firmware_nerves_hub_steps
2018-11-23 15:37:05 -07:00
2018-12-13 09:54:50 -07:00
rpi_prod_staging:
2018-11-21 17:20:11 -07:00
<<: *defaults
environment:
ELIXIR_VERSION: 1.7.3
SKIP_ARDUINO_BUILD: 1
2018-12-13 09:54:50 -07:00
MIX_TARGET: rpi
MIX_ENV: prod
NERVES_HUB_DEPLOY: rpi-prod-staging
NERVES_HUB_TTL: "--ttl 3600"
<<: *build_deploy_firmware_nerves_hub_steps
2018-11-23 15:37:05 -07:00
2018-12-13 09:54:50 -07:00
rpi3_prod_staging:
2018-01-03 11:56:52 -07:00
<<: *defaults
2018-11-21 17:20:11 -07:00
environment:
ELIXIR_VERSION: 1.7.3
SKIP_ARDUINO_BUILD: 1
2018-12-13 09:54:50 -07:00
MIX_TARGET: rpi3
MIX_ENV: prod
NERVES_HUB_DEPLOY: rpi3-prod-staging
NERVES_HUB_TTL: "--ttl 3600"
<<: *build_deploy_firmware_nerves_hub_steps
2018-11-23 15:37:05 -07:00
################################################################################
# TARGET FIRMWARE NERVES GITHUB RELEASE BETA #
################################################################################
publish_prod_firmware_beta_release:
<<: *defaults
environment:
MIX_ENV: prod
ELIXIR_VERSION: 1.7.3
SKIP_ARDUINO_BUILD: 1
steps:
- checkout
2018-12-13 09:54:50 -07:00
- run:
name: Setup ENV
command: |
echo rpi3 > MIX_TARGET_RPI3
echo rpi > MIX_TARGET_RPI
echo $MIX_ENV > MIX_ENV
cp mix.lock.rpi3 MIX_LOCK_RPI3
cp mix.lock.rpi MIX_LOCK_RPI
2018-11-23 15:37:05 -07:00
- restore_cache:
2018-12-13 09:54:50 -07:00
key: nerves/deploy/system-{{ checksum "MIX_TARGET_RPI3" }}-{{ .Revision }}-{{ .Environment.CIRCLE_TAG }}
2018-11-23 15:37:05 -07:00
- restore_cache:
2018-12-13 09:54:50 -07:00
key: nerves/deploy/system-{{ checksum "MIX_TARGET_RPI" }}-{{ .Revision }}-{{ .Environment.CIRCLE_TAG }}
2018-05-09 15:25:41 -06:00
- <<: *install_elixir
2018-11-21 17:20:11 -07:00
- <<: *install_hex_archives
- <<: *install_ghr
- <<: *install_slack_helpers
2018-11-21 17:20:11 -07:00
- <<: *install_jq
2018-01-04 10:18:46 -07:00
- run:
name: Run setup script
command: bash .circleci/setup-heroku.sh
- add_ssh_keys:
fingerprints:
- "97:92:32:5d:d7:96:e1:fa:f3:6b:f3:bd:d6:aa:84:c6"
2018-11-23 15:37:05 -07:00
- run: grep -Pazo "(?s)(?<=# $(cat VERSION))[^#]+" CHANGELOG.md > RELEASE_NOTES
- run: echo $FWUP_KEY_BASE64 | base64 --decode --ignore-garbage > $NERVES_FW_PRIV_KEY
2018-01-03 11:56:52 -07:00
- run:
2018-11-23 15:37:05 -07:00
name: Sign rpi3 Firmware
2018-01-03 11:57:59 -07:00
command: |
2018-11-23 15:37:05 -07:00
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
2018-01-03 11:56:52 -07:00
- run:
2018-11-23 15:37:05 -07:00
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
2018-01-03 11:56:52 -07:00
- run:
2018-11-21 17:20:11 -07:00
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/
2018-01-04 10:19:38 -07:00
- run:
2018-01-04 10:18:46 -07:00
name: Update heroku env
command: |
2018-01-21 15:10:45 -07:00
export OTA_URL=$(wget https://api.github.com/repos/farmbot/farmbot_os/releases -qO- | ./jq-linux64 '.[0].url' | sed -e 's/^"//' -e 's/"$//')
2018-05-09 15:35:54 -06:00
export SLACK_MESSAGE="New Farmbot Beta: $OTA_URL"
2018-01-04 10:54:33 -07:00
heroku config:set BETA_OTA_URL=$OTA_URL --app=farmbot-production
heroku config:set BETA_OTA_URL=$OTA_URL --app=farmbot-staging
elixir slack_message.ex $SLACK_MESSAGE
2018-11-23 15:37:05 -07:00
################################################################################
# TARGET FIRMWARE NERVES GITHUB RELEASE MASTER #
################################################################################
publish_prod_firmware_master_release:
<<: *defaults
environment:
MIX_ENV: prod
2018-11-21 17:20:11 -07:00
ELIXIR_VERSION: 1.7.3
SKIP_ARDUINO_BUILD: 1
steps:
- checkout
2018-12-13 09:54:50 -07:00
- run:
name: Setup ENV
command: |
echo rpi3 > MIX_TARGET_RPI3
echo rpi > MIX_TARGET_RPI
echo $MIX_ENV > MIX_ENV
cp mix.lock.rpi3 MIX_LOCK_RPI3
cp mix.lock.rpi MIX_LOCK_RPI
- restore_cache:
2018-12-13 09:54:50 -07:00
key: nerves/deploy/system-{{ checksum "MIX_TARGET_RPI3" }} -{{ .Revision }}-{{ .Environment.CIRCLE_TAG }}
2018-11-21 17:20:11 -07:00
- restore_cache:
2018-12-13 09:54:50 -07:00
key: nerves/deploy/system-{{ checksum "MIX_TARGET_RPI" }}-{{ .Revision }}-{{ .Environment.CIRCLE_TAG }}
2018-11-21 17:20:11 -07:00
- <<: *install_elixir
- <<: *install_hex_archives
- <<: *install_ghr
- <<: *install_slack_helpers
2018-01-08 12:39:32 -07:00
- run:
2018-11-21 17:20:11 -07:00
name: Run setup script
command: bash .circleci/setup-heroku.sh
- add_ssh_keys:
fingerprints:
- "97:92:32:5d:d7:96:e1:fa:f3:6b:f3:bd:d6:aa:84:c6"
2018-11-23 15:37:05 -07:00
- run: grep -Pazo "(?s)(?<=# $(cat VERSION))[^#]+" CHANGELOG.md > RELEASE_NOTES
- run: echo $FWUP_KEY_BASE64 | base64 --decode --ignore-garbage > $NERVES_FW_PRIV_KEY
- run:
2018-11-23 15:37:05 -07:00
name: Sign rpi3 Firmware and create image
command: |
2018-11-23 15:37:05 -07:00
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/farmbot-rpi3-$(cat VERSION).img
- run:
2018-11-23 15:37:05 -07:00
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/farmbot-rpi-$(cat VERSION).img
- run:
2018-11-21 17:20:11 -07:00
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/
- run:
name: Send Slack Message
command: elixir slack_message.ex "New Farmbot Prod release $(cat VERSION)"
2018-11-23 15:37:05 -07:00
2017-12-13 11:51:27 -07:00
workflows:
version: 2
2018-11-21 17:20:11 -07:00
test:
2017-12-13 11:51:27 -07:00
jobs:
- test:
2017-12-13 12:11:00 -07:00
context: org-global
2018-01-03 10:28:48 -07:00
filters:
branches:
ignore:
2018-11-21 17:20:11 -07:00
# Merging is blocked on these branches until tests pass.
- beta
- master
2018-11-21 17:20:11 -07:00
- staging
2018-12-13 09:54:50 -07:00
# master branch to staging.farmbot.io
nerves_hub_prod_stable_staging:
2018-11-21 17:20:11 -07:00
jobs:
2018-12-13 09:54:50 -07:00
- rpi_prod_stable:
context: farmbot-staging
2018-11-21 17:20:11 -07:00
filters:
branches:
only:
- master
2018-12-13 09:54:50 -07:00
- rpi3_prod_stable:
context: farmbot-staging
2018-11-23 15:37:05 -07:00
filters:
branches:
only:
- master
2018-12-13 09:54:50 -07:00
# master branch to my.farmbot.io
nerves_hub_prod_stable_production:
jobs:
- rpi_prod_stable:
2018-11-21 17:20:11 -07:00
context: farmbot-production
filters:
branches:
only:
- master
2018-12-13 09:54:50 -07:00
- rpi3_prod_stable:
2018-11-23 15:37:05 -07:00
context: farmbot-production
filters:
branches:
only:
- master
- publish_prod_firmware_master_release:
2017-12-13 12:11:00 -07:00
context: org-global
2018-01-03 16:48:16 -07:00
requires:
2018-12-13 09:54:50 -07:00
- rpi_prod_stable
- rpi3_prod_stable
2018-11-23 15:37:05 -07:00
2018-12-13 09:54:50 -07:00
# beta branch to staging.farmbot.io
nerves_hub_prod_beta_staging:
2018-11-21 17:20:11 -07:00
jobs:
2018-12-13 09:54:50 -07:00
- rpi_prod_beta:
2018-11-21 17:20:11 -07:00
context: farmbot-staging
filters:
branches:
only:
- beta
2018-12-13 09:54:50 -07:00
- rpi3_prod_beta:
context: farmbot-staging
2018-11-23 15:37:05 -07:00
filters:
branches:
only:
- beta
2018-12-13 09:54:50 -07:00
# beta branch to my.farmbot.io
nerves_hub_prod_beta_production:
jobs:
- rpi_prod_beta:
2018-11-21 17:20:11 -07:00
context: farmbot-production
2018-01-03 14:03:44 -07:00
filters:
branches:
only:
2018-01-03 14:14:35 -07:00
- beta
2018-12-13 09:54:50 -07:00
- rpi3_prod_beta:
2018-11-23 15:37:05 -07:00
context: farmbot-production
filters:
branches:
only:
- beta
- publish_prod_firmware_beta_release:
2018-01-03 11:56:52 -07:00
context: org-global
requires:
2018-12-13 09:54:50 -07:00
- rpi_prod_beta
- rpi3_prod_beta
2018-11-23 15:37:05 -07:00
2018-12-13 09:54:50 -07:00
# staging branch to staging.farmbot.io
nerves_hub_rpi_prod_staging_staging:
2018-11-21 17:20:11 -07:00
jobs:
2018-12-13 09:54:50 -07:00
- rpi_prod_staging:
2018-11-21 17:20:11 -07:00
context: farmbot-staging
filters:
branches:
only:
- staging
2018-12-13 09:54:50 -07:00
- rpi3_prod_staging:
2018-11-21 17:20:11 -07:00
context: farmbot-staging
filters:
branches:
only:
- staging