diff --git a/.ci/publish-images.sh b/.ci/publish-images.sh index b1f40536e..59f344597 100755 --- a/.ci/publish-images.sh +++ b/.ci/publish-images.sh @@ -18,17 +18,11 @@ if [ "${DOCKER_PASSWORD}x" != "x" -a "${DOCKER_USERNAME}x" != "x" ]; then echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin fi -echo "Building image ${BUILD_IMAGE}" -make install-tools build docker BUILD_IMAGE="${BUILD_IMAGE}" - -# see https://github.com/jaegertracing/jaeger-operator/issues/555 -echo "Pushing image ${BUILD_IMAGE}" -docker push "${BUILD_IMAGE}" +IMAGE_TAGS="--tag ${BUILD_IMAGE}" if [ "${MAJOR_MINOR}x" != "x" ]; then MAJOR_MINOR_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR_MINOR}" - docker tag "${BUILD_IMAGE}" "${MAJOR_MINOR_IMAGE}" - docker push "${MAJOR_MINOR_IMAGE}" + IMAGE_TAGS="${IMAGE_TAGS} --tag ${MAJOR_MINOR_IMAGE}" fi ## now, push to quay.io @@ -37,14 +31,12 @@ if [ "${QUAY_PASSWORD}x" != "x" -a "${QUAY_USERNAME}x" != "x" ]; then echo "${QUAY_PASSWORD}" | docker login -u "${QUAY_USERNAME}" quay.io --password-stdin echo "Tagging ${BUILD_IMAGE} as quay.io/${BUILD_IMAGE}" - docker tag "${BUILD_IMAGE}" "quay.io/${BUILD_IMAGE}" - - echo "Pushing 'quay.io/${BUILD_IMAGE}'" - docker push "quay.io/${BUILD_IMAGE}" + IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${BUILD_IMAGE}" if [ "${MAJOR_MINOR_IMAGE}x" != "x" ]; then - echo "Pushing 'quay.io/${MAJOR_MINOR_IMAGE}' to quay.io" - docker tag "${MAJOR_MINOR_IMAGE}" "quay.io/${MAJOR_MINOR_IMAGE}" - docker push "quay.io/${MAJOR_MINOR_IMAGE}" + IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${MAJOR_MINOR_IMAGE}" fi fi + +echo "Building with tags ${IMAGE_TAGS}" +docker buildx build --push --build-arg=GOPROXY=${GOPROXY} --platform=linux/amd64,linux/arm64 ${IMAGE_TAGS} --file build/Dockerfile . diff --git a/.github/workflows/publish-images.yaml b/.github/workflows/publish-images.yaml index 2a2f68339..e73cf864d 100644 --- a/.github/workflows/publish-images.yaml +++ b/.github/workflows/publish-images.yaml @@ -8,10 +8,9 @@ jobs: publish: runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v1 - with: - go-version: '1.14.4' - uses: actions/checkout@v1 + - uses: docker/setup-qemu-action@v1 + - uses: docker/setup-buildx-action@v1 - name: "publishes the images" env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6d8fe3b2e..75122c7cb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -175,3 +175,37 @@ If you face issues like the one below, make sure you don't have any Jaeger insta ... ``` +#### Building [OCI Images](https://github.com/opencontainers/image-spec/blob/master/spec.md) for multiple arch (linux/arm64, linux/amd64) + +OCI images could be built and published by [buildx](https://github.com/docker/buildx), it could be executed for local test via: + +``` +$ OPERATOR_VERSION=devel ./.ci/publish-images.sh +``` + +more arch support only need to change `--platform=linux/amd64,linux/arm64` + +if we want to execute this in local env, need to setup buildx: + +1. install docker cli plugin + +``` +$ export DOCKER_BUILDKIT=1 +$ docker build --platform=local -o . git://github.com/docker/buildx +$ mkdir -p ~/.docker/cli-plugins +$ mv buildx ~/.docker/cli-plugins/docker-buildx +``` +(via https://github.com/docker/buildx#with-buildx-or-docker-1903) + +2. install qemu for multi arch + +``` +$ docker run --privileged --rm tonistiigi/binfmt --install all +``` +(via https://github.com/docker/buildx#building-multi-platform-images) + +3. create a builder + +``` +$ docker buildx create --use --name builder +``` \ No newline at end of file diff --git a/Makefile b/Makefile index 8600ce0b5..a1606d6a2 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ VERSION_DATE ?= $(shell date -u +'%Y-%m-%dT%H:%M:%SZ') -GO_FLAGS ?= GOOS=linux GOARCH=amd64 CGO_ENABLED=0 GO111MODULE=on +GO_FLAGS ?= GOOS=$(go env GOOS) GOARCH=$(go env GOARCH) CGO_ENABLED=0 GO111MODULE=on KUBERNETES_CONFIG ?= "$(HOME)/.kube/config" WATCH_NAMESPACE ?= "" BIN_DIR ?= "build/_output/bin" @@ -63,6 +63,10 @@ security: .PHONY: build build: format + $(MAKE) gobuild + +.PHONY: gobuild +gobuild: @echo Building... @${GO_FLAGS} go build -o $(OUTPUT_BINARY) -ldflags $(LD_FLAGS) # compile the tests without running them @@ -70,7 +74,7 @@ build: format .PHONY: docker docker: - @[ ! -z "$(PIPELINE)" ] || docker build --file build/Dockerfile -t "$(BUILD_IMAGE)" . + @[ ! -z "$(PIPELINE)" ] || docker build --build-arg=GOPROXY=${GOPROXY} --file build/Dockerfile -t "$(BUILD_IMAGE)" . .PHONY: push push: diff --git a/build/Dockerfile b/build/Dockerfile index 3577626a0..bd0a50616 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,3 +1,12 @@ +FROM golang:1.14 as builder + +ARG GOPROXY +ENV GOPROXY=${GOPROXY} + +COPY . /go/src/github.com/jaegertracing/jaeger-operator/ +WORKDIR /go/src/github.com/jaegertracing/jaeger-operator +RUN make gobuild + FROM registry.access.redhat.com/ubi8/ubi ENV OPERATOR=/usr/local/bin/jaeger-operator \ @@ -13,10 +22,10 @@ RUN INSTALL_PKGS=" \ mkdir /tmp/_working_dir && \ chmod og+w /tmp/_working_dir -COPY scripts/* /scripts/ +COPY --from=builder /go/src/github.com/jaegertracing/jaeger-operator/scripts/* /scripts/ # install operator binary -COPY build/_output/bin/jaeger-operator ${OPERATOR} +COPY --from=builder /go/src/github.com/jaegertracing/jaeger-operator/build/_output/bin/jaeger-operator ${OPERATOR} ENTRYPOINT ["/usr/local/bin/jaeger-operator"]