Skip to content

Commit

Permalink
feat(system): Include opentrons api server from external tree
Browse files Browse the repository at this point in the history
- Adds a BR2_EXTERNAL tree from the
  monorepo (Opentrons/opentrons#3217) and pulls in the opentrons api server to the build.

- Fixes some issues in systemd services and targets. Codebuild rewrites
  broken (and maybe non-broken) absolute links to fit inside its chroot jail,
  which was breaking the absolute links that aren’t supposed to be valid until
  they’re on the robot

- Add a VERSIONS file taken from a combination of the buildroot version (from
  git) and opentrons api server versions (from package.json) and save to
  /etc/VERSIONS.json

- VERSIONS.json is a new artifact and also zipped up with the full images and
  update images when uploaded to s3

Closes Opentrons/opentrons#2877
  • Loading branch information
sfoster1 committed Mar 26, 2019
1 parent 5b34077 commit ffa34c7
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
*.rej
*~
*.pyc
.env
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG filter_output
VOLUME /buildroot

RUN apt-get -y update &&\
apt-get -y install build-essential wget file cpio python rsync unzip bc libncurses-dev
apt-get -y install build-essential wget file cpio python rsync unzip bc libncurses-dev git

RUN wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.23.0.tar.xz &&\
tar xf ./crosstool-* &&\
Expand Down
6 changes: 6 additions & 0 deletions board/opentrons/ot2/post-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ sed -i s/kernel=zImage/kernel=u-boot.bin/ ${BINARIES_DIR}/rpi-firmware/config.tx
# write common pubkey to authorized keys
# TODO: DO NOT DO THIS IN RELEASE BUILDS
cat ${TARGET_DIR}/var/home/.ssh/robot_key.pub > ${TARGET_DIR}/var/home/.ssh/authorized_keys

# Load the out-of-container env to get stuff from codebuild
export $(cat /buildroot/.env | xargs)

python ./board/opentrons/ot2/write_version.py ${BINARIES_DIR}/opentrons-api-version.json ${BINARIES_DIR}/VERSION.json
cp ${BINARIES_DIR}/VERSION.json ${TARGET_DIR}/etc/VERSION.json
8 changes: 8 additions & 0 deletions board/opentrons/ot2/post-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ BOARD_NAME="$(basename ${BOARD_DIR})"
GENIMAGE_CFG="${BOARD_DIR}/genimage-${BOARD_NAME}.cfg"
GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"

sed -i -e 's/console=ttyAMA0,115200//' "${BINARIES_DIR}/rpi-firmware/cmdline.txt"

for arg in "$@"
do
case "${arg}" in
Expand Down Expand Up @@ -61,4 +63,10 @@ genimage \
--outputpath "${BINARIES_DIR}" \
--config "${GENIMAGE_CFG}"

rm -f ${BINARIES_DIR}/ot2-system.zip
zip -j ${BINARIES_DIR}/ot2-system.zip ${BINARIES_DIR}/rootfs.ext4 ${BINARIES_DIR}/VERSION.json
rm -f ${BINARIES_DIR}/ot2-fullimage.zip
zip -j ${BINARIES_DIR}/ot2-fullimage.zip ${BINARIES_DIR}/sdcard.img ${BINARIES_DIR}/VERSION.json


exit $?
2 changes: 1 addition & 1 deletion board/opentrons/ot2/rootfs-overlay/etc/dropbear
2 changes: 1 addition & 1 deletion board/opentrons/ot2/rootfs-overlay/etc/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ http {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 1h;
proxy_pass http://unix:/tmp/aiohttp.sock;
proxy_pass http://unix:/run/aiohttp.sock;
}

location /server {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[Unit]
Description=Opentrons: Ensure system wired connections
Before=NetworkManager.service
Requires=local-fs.target
After=local-fs.target
Requires=basic.target
After=basic.target

[Service]
Type=oneshot
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=Opentrons: Run user-supplied boot scripts
Requires=local-fs.target
After=local-fs.target
Requires=basic.target
After=basic.target

[Service]
Type=oneshot
Expand Down
56 changes: 56 additions & 0 deletions board/opentrons/ot2/write_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import json
import os
import sys
import subprocess
import argparse

try:
br_version = subprocess.check_output(
['git', 'describe', '--tags', '--always'],
stderr=subprocess.STDOUT).decode().strip()
except subprocess.CalledProcessError as cpe:
print("{}: {}: {}".format(cpe.cmd, cpe.returncode, cpe.stdout))
print("Defaulting to (unknown)")
br_version = 'unknown'

try:
br_sha = subprocess.check_output(
['git', 'rev-parse', 'HEAD'],
stderr=subprocess.STDOUT).decode().strip()
except subprocess.CalledProcessError as cpe:
print("{}: {}: {}".format(cpe.cmd, cpe.returncode, cpe.stdout))
print("Defaulting to (unknown)")
br_sha = 'unknown'

try:
br_branch_from_git = subprocess.check_output(
['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
stderr=subprocess.STDOUT).decode().strip()
except subprocess.CalledProcessError as cpe:
print("{}: {}: {}".format(cpe.cmd, cpe.returncode, cpe.stdout))
print("Defaulting to (unknown)")
br_branch = 'unknown'

br_branch = os.getenv('CODEBUILD_SOURCE_VERSION', br_branch_from_git)
build_id = os.getenv('CODEBUILD_BUILD_ID', 'dev')

parser = argparse.ArgumentParser(description='Write a version file to buildroot')
parser.add_argument('in_versions', metavar='IN_VERSIONS',
type=argparse.FileType('r'), nargs='+',
help='A list of files to read versions from. These should '
'be json files with non-overlapping keys that will be'
' unified (along with the buildroot version from git)'
' into the final product.')
parser.add_argument('outfile', metavar='OUT', type=argparse.FileType('w'),
help='The file to write to')
args = parser.parse_args()

version_dict = {'buildroot_version': br_version,
'buildroot_sha': br_sha,
'buildroot_branch': br_branch,
'buildroot_buildid': build_id}

for f in args.in_versions:
version_dict.update(json.load(f))

json.dump(version_dict, args.outfile)
10 changes: 5 additions & 5 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ phases:
- "docker build -t opentrons-buildroot ."
build:
commands:
- "docker run --mount type=bind,source=$(pwd),destination=/buildroot opentrons-buildroot ot2_defconfig"
- "docker run --mount type=bind,source=$(pwd),destination=/buildroot opentrons-buildroot all"
- ./opentrons-build.sh
artifacts:
files:
- output/images/sdcard.img
- output/images/rootfs.tar.gz
- output/images/rootfs.ext4
- output/images/ot2-system.zip
- output/images/ot2-fullimage.zip
- output/images/VERSION.json
name: ot2-system
discard-paths: yes
3 changes: 3 additions & 0 deletions configs/ot2_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ BR2_PACKAGE_HOST_DOSFSTOOLS=y
BR2_PACKAGE_HOST_GENEXT2FS=y
BR2_PACKAGE_HOST_GENIMAGE=y
BR2_PACKAGE_HOST_MTOOLS=y

BR2_PACKAGE_PYTHON_OPENTRONS_API=y
BR2_PACKAGE_HOST_ZIP=y
4 changes: 2 additions & 2 deletions in_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fi
if [ -z $filter ]
then
echo "Unfiltered make"
make -C /buildroot $@
BR2_EXTERNAL=/opentrons make -C /buildroot $@
else
echo "Filtered make"
(make -C /buildroot $@ 2>/buildroot/warnings.txt | awk '/^make/;{print $0 >>"/buildroot/buildlog.txt"}') || cat warnings.txt
(BR2_EXTERNAL=/opentrons make -C /buildroot $@ 2>/buildroot/warnings.txt | awk '/^make/;{print $0 >>"/buildroot/buildlog.txt"}') || cat warnings.txt
fi
9 changes: 8 additions & 1 deletion opentrons-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
# are provided, it will run the docker container once with the arguments
set -e -x -o pipefail

DOCKER_BIND="--mount type=bind,source=$(pwd),destination=/buildroot"
DOCKER_BR_BIND_DIR="/buildroot"
DOCKER_OT_BIND_DIR="/opentrons"
DOCKER_BIND_BR="--mount type=bind,source=$(pwd),destination=${DOCKER_BR_BIND_DIR}"
DOCKER_BIND_OT="--mount type=bind,source=$(pwd)/../opentrons,destination=${DOCKER_OT_BIND_DIR}"
DOCKER_BIND="${DOCKER_BIND_BR} ${DOCKER_BIND_OT}"
heads=${@:1:$(($# - 1))}
tail=${@:$#}

Expand All @@ -32,6 +36,9 @@ imgname=opentrons-buildroot-$(git describe --all --dirty --always)

docker build ${filter_arg} -t ${imgname} .

# Save codebuild-relevant env vars to get them inside docker
env | grep 'CODEBUILD\|AWS' >.env

case $# in
0)
docker run ${DOCKER_BIND} ${imgname} ot2_defconfig
Expand Down

0 comments on commit ffa34c7

Please sign in to comment.