diff --git a/.gitignore b/.gitignore index bd1de26..8e3620c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -k-rail -vendor \ No newline at end of file +/k-rail +/evicter +vendor diff --git a/Dockerfile b/Dockerfile index 1a69d35..e5e859f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ ARG GO_VERSION=1.13 FROM golang:${GO_VERSION}-buster AS builder WORKDIR /build COPY ./ /build/ -RUN make test +RUN make clean test RUN make build # Production image build stage @@ -11,5 +11,6 @@ FROM scratch EXPOSE 8443/tcp COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY --from=builder /build/k-rail /k-rail +COPY --from=builder /build/evicter /evicter USER 65534 ENTRYPOINT ["/k-rail", "-config", "/config/config.yml"] diff --git a/Makefile b/Makefile index d5d5857..beec44a 100644 --- a/Makefile +++ b/Makefile @@ -9,13 +9,27 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +.PHONY: all build test image clean -ensure: - dep ensure +LDFLAGS = -extldflags=-static -s -w +BUILD_FLAGS = -mod=readonly -ldflags '$(LDFLAGS)' -trimpath +BUILD_VERSION ?= manual +IMAGE_NAME = "cruise/k-rail:${BUILD_VERSION}" + +all: dist + +dist: image + +clean: + rm -f evicter k-rail + go mod verify build: - GO111MODULE=on CGO_ENABLED=0 go build -o k-rail cmd/main.go + GO111MODULE=on CGO_ENABLED=0 go build ${BUILD_FLAGS} -o k-rail cmd/k-rail/main.go + GO111MODULE=on CGO_ENABLED=0 go build ${BUILD_FLAGS} -o evicter cmd/evicter/*.go test: - GO111MODULE=on CGO_ENABLED=1 go test -race -cover $(shell go list ./... | grep -v /vendor/) - \ No newline at end of file + GO111MODULE=on CGO_ENABLED=1 go test -mod=readonly -race ./... + +image: build + docker build --pull -t $(IMAGE_NAME) . \ No newline at end of file diff --git a/cmd/main.go b/cmd/k-rail/main.go similarity index 100% rename from cmd/main.go rename to cmd/k-rail/main.go