Browse Source

Update Dockerfile to use `make` command

Signed-off-by: llhuii <liulinghui@huawei.com>
tags/v0.1.0
llhuii 4 years ago
parent
commit
8de6a4bcd6
4 changed files with 40 additions and 38 deletions
  1. +2
    -4
      .github/workflows/main.yaml
  2. +21
    -15
      Makefile
  3. +8
    -5
      build/gm/Dockerfile
  4. +9
    -14
      build/lc/Dockerfile

+ 2
- 4
.github/workflows/main.yaml View File

@@ -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

+ 21
- 15
Makefile View File

@@ -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 .

+ 8
- 5
build/gm/Dockerfile View File

@@ -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



+ 9
- 14
build/lc/Dockerfile View File

@@ -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"]





Loading…
Cancel
Save