Skip to content

Commit

Permalink
refactor: arm64 builds; working locally (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
OneCricketeer authored Jan 8, 2023
1 parent d0e978a commit 36137a0
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 43 deletions.
34 changes: 14 additions & 20 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,32 @@ 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:
java-version: '11'
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
- name: Build & Push
run: BUILDX_PLATFORMS=linux/arm64,linux/amd64 make
34 changes: 22 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <registry-address> --username=$(whoami)

$ DOCKER_REGISTRY=<registry-address> DOCKER_USER=$(whoami) \
make
```

## Tutorial

Expand Down
38 changes: 28 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,6 @@
<configuration>
<from>
<image>${jib.from.image}</image>
<platforms>
<platform>
<os>linux</os>
<architecture>amd64</architecture>
</platform>
<platform>
<os>linux</os>
<architecture>arm64</architecture>
</platform>
</platforms>
</from>
<to>
<image>${jib.to.image}</image>
Expand Down Expand Up @@ -342,4 +332,32 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>multi-arch</id>
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<from>
<platforms>
<platform>
<os>linux</os>
<architecture>amd64</architecture>
</platform>
<platform>
<os>linux</os>
<architecture>arm64</architecture>
</platform>
</platforms>
</from>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

0 comments on commit 36137a0

Please sign in to comment.