Skip to content

Commit

Permalink
enable REGION and decouple build with local-up
Browse files Browse the repository at this point in the history
Signed-off-by: Congrool <[email protected]>
  • Loading branch information
Congrool committed May 20, 2022
1 parent 936a0bc commit e7bbb91
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ jobs:
run: |
go get sigs.k8s.io/[email protected]
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.20.7/bin/linux/amd64/kubectl && sudo install kubectl /usr/local/bin/kubectl
- name: Build Images
run: make docker-build
- name: Local Up Openyurt Cluster With Kind
run: make local-up-openyurt
- name: Run e2e Tests
Expand Down
42 changes: 28 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,22 @@
# limitations under the License.

TARGET_PLATFORMS ?= linux/amd64
IMAGE_REPO ?=openyurt
IMAGE_TAG ?= $(shell git describe --abbrev=0 --tags)
IMAGE_REPO ?= openyurt
GIT_COMMIT = $(shell git rev-parse HEAD)
VERSION = $(shell git describe --abbrev=0 --tags)

ifeq ($(shell git tag --points-at ${GIT_COMMIT}),)
GIT_VERSION=$(VERSION)-$(shell expr substr ${GIT_COMMIT} 1 7)
else
GIT_VERSION=$(VERSION)
endif

DOCKER_BUILD_ARGS = --build-arg GIT_VERSION=${GIT_VERSION}

ifeq (${REGION}, cn)
DOCKER_BUILD_ARGS += --build-arg GOPROXY=https://goproxy.cn --build-arg MIRROR_REPO=mirrors.aliyun.com
endif


.PHONY: clean all build

Expand Down Expand Up @@ -48,8 +62,8 @@ clean:
# And you can run the following command on different env by specify TARGET_PLATFORMS, default platform is linux/amd64
# - on centos env: make local-up-openyurt
# - on MACBook Pro M1: make local-up-openyurt TARGET_PLATFORMS=linux/arm64
local-up-openyurt: docker-build
bash hack/make-rules/local-up-openyurt.sh
local-up-openyurt:
YURT_VERSION=$(GIT_VERSION) bash hack/make-rules/local-up-openyurt.sh

e2e-tests:
bash hack/make-rules/run-e2e-tests.sh
Expand All @@ -76,34 +90,34 @@ lint: install-golint ## Run go lint against code.
docker-build: docker-build-yurthub docker-build-yurt-controller-manager docker-build-yurt-tunnel-server docker-build-yurt-tunnel-agent docker-build-node-servant

docker-build-yurthub:
docker buildx build --no-cache --load --build-arg GIT_VERSION=${IMAGE_TAG} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurthub . -t ${IMAGE_REPO}/yurthub:${IMAGE_TAG}
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurthub . -t ${IMAGE_REPO}/yurthub:${GIT_VERSION}

docker-build-yurt-controller-manager:
docker buildx build --no-cache --load --build-arg GIT_VERSION=${IMAGE_TAG} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-controller-manager . -t ${IMAGE_REPO}/yurt-controller-manager:${IMAGE_TAG}
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-controller-manager . -t ${IMAGE_REPO}/yurt-controller-manager:${GIT_VERSION}

docker-build-yurt-tunnel-server:
docker buildx build --no-cache --load --build-arg GIT_VERSION=${IMAGE_TAG} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-server . -t ${IMAGE_REPO}/yurt-tunnel-server:${IMAGE_TAG}
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-server . -t ${IMAGE_REPO}/yurt-tunnel-server:${GIT_VERSION}

docker-build-yurt-tunnel-agent:
docker buildx build --no-cache --load --build-arg GIT_VERSION=${IMAGE_TAG} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-agent . -t ${IMAGE_REPO}/yurt-tunnel-agent:${IMAGE_TAG}
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-agent . -t ${IMAGE_REPO}/yurt-tunnel-agent:${GIT_VERSION}

docker-build-node-servant:
docker buildx build --no-cache --load --build-arg GIT_VERSION=${IMAGE_TAG} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-node-servant . -t ${IMAGE_REPO}/node-servant:${IMAGE_TAG}
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-node-servant . -t ${IMAGE_REPO}/node-servant:${GIT_VERSION}

# Build and Push the docker images with multi-arch
docker-push: docker-push-yurthub docker-push-yurt-controller-manager docker-push-yurt-tunnel-server docker-push-yurt-tunnel-agent docker-push-node-servant

docker-push-yurthub:
docker buildx build --no-cache --push --build-arg GIT_VERSION=${IMAGE_TAG} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurthub . -t ${IMAGE_REPO}/yurthub:${IMAGE_TAG}
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurthub . -t ${IMAGE_REPO}/yurthub:${GIT_VERSION}

docker-push-yurt-controller-manager:
docker buildx build --no-cache --push --build-arg GIT_VERSION=${IMAGE_TAG} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-controller-manager . -t ${IMAGE_REPO}/yurt-controller-manager:${IMAGE_TAG}
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-controller-manager . -t ${IMAGE_REPO}/yurt-controller-manager:${GIT_VERSION}

docker-push-yurt-tunnel-server:
docker buildx build --no-cache --push --build-arg GIT_VERSION=${IMAGE_TAG} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-server . -t ${IMAGE_REPO}/yurt-tunnel-server:${IMAGE_TAG}
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-server . -t ${IMAGE_REPO}/yurt-tunnel-server:${GIT_VERSION}

docker-push-yurt-tunnel-agent:
docker buildx build --no-cache --push --build-arg GIT_VERSION=${IMAGE_TAG} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-agent . -t ${IMAGE_REPO}/yurt-tunnel-agent:${IMAGE_TAG}
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-agent . -t ${IMAGE_REPO}/yurt-tunnel-agent:${GIT_VERSION}

docker-push-node-servant:
docker buildx build --no-cache --push --build-arg GIT_VERSION=${IMAGE_TAG} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-node-servant . -t ${IMAGE_REPO}/node-servant:${IMAGE_TAG}
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-node-servant . -t ${IMAGE_REPO}/node-servant:${GIT_VERSION}
7 changes: 4 additions & 3 deletions hack/dockerfiles/Dockerfile.yurt-controller-manager
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder
ADD . /build
ARG TARGETOS TARGETARCH GIT_VERSION
ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO
WORKDIR /build/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/yurt-controller-manager

FROM --platform=${TARGETPLATFORM} alpine:3.14
ARG TARGETOS TARGETARCH
RUN apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/*
ARG TARGETOS TARGETARCH MIRROR_REPO
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \
apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/*
COPY --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-controller-manager /usr/local/bin/yurt-controller-manager
ENTRYPOINT ["/usr/local/bin/yurt-controller-manager"]
7 changes: 4 additions & 3 deletions hack/dockerfiles/Dockerfile.yurt-node-servant
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder
ADD . /build
ARG TARGETOS TARGETARCH GIT_VERSION
ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO
WORKDIR /build/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/yurt-node-servant

FROM --platform=${TARGETPLATFORM} alpine:3.14
ARG TARGETOS TARGETARCH
RUN apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/*
ARG TARGETOS TARGETARCH MIRROR_REPO
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \
apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/*
COPY --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-node-servant /usr/local/bin/node-servant
COPY hack/lib/node-servant-entry.sh /usr/local/bin/entry.sh
RUN chmod +x /usr/local/bin/entry.sh
7 changes: 4 additions & 3 deletions hack/dockerfiles/Dockerfile.yurt-tunnel-agent
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder
ADD . /build
ARG TARGETOS TARGETARCH GIT_VERSION
ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO
WORKDIR /build/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/yurt-tunnel-agent

FROM --platform=${TARGETPLATFORM} alpine:3.14
ARG TARGETOS TARGETARCH
RUN apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/*
ARG TARGETOS TARGETARCH MIRROR_REPO
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \
apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/*
COPY --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-tunnel-agent /usr/local/bin/yurt-tunnel-agent
ENTRYPOINT ["/usr/local/bin/yurt-tunnel-agent"]
7 changes: 4 additions & 3 deletions hack/dockerfiles/Dockerfile.yurt-tunnel-server
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder
ADD . /build
ARG TARGETOS TARGETARCH GIT_VERSION
ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO
WORKDIR /build/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/yurt-tunnel-server

FROM --platform=${TARGETPLATFORM} alpine:3.14
ARG TARGETOS TARGETARCH
RUN apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/*
ARG TARGETOS TARGETARCH MIRROR_REPO
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \
apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/*
COPY --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-tunnel-server /usr/local/bin/yurt-tunnel-server
ENTRYPOINT ["/usr/local/bin/yurt-tunnel-server"]
7 changes: 4 additions & 3 deletions hack/dockerfiles/Dockerfile.yurthub
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder
ADD . /build
ARG TARGETOS TARGETARCH GIT_VERSION
ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO
WORKDIR /build/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/yurthub

FROM --platform=${TARGETPLATFORM} alpine:3.14
ARG TARGETOS TARGETARCH
RUN apk add ca-certificates bash libc6-compat iptables ip6tables && update-ca-certificates && rm /var/cache/apk/*
ARG TARGETOS TARGETARCH MIRROR_REPO
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \
apk add ca-certificates bash libc6-compat iptables ip6tables && update-ca-certificates && rm /var/cache/apk/*
COPY --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurthub /usr/local/bin/yurthub
ENTRYPOINT ["/usr/local/bin/yurthub"]
14 changes: 6 additions & 8 deletions hack/make-rules/local-up-openyurt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
# automatically deployed, and the autonomous mode will be active.
#
# It uses the following env variables:
# REGION
# REGION affects the GOPROXY to use. You can set it to "cn" to use GOPROXY="https://goproxy.cn".
# Default value is "us", which means using GOPROXY="https://goproxy.io".
#
# KIND_KUBECONFIG
# KIND_KUBECONFIG represents the path to store the kubeconfig file of the cluster
# which is created by this shell. The default value is "$HOME/.kube/config".
Expand All @@ -42,8 +38,10 @@ set -e
set -u

YURT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"

source "${YURT_ROOT}/hack/lib/init.sh"
source "${YURT_ROOT}/hack/lib/build.sh"
YURT_VERSION=${YURT_VERSION:-${GIT_VERSION}}

readonly REQUIRED_CMD=(
go
Expand Down Expand Up @@ -106,8 +104,8 @@ function preflight {
done

for image in "${REQUIRED_IMAGES[@]}"; do
if [[ "$(docker image inspect --format='ignore me' ${image}:${GIT_VERSION})" != "ignore me" ]]; then
echo "image ${image}:${GIT_VERSION} is not exist locally"
if [[ "$(docker image inspect --format='ignore me' ${image}:${YURT_VERSION})" != "ignore me" ]]; then
echo "image ${image}:${YURT_VERSION} is not exist locally"
exit -1
fi
done
Expand All @@ -119,10 +117,10 @@ function build_yurtctl_binary {
}

function local_up_openyurt {
echo "Begin to setup OpenYurt cluster(version=${GIT_VERSION})"
echo "Begin to setup OpenYurt cluster(version=${YURT_VERSION})"
${YURT_LOCAL_BIN_DIR}/${LOCAL_OS}/${LOCAL_ARCH}/yurtctl test init \
--kubernetes-version=${KUBERNETESVERSION} --kube-config=${KIND_KUBECONFIG} \
--cluster-name=${CLUSTER_NAME} --openyurt-version=${GIT_VERSION} --use-local-images --ignore-error \
--cluster-name=${CLUSTER_NAME} --openyurt-version=${YURT_VERSION} --use-local-images --ignore-error \
--node-num=${NODES_NUM} --enable-dummy-if=${ENABLE_DUMMY_IF}
}

Expand Down

0 comments on commit e7bbb91

Please sign in to comment.