diff --git a/.dockerignore b/.dockerignore index 8f976e7..d738f6d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,8 +1,10 @@ * # exluding everything and only allowing directly relevant stuff !cmd/server/main.go +!cmd/reactor/main.go !internal !tokens !go.mod !go.sum !server +!reactor diff --git a/Dockerfile.reactor b/Dockerfile.reactor new file mode 100644 index 0000000..371d40e --- /dev/null +++ b/Dockerfile.reactor @@ -0,0 +1,22 @@ +# syntax=docker/dockerfile:1 +FROM --platform=$BUILDPLATFORM golang:1.18-alpine as builder + +WORKDIR /app + +COPY . . + +RUN go mod download + +ARG TARGETOS TARGETARCH TARGETVARIANT + +RUN if [[ $TARGETVARIANT == "v7" ]]; \ +then \ +export GOARM=7; \ +fi; \ +CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /reactor ./cmd/reactor/main.go + +FROM alpine + +COPY --from=builder /reactor . + +ENTRYPOINT [ "./reactor" ] diff --git a/reactor_build.sh b/reactor_build.sh new file mode 100755 index 0000000..455f838 --- /dev/null +++ b/reactor_build.sh @@ -0,0 +1,44 @@ +#!/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