Skip to content

Commit

Permalink
🐳 Fix dockerfile
Browse files Browse the repository at this point in the history
Signed-off-by: vankichi <[email protected]>
  • Loading branch information
vankichi committed Dec 11, 2023
1 parent a546a5d commit ce7414d
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 55 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ TELEPRESENCE_VERSION := $(eval TELEPRESENCE_VERSION := $(shell cat versions
VALDCLI_VERSION := $(eval VALDCLI_VERSION := $(shell cat versions/VALDCLI_VERSION))$(VALDCLI_VERSION)
YQ_VERSION := $(eval YQ_VERSION := $(shell cat versions/YQ_VERSION))$(YQ_VERSION)
BUF_VERSION := $(eval BUF_VERSION := $(shell cat versions/BUF_VERSION))$(BUF_VERSION)
ZLIB_VERSION := $(eval ZLIB_VERSION := $(shell cat versions/ZLIB_VERSION))$(ZLIB_VERSION)
HDF5_VERSION := $(eval HDF5_VERSION := $(shell cat versions/HDF5_VERSION))$(HDF5_VERSION)

OTEL_OPERATOR_RELEASE_NAME ?= opentelemetry-operator
PROMETHEUS_RELEASE_NAME ?= prometheus
Expand Down Expand Up @@ -265,7 +267,7 @@ GO_ALL_TEST_SOURCES = $(GO_TEST_SOURCES) $(GO_OPTION_TEST_SOURCES)
DOCKER ?= docker
DOCKER_OPTS ?=

DISTROLESS_IMAGE ?= gcr.io/distroless/base
DISTROLESS_IMAGE ?= gcr.io/distroless/static
DISTROLESS_IMAGE_TAG ?= nonroot
UPX_OPTIONS ?= -9
GOLINES_MAX_WIDTH ?= 200
Expand Down
10 changes: 5 additions & 5 deletions Makefile.d/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,14 @@ cmd/tools/benchmark/job/job: \
GOPRIVATE=$(GOPRIVATE) \
go build \
--ldflags "-w -linkmode 'external' \
-extldflags '-static -fPIC -pthread -fopenmp -std=gnu++20' \
-extldflags '-static -fPIC -pthread -fopenmp -std=gnu++20 -lhdf5 -lhdf5_hl -lm -ldl' \
-X '$(GOPKG)/internal/info.Version=$(VERSION)' \
-X '$(GOPKG)/internal/info.GitCommit=$(GIT_COMMIT)' \
-X '$(GOPKG)/internal/info.BuildTime=$(DATETIME)' \
-X '$(GOPKG)/internal/info.GoVersion=$(GO_VERSION)' \
-X '$(GOPKG)/internal/info.GoOS=$(GOOS)' \
-X '$(GOPKG)/internal/info.GoArch=$(GOARCH)' \
-X '$(GOPKG)/internal/info.CGOEnabled=$${CGO_ENABLED}' \
-X '$(GOPKG)/internal/info.CGOEnabled=${CGO_ENABLED}' \
-X '$(GOPKG)/internal/info.NGTVersion=$(NGT_VERSION)' \
-X '$(GOPKG)/internal/info.BuildCPUInfoFlags=$(CPU_INFO_FLAGS)' \
-buildid=" \
Expand All @@ -368,15 +368,15 @@ cmd/tools/benchmark/operator/operator: \
GO111MODULE=on \
GOPRIVATE=$(GOPRIVATE) \
go build \
--ldflags "-s -w \
-X '$(GOPKG)/internal/info.CGOEnabled=$${CGO_ENABLED}' \
--ldflags "-w -extldflags=-static \
-X '$(GOPKG)/internal/info.CGOEnabled=${CGO_ENABLED}' \
-X '$(GOPKG)/internal/info.NGTVersion=$(NGT_VERSION)' \
-X '$(GOPKG)/internal/info.BuildCPUInfoFlags=$(CPU_INFO_FLAGS)' \
-buildid=" \
-mod=readonly \
-modcacherw \
-a \
-tags "cgo osusergo netgo" \
-tags "osusergo netgo static_build" \
-trimpath \
-o $@ \
$(dir $@)main.go
Expand Down
14 changes: 13 additions & 1 deletion Makefile.d/dependencies.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ update/libs: \
update/telepresence \
update/vald \
update/valdcli \
update/yq
update/yq \
update/zlib \
update/hdf5

.PHONY: go/download
## download Go package dependencies
Expand Down Expand Up @@ -163,6 +165,16 @@ update/telepresence:
update/yq:
curl --silent https://api.github.com/repos/mikefarah/yq/releases/latest | grep -Po '"tag_name": "\K.*?(?=")' > $(ROOTDIR)/versions/YQ_VERSION

.PHONY: update/zlib
## update zlib version
update/zlib:
curl --silent https://api.github.com/repos/madler/zlib/releases/latest | grep -Po '"tag_name": "\K.*?(?=")' | sed 's/v//g' > $(ROOTDIR)/versions/ZLIB_VERSION

.PHONY: update/hdf5
## update hdf5 version
update/hdf5:
curl --silent https://api.github.com/repos/HDFGroup/hdf5/releases/latest | grep -Po '"tag_name": "\K.*?(?=")' | sed 's/v//g' > $(ROOTDIR)/versions/HDF5_VERSION

.PHONY: update/vald
## update vald it's self version
update/vald:
Expand Down
21 changes: 7 additions & 14 deletions Makefile.d/docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,10 @@ docker/name/benchmark-job:
.PHONY: docker/build/benchmark-job
## build benchmark job
docker/build/benchmark-job:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/tools/benchmark/job/Dockerfile \
-t $(ORG)/$(BENCHMARK_JOB_IMAGE):$(TAG) . \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg DISTROLESS_IMAGE=$(DISTROLESS_IMAGE) \
--build-arg DISTROLESS_IMAGE_TAG=$(DISTROLESS_IMAGE_TAG)
@make DOCKERFILE="$(ROOTDIR)/dockers/tools/benchmark/job/Dockerfile" \
IMAGE=$(BENCHMARK_JOB_IMAGE) \
DOCKER_OPTS="--build-arg ZLIB_VERSION=$(ZLIB_VERSION) --build-arg HDF5_VERSION=$(HDF5_VERSION)" \
docker/build/image

.PHONY: docker/name/benchmark-operator
docker/name/benchmark-operator:
Expand All @@ -250,10 +247,6 @@ docker/name/benchmark-operator:
.PHONY: docker/build/benchmark-operator
## build benchmark operator
docker/build/benchmark-operator:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/tools/benchmark/operator/Dockerfile \
-t $(ORG)/$(BENCHMARK_OPERATOR_IMAGE):$(TAG) . \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg DISTROLESS_IMAGE=$(DISTROLESS_IMAGE) \
--build-arg DISTROLESS_IMAGE_TAG=$(DISTROLESS_IMAGE_TAG)
@make DOCKERFILE="$(ROOTDIR)/dockers/tools/benchmark/operator/Dockerfile" \
IMAGE=$(BENCHMARK_OPERATOR_IMAGE) \
docker/build/image
52 changes: 18 additions & 34 deletions dockers/tools/benchmark/job/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
#

ARG GO_VERSION=latest
ARG ZLIB_VERSION
ARG HDF5_VERSION
ARG DISTROLESS_IMAGE=gcr.io/distroless/static
ARG DISTROLESS_IMAGE_TAG=nonroot
ARG UPX_OPTIONS=-9
ARG MAINTAINER="vdaas.org vald team <[email protected]>"
ARG TARGETARCH

FROM golang:${GO_VERSION} AS golang

FROM ubuntu:devel AS builder

ARG UPX_OPTIONS
ARG TARGETARCH
ARG ZLIB_VERSION
ARG HDF5_VERSION

ENV GO111MODULE on
ENV DEBIAN_FRONTEND noninteractive
Expand All @@ -39,11 +41,9 @@ ENV ORG vdaas
ENV REPO vald
ENV APP_NAME job
ENV PKG tools/benchmark/${APP_NAME}
ENV BUILD_DIR=/usr/local
ENV LIB_DIR=/usr/local/lib
ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:${LIB_DIR}
ENV ARCH=${TARGETARCH}
ENV XARCH x86_64
ENV AARCH aarch64
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${LIB_DIR}:/lib

# skipcq: DOK-DL3008
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand All @@ -57,31 +57,23 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p ${LIB_DIR} \
&& curl -sOL https://github.com/madler/zlib/releases/download/v1.3/zlib-1.3.tar.gz \
&& tar -xzvf zlib-1.3.tar.gz \
&& cd zlib-1.3 \
&& ./configure --prefix="${LIB_DIR}" --static --shared \
&& curl -sOL https://github.com/madler/zlib/releases/download/v${ZLIB_VERSION}/zlib-${ZLIB_VERSION}.tar.gz \
&& mkdir -p zlib \
&& tar -xzvf zlib-${ZLIB_VERSION}.tar.gz -C zlib --strip-components 1 \
&& cd zlib \
&& ./configure --prefix=${LIB_DIR} --static \
&& make \
&& make test \
&& make install \
&& cd / \
&& curl -sOL https://github.com/HDFGroup/hdf5/releases/download/hdf5-1_14_3/hdf5-1_14_3.tar.gz \
&& tar -xzvf hdf5-1_14_3.tar.gz \
&& cd hdfsrc \
&& ./configure --enable-build-mode=production --enable-static-exec --disable-shared --prefix="/usr/local" --with-zlib=/usr/local/include,/usr/local/lib LDFLAGS="-Wl,-rpath,${LIB_DIR}" \
&& mkdir -p hdf5 \
&& curl -sOL https://github.com/HDFGroup/hdf5/releases/download/${HDF5_VERSION}/${HDF5_VERSION}.tar.gz \
&& tar -xzvf ${HDF5_VERSION}.tar.gz -C hdf5 --strip-components 2 \
&& cd hdf5 \
&& ./configure --enable-build-mode=production --enable-static-exec --disable-shared --prefix=${BUILD_DIR} --with-zlib=${BUILD_DIR}/include,${LIB_DIR} LDFLAGS="-Wl,-rpath,${LIB_DIR}" \
&& make check \
&& make install \
&& ldconfig
# && mkdir -p /usr/local/lib/linux-gnu \
# && if [ "${ARCH}" = "amd64" ]; then \
# ARCH=${XARCH} ; \
# # mv /lib64/ld-linux-x86-64.so.2 /usr/local/lib/linux-gnu ; \
# else \
# ARCH=${AARCH}; \
# fi \
# && mv /usr/lib/${ARCH}-linux-gnu/libc.so.6 /usr/local/lib/linux-gnu/ \
# && /usr/sbin/ldconfig


COPY --from=golang /usr/local/go $GOROOT
RUN mkdir -p "$GOPATH/src"
Expand Down Expand Up @@ -119,22 +111,14 @@ RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \
WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG}
RUN cp sample.yaml /tmp/config.yaml

# CMD ["/usr/bin/bash"]

FROM ${DISTROLESS_IMAGE}:${DISTROLESS_IMAGE_TAG}
LABEL maintainer="${MAINTAINER}"

ENV APP_NAME job

ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/lib

COPY --from=builder /usr/local/lib/* /usr/lib/
COPY --from=builder /usr/local/include/* /usr/include
COPY --from=builder /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/
# COPY --from=builder /lib64/* /lib64/
COPY --from=builder /usr/bin/${APP_NAME} /usr/bin/${APP_NAME}
COPY --from=builder /usr/bin/${APP_NAME} /go/bin/${APP_NAME}
COPY --from=builder /tmp/config.yaml /etc/server/config.yaml

USER nonroot:nonroot

ENTRYPOINT ["/usr/bin/job"]
ENTRYPOINT ["/go/bin/job"]
1 change: 1 addition & 0 deletions internal/k8s/vald/benchmark/job/job_template_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type BenchmarkJobOption func(b *jobs.Job) error
var defaultBenchmarkJobOpts = []BenchmarkJobOption{
WithSvcAccountName(svcAccount),
WithRestartPolicy(RestartPolicyNever),
WithTTLSecondsAfterFinished(int32(600)),
}

// WithSvcAccountName sets the service account name for benchmark job.
Expand Down
1 change: 1 addition & 0 deletions versions/HDF5_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hdf5-1_14_3
1 change: 1 addition & 0 deletions versions/ZLIB_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.3

0 comments on commit ce7414d

Please sign in to comment.