diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 391526e..2bc4a56 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -8,11 +8,21 @@ on: branches: [ master ] jobs: - build: + deploy: if: github.repository == 'OneCricketeer/apache-kafka-connect-docker' runs-on: ubuntu-latest steps: + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + platforms: linux/amd64,linux/arm64 + - uses: actions/checkout@v3 + - name: Set up JDK uses: actions/setup-java@v3 with: @@ -20,26 +30,10 @@ jobs: distribution: 'temurin' - name: Log in to Docker Hub - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v2 with: username: cricketeerone password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build & Push (linux/amd64) - run: make push - - # Support ARM - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - with: - platforms: linux/arm64 - - - name: Build & Push (linux/arm64) - run: make jib-build - - - name: Build & Push [confluent-hub] (linux/arm64) - run: make buildx-confluent-hub-arm64 \ No newline at end of file + - name: Build & Push + run: BUILDX_PLATFORMS=linux/arm64,linux/amd64 make \ No newline at end of file diff --git a/Makefile b/Makefile index 5ac5664..7de8a4c 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,44 @@ DOCKER_REGISTRY ?= '' DOCKER_USER ?= cricketeerone DOCKER_IMAGE ?= apache-kafka-connect +DOCKER_FQN = $(DOCKER_REGISTRY)$(DOCKER_USER)/$(DOCKER_IMAGE) VERSION = 3.2.3 DOCKER_TAG_CONFLUENT_HUB = confluent-hub DOCKERFILE_CONFLUENT_HUB = Dockerfile.$(DOCKER_TAG_CONFLUENT_HUB) -BUILDX_PLATFORMS ?= linux/arm64 +# Override with 'linux/amd64,linux/arm64' to do multi-platform builds +# Requires running 'docker buildx create --use' to do multi-platform +# ref. https://www.docker.com/blog/how-to-rapidly-build-multi-architecture-images-with-buildx/ +BUILDX_PLATFORMS ?= linux/amd64 +# TODO: fix 'package' phase +# Defaults to build and push. Requires 'docker login'. +# Other supported option: 'compile jib:dockerBuild' MVN_BUILD_CMD ?= compile jib:build -DOCKER_FQN = $(DOCKER_REGISTRY)$(DOCKER_USER)/$(DOCKER_IMAGE) - +# Supports arm64; builds and pushes. Refer blog above for setup +# Requires 'docker login' +ifneq (,$(findstring arm64,$(BUILDX_PLATFORMS))) +buildx-confluent-hub: build-multi-arch + @docker buildx build -f $(DOCKERFILE_CONFLUENT_HUB) -t $(DOCKER_FQN):$(VERSION)-$(DOCKER_TAG_CONFLUENT_HUB) --push --platform=$(BUILDX_PLATFORMS) . + @docker buildx build -f $(DOCKERFILE_CONFLUENT_HUB) -t $(DOCKER_FQN):latest-$(DOCKER_TAG_CONFLUENT_HUB) --push --platform=$(BUILDX_PLATFORMS) . +else build-confluent-hub: build @docker build -f $(DOCKERFILE_CONFLUENT_HUB) -t $(DOCKER_FQN):$(VERSION)-$(DOCKER_TAG_CONFLUENT_HUB) . @docker tag $(DOCKER_FQN):$(VERSION)-$(DOCKER_TAG_CONFLUENT_HUB) $(DOCKER_FQN):latest-$(DOCKER_TAG_CONFLUENT_HUB) -build: - @./mvnw -B --errors clean $(MVN_BUILD_CMD) --file pom.xml +endif -# Targets to support arm64 -jib-build: # requires docker login - @./mvnw -B --errors clean compile jib:build --file pom.xml -buildx-confluent-hub-arm64: - @docker buildx build -f $(DOCKERFILE_CONFLUENT_HUB) -t $(DOCKER_FQN):$(VERSION)-$(DOCKER_TAG_CONFLUENT_HUB) --push --platform=$(BUILDX_PLATFORMS) . - @docker buildx build -f $(DOCKERFILE_CONFLUENT_HUB) -t $(DOCKER_FQN):latest-$(DOCKER_TAG_CONFLUENT_HUB) --push --platform=$(BUILDX_PLATFORMS) . +build: # default machine architecture build + @./mvnw -B --errors clean $(MVN_BUILD_CMD) --file pom.xml +build-multi-arch: # refer pom.xml for built platforms + @./mvnw -B --errors -Pmulti-arch clean $(MVN_BUILD_CMD) --file pom.xml +# required target if using `mvn jib:dockerBuild` push: build-confluent-hub @docker push $(DOCKER_FQN):latest - @docker push $(DOCKER_FQN):latest-$(DOCKER_TAG_CONFLUENT_HUB) @docker push $(DOCKER_FQN):$(VERSION) + @docker push $(DOCKER_FQN):latest-$(DOCKER_TAG_CONFLUENT_HUB) @docker push $(DOCKER_FQN):$(VERSION)-$(DOCKER_TAG_CONFLUENT_HUB) clean: diff --git a/README.md b/README.md index 5fe05b6..1ae0bcb 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,27 @@ See [`docker-compose.yml`](docker-compose.yml) for a full example of these varia ## Build it locally -Looking to build your own image? **tl;dr** - Clone repo, and use `./mvnw clean package` or `make` and you're done! +Looking to build your own image? **tl;dr** - Clone repo, and use `./mvnw clean compile jib:dockerBuild` or `MVN_BUILD_CMD='compile jib:dockerBuild' make` and you're done! + +**Multi-platform builds (buildx)** + +By default, with the above commands, an image should build for your local OS architecture (although, this has not been tested on `arm64` devices). +The following builds and pushes multi-platform images to Docker Hub via Docker Buildx. + +```sh +BUILDX_PLATFORMS=linux/arm64,linux/amd64 make +``` + +## Push to a private registry + +To push to a private Docker Registry, you'll need to `docker login` to that address. The following commands will push the `apache-kafka-docker` image to a Docker Registry under your local username. Feel free to change `DOCKER_USER` to a custom repo name in the Registry. + +```sh +$ docker login --username=$(whoami) + +$ DOCKER_REGISTRY= DOCKER_USER=$(whoami) \ + make +``` ## Tutorial diff --git a/pom.xml b/pom.xml index 91ecc36..9c31f43 100644 --- a/pom.xml +++ b/pom.xml @@ -265,16 +265,6 @@ ${jib.from.image} - - - linux - amd64 - - - linux - arm64 - - ${jib.to.image} @@ -342,4 +332,32 @@ + + + + multi-arch + + + + com.google.cloud.tools + jib-maven-plugin + + + + + linux + amd64 + + + linux + arm64 + + + + + + + + +