Skip to content

Commit

Permalink
Added support for multi-arch builds (#1203)
Browse files Browse the repository at this point in the history
Signed-off-by: Morlay <[email protected]>
  • Loading branch information
morlay authored Oct 12, 2020
1 parent c69e666 commit 9cedde6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 22 deletions.
22 changes: 7 additions & 15 deletions .ci/publish-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 .
5 changes: 2 additions & 3 deletions .github/workflows/publish-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
34 changes: 34 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -63,14 +63,18 @@ 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
@${GO_FLAGS} go test -c ./test/e2e/...

.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:
Expand Down
13 changes: 11 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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"]

Expand Down

0 comments on commit 9cedde6

Please sign in to comment.