Skip to content

Commit

Permalink
[bugfix] gcc environment for ARM
Browse files Browse the repository at this point in the history
Signed-off-by: kpango <[email protected]>
  • Loading branch information
kpango committed Feb 8, 2024
1 parent 4c93f1b commit 49d31e6
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 27 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/dockers-agent-faiss-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#
# Copyright (C) 2019-2024 vdaas.org vald team <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#
name: "Build docker image: agent-faiss"
on:
push:
branches:
- "main"
- "release/v*.*"
- "!release/v*.*.*"
tags:
- "*.*.*"
- "v*.*.*"
- "*.*.*-*"
- "v*.*.*-*"
paths:
- ".github/actions/docker-build/actions.yaml"
- ".github/workflows/_docker-image.yaml"
- ".github/workflows/dockers-agent-faiss-image.yml"
- "go.mod"
- "go.sum"
- "internal/**"
- "!internal/**/*_test.go"
- "!internal/db/**"
- "!internal/k8s/**"
- "apis/grpc/**"
- "pkg/agent/core/faiss/**"
- "cmd/agent/core/faiss/**"
- "dockers/agent/core/faiss/Dockerfile"
- "versions/GO_VERSION"
- "versions/FAISS_VERSION"
pull_request:
paths:
- ".github/actions/docker-build/actions.yaml"
- ".github/workflows/_docker-image.yaml"
- ".github/workflows/dockers-agent-faiss-image.yml"
- "go.mod"
- "go.sum"
- "internal/**"
- "!internal/**/*_test.go"
- "!internal/db/**"
- "!internal/k8s/**"
- "apis/grpc/**"
- "pkg/agent/core/faiss/**"
- "cmd/agent/core/faiss/**"
- "dockers/agent/core/faiss/Dockerfile"
- "versions/GO_VERSION"
- "versions/FAISS_VERSION"
pull_request_target:
paths:
- ".github/actions/docker-build/actions.yaml"
- ".github/workflows/_docker-image.yaml"
- ".github/workflows/dockers-agent-faiss-image.yml"
- "go.mod"
- "go.sum"
- "internal/**"
- "!internal/**/*_test.go"
- "!internal/db/**"
- "!internal/k8s/**"
- "apis/grpc/**"
- "pkg/agent/core/faiss/**"
- "cmd/agent/core/faiss/**"
- "dockers/agent/core/faiss/Dockerfile"
- "versions/GO_VERSION"
- "versions/FAISS_VERSION"
jobs:
build:
uses: ./.github/workflows/_docker-image.yaml
with:
target: agent-faiss
platforms: linux/amd64
secrets: inherit
1 change: 1 addition & 0 deletions .github/workflows/dockers-agent-ngt-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ jobs:
uses: ./.github/workflows/_docker-image.yaml
with:
target: agent-ngt
platforms: linux/amd64,linux/arm64
secrets: inherit
1 change: 1 addition & 0 deletions .github/workflows/dockers-benchmark-job-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ jobs:
uses: ./.github/workflows/_docker-image.yaml
with:
target: benchmark-job
platforms: linux/amd64,linux/arm64
secrets: inherit
1 change: 1 addition & 0 deletions .github/workflows/dockers-helm-operator-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ jobs:
uses: ./.github/workflows/_docker-image.yaml
with:
target: operator/helm
platforms: linux/amd64,linux/arm64
secrets: inherit
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ DATETIME = $(eval DATETIME := $(shell date -u +%Y/%m/%d_%
TAG ?= latest
CRORG ?= $(ORG)
GHCRORG = ghcr.io/$(ORG)/$(NAME)
AGENT_IMAGE = $(NAME)-agent-ngt
AGENT_NGT_IMAGE = $(NAME)-agent-ngt
AGENT_FAISS_IMAGE = $(NAME)-agent-faiss
AGENT_SIDECAR_IMAGE = $(NAME)-agent-sidecar
CI_CONTAINER_IMAGE = $(NAME)-ci-container
DEV_CONTAINER_IMAGE = $(NAME)-dev-container
Expand Down Expand Up @@ -571,7 +572,7 @@ faiss/install: /usr/local/lib/libfaiss.so
curl -LO https://github.com/facebookresearch/faiss/archive/v$(FAISS_VERSION).tar.gz
tar zxf v$(FAISS_VERSION).tar.gz -C $(TEMP_DIR)/
cd $(TEMP_DIR)/faiss-$(FAISS_VERSION) && \
cmake -DFAISS_ENABLE_GPU=OFF -DFAISS_ENABLE_PYTHON=OFF -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=ON -B build . && \
cmake -DFAISS_ENABLE_GPU=OFF -DFAISS_ENABLE_PYTHON=OFF -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -B build . && \
make -C build -j faiss && \
make -C build install
rm -rf v$(FAISS_VERSION).tar.gz
Expand Down
26 changes: 13 additions & 13 deletions Makefile.d/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ binary/build: \
cmd/agent/core/ngt/ngt: \
ngt/install
$(eval CGO_ENABLED = 1)
$(call go-build,agent/core/ngt,-linkmode 'external',-fPIC -pthread -fopenmp -std=gnu++20 -lstdc++ -lm -z relro -z now $(EXTLDFLAGS), cgo,NGT-$(NGT_VERSION),$@)
$(call go-build,agent/core/ngt,-linkmode 'external',-static -fPIC -pthread -fopenmp -std=gnu++20 -lstdc++ -lm -z relro -z now $(EXTLDFLAGS), cgo,NGT-$(NGT_VERSION),$@)

cmd/agent/core/faiss/faiss: \
faiss/install
Expand All @@ -45,50 +45,50 @@ cmd/agent/core/faiss/faiss: \

cmd/agent/sidecar/sidecar:
$(eval CGO_ENABLED = 0)
$(call go-build,agent/sidecar,,,,,$@)
$(call go-build,agent/sidecar,,-static,,,$@)

cmd/discoverer/k8s/discoverer:
$(eval CGO_ENABLED = 0)
$(call go-build,discoverer/k8s,,,,,$@)
$(call go-build,discoverer/k8s,,-static,,,$@)

cmd/gateway/lb/lb:
$(eval CGO_ENABLED = 0)
$(call go-build,gateway/lb,,,,,$@)
$(call go-build,gateway/lb,,-static,,,$@)

cmd/gateway/filter/filter:
$(eval CGO_ENABLED = 0)
$(call go-build,gateway/filter,,,,,$@)
$(call go-build,gateway/filter,,-static,,,$@)

cmd/gateway/mirror/mirror:
$(eval CGO_ENABLED = 0)
$(call go-build,gateway/mirror,,,,,$@)
$(call go-build,gateway/mirror,,-static,,,$@)

cmd/manager/index/index:
$(eval CGO_ENABLED = 0)
$(call go-build,manager/index,,,,,$@)
$(call go-build,manager/index,,-static,,,$@)

cmd/index/job/correction/index-correction:
$(eval CGO_ENABLED = 0)
$(call go-build,index/job/correction,,,,,$@)
$(call go-build,index/job/correction,,-static,,,$@)

cmd/index/job/creation/index-creation:
$(eval CGO_ENABLED = 0)
$(call go-build,index/job/creation,,,,,$@)
$(call go-build,index/job/creation,,-static,,,$@)

cmd/index/job/save/index-save:
$(eval CGO_ENABLED = 0)
$(call go-build,index/job/save,,,,,$@)
$(call go-build,index/job/save,,-static,,,$@)

cmd/index/job/readreplica/rotate/readreplica-rotate:
$(eval CGO_ENABLED = 0)
$(call go-build,index/job/readreplica/rotate,,,,,$@)
$(call go-build,index/job/readreplica/rotate,,-static,,,$@)

cmd/tools/benchmark/job/job:
$(call go-build,tools/benchmark/job,-linkmode 'external',-fPIC -pthread -fopenmp -std=gnu++20 -lhdf5 -lhdf5_hl -lm -ldl, cgo,$(HDF5_VERSION),$@)
$(call go-build,tools/benchmark/job,-linkmode 'external',-static -fPIC -pthread -fopenmp -std=gnu++20 -lhdf5 -lhdf5_hl -lm -ldl, cgo,$(HDF5_VERSION),$@)

cmd/tools/benchmark/operator/operator:
$(eval CGO_ENABLED = 0)
$(call go-build,tools/benchmark/operator,,,,,$@)
$(call go-build,tools/benchmark/operator,,-static,,,$@)

.PHONY: binary/build/zip
## build all binaries and zip them
Expand Down
8 changes: 4 additions & 4 deletions Makefile.d/docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ endif

.PHONY: docker/name/agent-ngt
docker/name/agent-ngt:
@echo "$(ORG)/$(AGENT_IMAGE)"
@echo "$(ORG)/$(AGENT_NGT_IMAGE)"

.PHONY: docker/build/agent-ngt
## build agent-ngt image
docker/build/agent-ngt:
@make DOCKERFILE="$(ROOTDIR)/dockers/agent/core/ngt/Dockerfile" \
IMAGE=$(AGENT_IMAGE) \
IMAGE=$(AGENT_NGT_IMAGE) \
docker/build/image

.PHONY: docker/name/agent-faiss
docker/name/agent-faiss:
@echo "$(ORG)/$(AGENT_IMAGE)"
@echo "$(ORG)/$(AGENT_FAISS_IMAGE)"

.PHONY: docker/build/agent-faiss
## build agent-faiss image
docker/build/agent-faiss:
@make DOCKERFILE="$(ROOTDIR)/dockers/agent/core/faiss/Dockerfile" \
IMAGE=$(AGENT_IMAGE) \
IMAGE=$(AGENT_FAISS_IMAGE) \
docker/build/image

.PHONY: docker/name/agent-sidecar
Expand Down
2 changes: 1 addition & 1 deletion Makefile.d/functions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ define go-build
GO_VERSION=$(GO_VERSION) \
go build \
--ldflags "-w $2 \
-extldflags '-static $3' \
-extldflags '$3' \
-X '$(GOPKG)/internal/info.AlgorithmInfo=$5' \
-X '$(GOPKG)/internal/info.BuildCPUInfoFlags=$(CPU_INFO_FLAGS)' \
-X '$(GOPKG)/internal/info.BuildTime=$(DATETIME)' \
Expand Down
8 changes: 4 additions & 4 deletions Makefile.d/k8s.mk
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ k8s/vald/deploy:
helm template \
--values $(HELM_VALUES) \
--set defaults.image.tag=$(VERSION) \
--set agent.image.repository=$(CRORG)/$(AGENT_IMAGE) \
--set agent.image.repository=$(CRORG)/$(AGENT_NGT_IMAGE) \
--set agent.sidecar.image.repository=$(CRORG)/$(AGENT_SIDECAR_IMAGE) \
--set discoverer.image.repository=$(CRORG)/$(DISCOVERER_IMAGE) \
--set gateway.filter.image.repository=$(CRORG)/$(FILTER_GATEWAY_IMAGE) \
Expand Down Expand Up @@ -131,7 +131,7 @@ k8s/vald/delete:
helm template \
--values $(HELM_VALUES) \
--set defaults.image.tag=$(VERSION) \
--set agent.image.repository=$(CRORG)/$(AGENT_IMAGE) \
--set agent.image.repository=$(CRORG)/$(AGENT_NGT_IMAGE) \
--set agent.sidecar.image.repository=$(CRORG)/$(AGENT_SIDECAR_IMAGE) \
--set discoverer.image.repository=$(CRORG)/$(DISCOVERER_IMAGE) \
--set gateway.filter.image.repository=$(CRORG)/$(FILTER_GATEWAY_IMAGE) \
Expand Down Expand Up @@ -224,7 +224,7 @@ k8s/vald-readreplica/deploy:
helm template \
--values $(HELM_VALUES) \
--set defaults.image.tag=$(VERSION) \
--set agent.image.repository=$(CRORG)/$(AGENT_IMAGE) \
--set agent.image.repository=$(CRORG)/$(AGENT_NGT_IMAGE) \
--set agent.sidecar.image.repository=$(CRORG)/$(AGENT_SIDECAR_IMAGE) \
--set discoverer.image.repository=$(CRORG)/$(DISCOVERER_IMAGE) \
--set gateway.filter.image.repository=$(CRORG)/$(FILTER_GATEWAY_IMAGE) \
Expand All @@ -245,7 +245,7 @@ k8s/vald-readreplica/delete:
helm template \
--values $(HELM_VALUES) \
--set defaults.image.tag=$(VERSION) \
--set agent.image.repository=$(CRORG)/$(AGENT_IMAGE) \
--set agent.image.repository=$(CRORG)/$(AGENT_NGT_IMAGE) \
--set agent.sidecar.image.repository=$(CRORG)/$(AGENT_SIDECAR_IMAGE) \
--set discoverer.image.repository=$(CRORG)/$(DISCOVERER_IMAGE) \
--set gateway.filter.image.repository=$(CRORG)/$(FILTER_GATEWAY_IMAGE) \
Expand Down
12 changes: 12 additions & 0 deletions dockers/agent/core/faiss/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ ENV REPO vald
ENV PKG agent/core/faiss
ENV PKG_INTERNAL agent/internal
ENV APP_NAME faiss
ENV AARCH aarch_64
ENV XARCH x86_64

# skipcq: DOK-DL3008
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand All @@ -50,6 +52,16 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
intel-mkl \
unzip \
upx \
&& if [ "${TARGETARCH}" = "amd64" ] ; then \
apt install -y --no-install-recommends --fix-missing gcc-${XARCH}-${TARGETOS}-gnu; \
export CC=${XARCH}-${TARGETOS}-gnu-gcc; \
export CC_FOR_TARGET=${CC}; \
elif [ "${TARGETARCH}" = "arm64" ] ; then \
apt install -y --no-install-recommends --fix-missing gcc-${AARCH}-${TARGETOS}-gnu; \
export CC=${AARCH}-${TARGETOS}-gnu-gcc; \
export CC_FOR_TARGET=${CC}; \
fi \
&& ldconfig \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down
12 changes: 12 additions & 0 deletions dockers/agent/core/ngt/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ ENV REPO vald
ENV PKG agent/core/ngt
ENV PKG_INTERNAL agent/internal
ENV APP_NAME ngt
ENV AARCH aarch_64
ENV XARCH x86_64

# skipcq: DOK-DL3008
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand All @@ -52,6 +54,16 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libopenblas-dev \
unzip \
upx \
&& if [ "${TARGETARCH}" = "amd64" ] ; then \
apt install -y --no-install-recommends --fix-missing gcc-${XARCH}-${TARGETOS}-gnu; \
export CC=${XARCH}-${TARGETOS}-gnu-gcc; \
export CC_FOR_TARGET=${CC}; \
elif [ "${TARGETARCH}" = "arm64" ] ; then \
apt install -y --no-install-recommends --fix-missing gcc-${AARCH}-${TARGETOS}-gnu; \
export CC=${AARCH}-${TARGETOS}-gnu-gcc; \
export CC_FOR_TARGET=${CC}; \
fi \
&& ldconfig \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down
19 changes: 16 additions & 3 deletions dockers/operator/helm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ ENV PATH ${PATH}:${GOROOT}/bin:${GOPATH}/bin
ENV ORG vdaas
ENV REPO vald
ENV APP_NAME helm-operator
ENV AARCH aarch_64
ENV XARCH x86_64

# skipcq: DOK-DL3008
RUN apt-get clean \
Expand All @@ -62,6 +64,16 @@ RUN apt-get clean \
curl \
upx \
git \
&& if [ "${TARGETARCH}" = "amd64" ] ; then \
apt install -y --no-install-recommends --fix-missing gcc-${XARCH}-${TARGETOS}-gnu; \
export CC=${XARCH}-${TARGETOS}-gnu-gcc; \
export CC_FOR_TARGET=${CC}; \
elif [ "${TARGETARCH}" = "arm64" ] ; then \
apt install -y --no-install-recommends --fix-missing gcc-${AARCH}-${TARGETOS}-gnu; \
export CC=${AARCH}-${TARGETOS}-gnu-gcc; \
export CC_FOR_TARGET=${CC}; \
fi \
&& ldconfig \
&& apt-get clean \
&& rm -rf \
/var/lib/apt/lists/* \
Expand Down Expand Up @@ -121,11 +133,12 @@ COPY versions .
WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/charts
COPY charts .

WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/hack/helm/schema/gen
COPY hack/helm/schema/gen .
WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/hack
COPY hack .

WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}
RUN make GOARCH=${TARGETARCH} GOOS=${TARGETOS} helm/schema/vald helm/schema/vald-helm-operator \
RUN make GOARCH=${TARGETARCH} GOOS=${TARGETOS} helm/schema/vald \
&& make GOARCH=${TARGETARCH} GOOS=${TARGETOS} helm/schema/vald-helm-operator \
&& cp -r charts /charts

COPY --from=operator /usr/local/bin/${APP_NAME} /usr/bin/${APP_NAME}
Expand Down
11 changes: 11 additions & 0 deletions dockers/tools/benchmark/job/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ 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}:/lib
ENV AARCH aarch_64
ENV XARCH x86_64

# skipcq: DOK-DL3008, DOK-DL3003
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand All @@ -54,6 +56,15 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
upx \
g++ \
git \
&& if [ "${TARGETARCH}" = "amd64" ] ; then \
apt install -y --no-install-recommends --fix-missing gcc-${XARCH}-${TARGETOS}-gnu; \
export CC=${XARCH}-${TARGETOS}-gnu-gcc; \
export CC_FOR_TARGET=${CC}; \
elif [ "${TARGETARCH}" = "arm64" ] ; then \
apt install -y --no-install-recommends --fix-missing gcc-${AARCH}-${TARGETOS}-gnu; \
export CC=${AARCH}-${TARGETOS}-gnu-gcc; \
export CC_FOR_TARGET=${CC}; \
fi \
&& ldconfig \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
Expand Down

0 comments on commit 49d31e6

Please sign in to comment.