moved docker files to sub directory and cleaned up task file

main
KeeganForelight 1 year ago
parent 1cb29899b9
commit 5085500786

4
.gitignore vendored

@ -21,10 +21,6 @@ bin
*.tar.gz
# logs
*.log
# binaries generated in testing
cmd/server/server
cmd/reactor/reactor
cmd/tui/tui
# task related
.task

@ -1 +1 @@
b43ecff1fe53e18c4c9b756b32d38078
fe0b33dbcc236558952eb8f9f91422c9

@ -44,8 +44,8 @@ The project uses a make alternative called [task](https://github.com/go-task/tas
After using `git clone git@github.com:fl-src/FRMS.git` to clone the repository, you can then build binaries of the two commands `server` and `reactor` for testing.
The binaries will be put into the `bin/` folder and will be labeled with the platform and architecture they were built for.
**WARNING**: The reactor binary currently relies on a Linux cli application to interact with the i2c bus.
This may cause undefined behavior when run on a device without the tools installed. More information about this design choice can be found [here](wiki/reactor.md#i2c-issues)
**WARNING**: The reactor binary currently relies on the Linux [i2c-tools](https://archive.kernel.org/oldwiki/i2c.wiki.kernel.org/index.php/I2C_Tools.html) to interact with the i2c bus.
This may cause undefined behavior when run on a device without the tools installed. More information about this design choice can be found [here](wiki/reactor.md#i2c)
### Usage

@ -4,14 +4,19 @@ tasks:
clean:
desc: "clean all of the old binaries"
cmds:
- rm -v bin/* 2>/dev/null
- rm -vf bin/frms_* 2>/dev/null
test:
desc: "Runs the full test suite"
cmds:
- bin/gotest.py
all:
desc: "cleans and builds all"
deps: [clean, bb, server]
desc: "builds arm reactor binaries and arm/amd server binaries"
deps: [arm32-reactor, arm64-reactor, arm64-server, amd64-server]
bb:
desc: "Builds and sends to the beaglebone"
arm32-reactor:
desc: "Builds reactor binary for 32 bit arm linux device"
cmds:
- task: go-build
vars:
@ -19,31 +24,45 @@ tasks:
GOARCH: "arm"
GOOS: "linux"
BUILD_DIR: "reactor"
- scp bin/reactor_linux_arm debian:~/
server:
desc: "Builds server binary"
arm64-reactor:
desc: "Builds reactor binary for 64 bit arm linux device"
cmds:
- task: go-build
vars:
GOARCH: "arm64"
GOOS: "linux"
BUILD_DIR: "reactor"
arm64-server:
desc: "Builds server binary for 64 bit arm linux device"
cmds:
- task: go-build
vars:
GOARCH: "arm64"
GOOS: "linux"
BUILD_DIR: "server"
amd64-server:
desc: "Builds server binary for amd linux machine"
cmds:
- task: go-build
vars:
GOARCH: "amd64"
GOOS: "linux"
BUILD_DIR: "server"
GOOS: "{{OS}}"
GOARCH: "{{ARCH}}"
go-build:
internal: true
cmds:
- go build -o bin/{{.BUILD_DIR}}_{{.GOOS}}_{{.GOARCH}} cmd/{{.BUILD_DIR}}/main.go
- go build -o bin/frms_{{.BUILD_DIR}}_{{.GOOS}}_{{.GOARCH}} cmd/{{.BUILD_DIR}}/main.go
sources:
- internal/pkg/**/*.go
- cmd/{{.BUILD_DIR}}/main.go
generates:
- bin/{{.BUILD_DIR}}_{{.GOOS}}_{{.GOARCH}}
- bin/frms_{{.BUILD_DIR}}_{{.GOOS}}_{{.GOARCH}}
env:
GOARM: "{{.GOARM}}"
GOARCH: "{{.GOARCH}}"
GOOS: "{{.GOOS}}"
test:
desc: "Runs the full test suite"
cmds:
- ./gotest.py

@ -1,149 +0,0 @@
#!/bin/bash
# adding commands
usage() {
# how to use this build script
cat <<EOF
usage: $0 [-c][-l][-i s] s1 [s2....]
s1, s2, etc. the systems to build for (see -l)
Options:
-c, --clean cleans the bin folder of any existing builds
-f, --force same as clean but skips prompt
-l, --list list available systems to build for
-s, --scp will attempt to scp to aplicable devices
-h, --help display this message
EOF
}
list_systems() {
# list available systems to build for
cat <<EOF
Name (shorthand) SCP available? (y/n)
$0 Name or $0 (shorthand) will build for the device
RaspberryPi (rpi) y
BeagleBone (bb) y
Desktop (d) n
Server (s) n
EOF
}
clean_builds() {
# cleans old builds
if [[ "$FORCE"=true ]] ; then
printf 'Cleaning old builds... \n'
rm -v bin/* 2>/dev/null
else
read -p "Clean old builds?(y/n) " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]] ; then
rm -v bin/* 2>/dev/null
fi
fi
printf 'Clean!\n'
}
create_build() {
# create build for $1
case $1 in
'rpi' )
printf 'Building for Raspberry Pi!\n'
GARCH="arm64"
PLATFORM="reactor"
;;
'bb')
printf 'Building for BeagleBone!\n'
GARCH="arm"
GARM="GOARM=7"
PLATFORM="reactor"
;;
's')
printf 'Building for Server!\n'
GARCH="amd64"
PLATFORM="server"
;;
'd')
printf 'Building for Desktop!\n'
GARCH="amd64"
PLATFORM="server"
;;
* )
printf 'ERROR: %s type unrecognized!\n' "$1"
usage
exit 1
;;
esac
# setting up build
OUTFILE=$(printf '%s_linux_%s' "$PLATFORM" "$GARCH")
INFILE=$(printf '%s/main.go' "$PLATFORM")
# building
env GOOS=linux GOARCH="$GARCH" $GARM go build -o bin/"$OUTFILE" cmd/"$INFILE"
echo "Finished"
if [[ "$SCP"=true ]] ; then
printf 'Attempting to transfer to %s\n' "$2"
if [[ "$1" == "bb" ]] ; then
printf 'Copying to %s\n' "192.168.100.90"
scp "$HOME/FRMS/bin/$OUTFILE" debian:~/
else
printf 'SCP Not available!\n'
fi
fi
}
# handle long form
for arg in "$@"; do
shift
case "$arg" in
'--help') set -- "$@" "-h" ;;
'--list') set -- "$@" "-l" ;;
'--scp') set -- "$@" "-s" ;;
'--clean') set -- "$@" "-c" ;;
'--force') set -- "$@" "-f" ;;
*) set -- "$@" "$arg" ;;
esac
done
# handle args
while getopts "lcsfh" opt ; do
case "$opt" in
'h' )
usage
exit 0
;;
'c' )
clean_builds
;;
'f' )
FORCE=true
clean_builds
;;
's' )
SCP=true
;;
'l')
list_systems
;;
'?' )
usage
exit 1
;;
esac
done
shift $(($OPTIND - 1))
for dev in "$@"; do
case "$dev" in
'RaspberryPi') dev='rpi' ;;
'BeagleBone') dev='bb' ;;
'Server') dev='s' ;;
'Desktop') dev='d' ;;
esac
create_build "$dev"
done
printf 'Nothing else to do!\n'
# echo "Compressing binaries for distrubution"
# tar -czf pireactor.tar.gz -C bin reactor_linux_arm64
# tar -czf bbreactor.tar.gz -C bin reactor_linux_arm
# tar -czf server.tar.gz -C bin server_linux_amd64
# tar -czf tui.tar.gz -C bin tui_linux_amd64 tui_linux_arm tui_linux_arm64

@ -3,7 +3,7 @@ FROM --platform=$BUILDPLATFORM golang:1.18-alpine as builder
WORKDIR /app
COPY . .
COPY ../ .
RUN go mod download

@ -1,89 +0,0 @@
#!/usr/bin/env python
import json
import subprocess
class PackageTest:
def __init__(self):
self.status = ""
self.tests = []
self.totaltime = 0
res = {}
output = subprocess.run(["go","test","-count=1","-json","./..."], capture_output=True, text=True)
output = str(output.stdout)
output = output.split('\n')
for line in output[:-1]:
# parse the json
parsed = json.loads(line)
action = parsed["Action"]
# skip
if action in ["start", "output", "run"]:
continue
# create blank if doesn't exist
if parsed["Package"] not in res:
res[parsed["Package"]] = PackageTest()
pkg = res[parsed["Package"]]
if "Test" not in parsed:
# top level package result
pkg.status = action
if "Elapsed" in parsed:
pkg.totaltime = parsed["Elapsed"]
else:
# individual test
pkg.tests.append((parsed["Test"],parsed["Action"],parsed["Elapsed"]))
totalRan = 0
totalPassed = 0
totalTime = 0
# generating output from parsed json
for name, info in res.items():
pkgname = name.split('/')
pkgname = '/'.join(name.split('/')[1:])
if info.status == "skip":
print("Skipped %s" % (pkgname))
continue
print("\nTesting %s:" % (pkgname))
passed = 0
total = 0
for test in info.tests:
total += 1
out = []
if test[1] == "pass":
passed += 1
out = [" " + test[0] + ":",'\033[32mpass\033[0m ',str(test[2]) + 's']
elif test[1] == "fail":
out = [" " + test[0] + ":",'\033[31mfail\033[0m ',str(test[2]) + 's']
print(f"{out[0] : <30}{out[1] : >5}{out[2] : >8}")
result = ""
if info.status == "pass":
result = "\033[32mPASSED\033[0m"
else:
result = "\033[31mFAILED\033[0m"
# keep track of grand totals
totalRan += total
totalPassed += passed
totalTime += info.totaltime
print(" %s %d/%d in %.3fs/n" % (result, passed, total, info.totaltime))
# output overall test statistics
if totalRan == totalPassed:
result = "\033[32mPASSED\033[0m"
else:
result = "\033[31mFAILED\033[0m"
print("\nSUMMARY:\n\t%s %d/%d in %.3fs" % (result, totalPassed, totalRan, totalTime))

@ -1,44 +0,0 @@
#!/bin/bash
display_usage() {
echo "Usage: $0 reactor_type"
}
# checking for help options
if [[ $@ == "--help" || $@ == "-h" ]]
then
display_usage
exit 0
fi
# checking that arguements are not empty
if [[ -z $1 ]]
then
echo "Type of reactor not specified!"
display_usage
exit 1
fi
# checking for valid reactor types
if [[ $1 == "pi" ]]
then
platform="linux/arm64"
elif [[ $1 == "bb" ]]
then
platform="linux/arm/v7"
else
echo "Reactor type $1 not supported!"
echo "Supported reactors include: pi, bb"
display_usage
exit 1
fi
# building reactor image
echo "Building Reactor image for $1 platform=$platform"
docker buildx build --rm --platform=$platform -f Dockerfile.reactor --tag localhost:5000/reactor .
echo "Cleaning local images"
docker image remove localhost:5000/reactor

@ -1,2 +0,0 @@
#!/bin/bash
echo $(git ls-files | grep .go | awk '!/pb/' | xargs wc -l | tail -n 1)

@ -8,8 +8,3 @@ This will describe the hardware used
## I2C
<a name="i2c-issues">
### Issues
</a>
Should link here

Loading…
Cancel
Save