diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 63d24dd1..abcfae61 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -63,7 +63,7 @@ jobs: with: fetch-depth: 0 - - run: make + - run: make build # without verify basic_test: runs-on: ubuntu-latest @@ -132,6 +132,4 @@ jobs: with: fetch-depth: 0 - - run: make gmimage - - - run: make lcimage + - run: make images diff --git a/Makefile b/Makefile index f1683a7b..e30063e1 100644 --- a/Makefile +++ b/Makefile @@ -1,40 +1,45 @@ GOPATH ?= $(shell go env GOPATH) -# make all builds both cloud and edge binaries - +# make all builds both gm and lc binaries BINARIES=gm lc +SHELL=/bin/bash .EXPORT_ALL_VARIABLES: OUT_DIR ?= _output OUT_BINPATH := $(OUT_DIR)/bin -define ALL_HELP_INFO -# Build code. -# +define BUILD_HELP_INFO +# Build code with verifying or not. +# target all is the "build" with verify. # Args: # WHAT: binary names to build. support: $(BINARIES) # the build will produce executable files under ./$(OUT_BINPATH) # If not specified, "everything" will be built. # # Example: -# make -# make all -# make all HELP=y -# make all WHAT=gm -# make all WHAT=lc GOLDFLAGS="" GOGCFLAGS="-N -l" +# make TARGET +# make TARGET HELP=y +# make TARGET WHAT=gm +# make TARGET WHAT=lc GOLDFLAGS="" GOGCFLAGS="-N -l" # Note: Specify GOLDFLAGS as an empty string for building unstripped binaries, specify GOGCFLAGS # to "-N -l" to disable optimizations and inlining, this will be helpful when you want to # use the debugging tools like delve. When GOLDFLAGS is unspecified, it defaults to "-s -w" which strips # debug information, see https://golang.org/cmd/link for other flags. endef -.PHONY: all + +.PHONY: build all ifeq ($(HELP),y) -all: - @echo "$$ALL_HELP_INFO" +build all: + @echo "$${BUILD_HELP_INFO//TARGET/$@}" else -all: verify +# build without verify +# default target +build: hack/make-rules/build.sh $(WHAT) + +all: verify build + endif @@ -104,6 +109,7 @@ IMAGE_REPO ?= ghcr.io/edgeai-neptune/neptune IMAGE_TAG ?= v1alpha1 GO_LDFLAGS ?='' -.PHONY: gmimage lcimage +.PHONY: images gmimage lcimage +images: gmimage lcimage gmimage lcimage: docker build --build-arg GO_LDFLAGS=${GO_LDFLAGS} -t ${IMAGE_REPO}/${@:image=}:${IMAGE_TAG} -f build/${@:image=}/Dockerfile . diff --git a/build/gm/Dockerfile b/build/gm/Dockerfile index 2f8f968e..6359d74b 100644 --- a/build/gm/Dockerfile +++ b/build/gm/Dockerfile @@ -2,18 +2,21 @@ FROM golang:1.14-alpine3.11 AS builder ARG GO_LDFLAGS -WORKDIR /code +# install build tools +RUN apk update +RUN apk add build-base bash +WORKDIR /code # copy source COPY . . +RUN make build WHAT=gm GO_LDFLAGS=$GO_LDFLAGS OUT_DIR=_output -RUN CGO_ENABLED=0 go build -o /usr/local/bin/neptune-gm -ldflags "$GO_LDFLAGS -w -s" \ -cmd/neptune-gm/neptune-gm.go - +# ALT: just using go build +# RUN CGO_ENABLED=0 go build -o _output/bin/neptune-gm -ldflags "$GO_LDFLAGS -w -s" cmd/neptune-gm/neptune-gm.go FROM alpine:3.11 -COPY --from=builder /usr/local/bin/neptune-gm /usr/local/bin/neptune-gm +COPY --from=builder /code/_output/bin/neptune-gm /usr/local/bin/neptune-gm COPY build/gm/gm-config.yaml /gm.yaml diff --git a/build/lc/Dockerfile b/build/lc/Dockerfile index 72df808d..4ecd1492 100644 --- a/build/lc/Dockerfile +++ b/build/lc/Dockerfile @@ -1,24 +1,19 @@ FROM golang:1.14-alpine3.11 AS builder -ARG PROXY - -COPY . /code -WORKDIR /code +ARG GO_LDFLAGS +# install build tools +RUN apk update +RUN apk add build-base bash -RUN if [ ! "$PROXY" = "" ]; then sed -i "s@http://dl-cdn.alpinelinux.org@$PROXY@g" /etc/apk/repositories ; fi - -RUN apk update -RUN apk add build-base +WORKDIR /code +# copy source +COPY . . +RUN make build WHAT=lc GO_LDFLAGS=$GO_LDFLAGS OUT_DIR=_output -RUN GOOS=linux go build -o /usr/local/bin/neptune-lc cmd/neptune-lc/neptune-lc.go FROM alpine:3.11 -COPY --from=builder /usr/local/bin/neptune-lc /usr/local/bin/neptune-lc +COPY --from=builder /code/_output/bin/neptune-lc /usr/local/bin/neptune-lc CMD ["neptune-lc"] - - - -