ARG BUILDER=golang
ARG BUILDER_VERSION=1.24.5-oe-24.03-lts-sp3
ARG BUILDER_IMAGE=cr.openfuyao.cn/openfuyao/$BUILDER:$BUILDER_VERSION
ARG K8S_VER=1.0
FROM ${BUILDER_IMAGE} AS build
USER 0
WORKDIR /go/src/app
COPY . .
RUN --mount=type=cache,target=/go/pkg/mod,sharing=locked \
<<'EOF'
mkdir -p /usr/include/ubse/
export KUBE_TAG="1.34.3-of.1"
export CLIENT_GO_VERSION="-X 'k8s.io/client-go/pkg/version.getVersion=${KUBE_TAG}'"
export COMPONENT_BASE_VERSION="-X 'k8s.io/component-base/version.getVersion=${KUBE_TAG}'"
export GO_BUILD_FLAGS='-v -tags=container -buildmode=pie -a -trimpath'
export LDFLAGS='-w -s -buildid none -linkmode=external -extldflags "-Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack"'
export GOPROXY="https://goproxy.cn,https://goproxy.io,direct"
export GOPRIVATE="atomgit.com"
export GONOPROXY="atomgit.com"
export GONOSUMDB="atomgit.com"
git config --global url."https://atomgit.com/".insteadOf "atomgit.com/"
go mod tidy
cd cmd/matrixcontroller
CGO_ENABLED=1 CC=gcc go build ${GO_BUILD_FLAGS} -o /home/nonroot/matrixcontroller -ldflags "${CLIENT_GO_VERSION} ${COMPONENT_BASE_VERSION} ${LDFLAGS}"
EOF
FROM hub.oepkgs.net/openeuler/openeuler:24.03-lts-sp1 AS release
WORKDIR /
ENV PATH="/:${PATH}"
RUN dnf install -y shadow-utils && dnf clean all
COPY --link --from=build --chmod=500 /home/nonroot/matrixcontroller /usr/local/bin/matrixcontroller
RUN /usr/sbin/useradd -u 4177 matrixplugin -m -s /sbin/nologin \
&& chown matrixplugin:matrixplugin /usr/local/bin/matrixcontroller \
&& dnf remove -y shadow-utils && dnf clean all
USER matrixplugin
ENTRYPOINT ["/usr/local/bin/matrixcontroller"]