diff --git a/.dockerignore b/.dockerignore index 5a764d40a7..01a7cf4213 100644 --- a/.dockerignore +++ b/.dockerignore @@ -40,6 +40,7 @@ *.exe *.rlib -!target/image/quilkin +!target/image/linux/arm64/quilkin +!target/image/linux/amd64/quilkin !dependencies-src.zip !image/quilkin.yaml \ No newline at end of file diff --git a/build/Makefile b/build/Makefile index 7d7cbf7898..6ec7dcf843 100644 --- a/build/Makefile +++ b/build/Makefile @@ -29,15 +29,17 @@ rust_toolchain := $(shell grep channel $(project_path)/rust-toolchain.toml | awk # if this is a release, don't put the sha, otherwise, leave it off. ifdef QUILKIN_RELEASE - package_version := $(shell grep -A1 -w "name = \"quilkin\"" $(project_path)/Cargo.toml | grep version -m 1 | awk '{print $$3}') + package_version := $(shell grep -A1 -w "name = \"quilkin\"" $(project_path)/Cargo.toml | grep version -m 1 | awk -F'"' '{print $$2}') else git_sha := $(shell git rev-parse --short=7 HEAD) - package_version := $(shell grep -A1 -w "name = \"quilkin\"" $(project_path)/Cargo.toml | grep version -m 1 | awk '{print $$3}')-${git_sha} + package_version := $(shell grep -A1 -w "name = \"quilkin\"" $(project_path)/Cargo.toml | grep version -m 1 | awk -F'"' '{print $$2}')-${git_sha} endif # Set this value if you want to use an external registry REPOSITORY ?= "" IMAGE_TAG ?= ${REPOSITORY}quilkin:$(package_version) +IMAGE_TAG_ARM64 ?= ${REPOSITORY}quilkin-arm64:$(package_version) +IMAGE_TAG_AMD64 ?= ${REPOSITORY}quilkin-amd64:$(package_version) PREV_IMAGE_TAG ?= us-docker.pkg.dev/quilkin/release/quilkin:0.8.0 MINIKUBE_PROFILE ?= quilkin CARGO_TARGET_DIR ?= /workspace/target/build-image @@ -57,6 +59,7 @@ gcloud_mount_args := -v $(build_path)/.config/gcloud:/root/.config/gcloud cargo_build_x86_64_linux := build --profile=lto --target x86_64-unknown-linux-gnu cargo_build_x86_64_apple := build --release --target x86_64-apple-darwin cargo_build_aarch64-apple := build --release --target aarch64-apple-darwin +cargo_build_aarch64_linux := build --profile=lto --target aarch64-unknown-linux-gnu cargo_build_x86_64_windows := build --release --target x86_64-pc-windows-gnu # _____ _ @@ -103,14 +106,18 @@ binary-archive: ensure-build-image build-licence-report build-all-binaries docker run --rm $(common_rust_args) -w $(CARGO_TARGET_DIR) \ --entrypoint=bash $(BUILD_IMAGE_TAG) -c 'cp ../../license.html . && zip ../../quilkin-$(package_version).zip ./*/lto/quilkin ./*/lto/quilkin.exe ./license.html' -# Build binary for x86_64-unknown-linux-gnu. +# Build binary for x86_64-unknown-linux-gnu and aarch64-unknown-linux-gnu # Use BUILD_LOCAL=1 to build through local cargo rather than through the build container. build-linux-binary: ensure-build-image gen-protobuf ifdef BUILD_LOCAL cargo $(cargo_build_x86_64_linux) + cargo $(cargo_build_aarch64_linux) else - docker run --rm $(common_rust_args) -e "CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/x86_64-linux-gnu-gcc" \ - --entrypoint=cargo $(BUILD_IMAGE_TAG) $(cargo_build_x86_64_linux) + docker run --rm $(common_rust_args) \ + -e "CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/x86_64-linux-gnu-gcc" \ + -e "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/aarch64-linux-gnu-gcc" \ + $(BUILD_IMAGE_TAG) \ + sh -c "cargo $(cargo_build_x86_64_linux) && CC=aarch64-linux-gnu-gcc cargo $(cargo_build_aarch64_linux) --no-default-features" endif # Build binary for x86_64-pc-windows-gnu @@ -147,15 +154,18 @@ endif # Use BUILD_LOCAL=1 to build the binary through local cargo rather than through the build container. build-image: ensure-build-image build-licence-report build-linux-binary build-image: - -mkdir -p "$(project_path)/target/image/" + -mkdir -p "$(project_path)/target/image/linux/amd64" + -mkdir -p "$(project_path)/target/image/linux/arm64" ifdef BUILD_LOCAL - cp "$(project_path)/target/x86_64-unknown-linux-gnu/lto/quilkin" "$(project_path)/target/image/" + cp "$(project_path)/target/x86_64-unknown-linux-gnu/lto/quilkin" "$(project_path)/target/image/linux/amd64/" + cp "$(project_path)/target/aarch64-unknown-linux-gnu/lto/quilkin" "$(project_path)/target/image/linux/arm64/" else - cp "$(project_path)/target/build-image/x86_64-unknown-linux-gnu/lto/quilkin" "$(project_path)/target/image/" + cp "$(project_path)/target/build-image/x86_64-unknown-linux-gnu/lto/quilkin" "$(project_path)/target/image/linux/amd64/" + cp "$(project_path)/target/build-image/aarch64-unknown-linux-gnu/lto/quilkin" "$(project_path)/target/image/linux/arm64/" endif docker run --rm $(common_rust_args) \ --entrypoint=bash $(BUILD_IMAGE_TAG) -c './image/archive_dependencies.sh' - docker build --platform=linux/amd64 -t $(IMAGE_TAG) -f $(project_path)/image/Dockerfile $(project_path) + docker build -t $(IMAGE_TAG) -f $(project_path)/image/Dockerfile $(project_path) # Generates the HTML report of all open source licence dependencies build-licence-report: ensure-build-image @@ -170,7 +180,9 @@ build-licence-report: # to set those options. # If a `kubectl` authentication failure occurs, run `kubectl get ns` to confirm access and refresh the Kubernetes # authentication token, and try again if successful. -test-agones: push +ifndef SKIP_BUILD_IMAGE +test-agones: build-image +endif test-agones: $(MAKE) run-test-agones @@ -189,13 +201,10 @@ run-test-agones: # Convenience target to build and push quilkin images to a repository. # Use `REPOSITORY` arg to specify the repository to push to. -# USe `SKIP_BUILD_IMAGE` if you want to skip building the image if it has been already built. -# See `build-image` for more details. push: -ifndef SKIP_BUILD_IMAGE -push: build-image -endif - docker push $(IMAGE_TAG) + docker buildx create --use --name multi-platform-builder --driver docker-container + docker buildx build --platform=linux/amd64,linux/arm64 -t $(IMAGE_TAG) \ + -f $(project_path)/image/Dockerfile $(project_path) --push # Convenience target to build and push quilkin images into a minikube instance # Use `MINIKUBE_PROFILE` to specify the profile. Defaults to `quilkin`. diff --git a/build/build-image/Dockerfile b/build/build-image/Dockerfile index 1259abb9f2..572f8c02f9 100644 --- a/build/build-image/Dockerfile +++ b/build/build-image/Dockerfile @@ -27,7 +27,7 @@ ENV RUSTUP_HOME=/usr/local/rustup \ RUN set -eux && \ apt-get update && \ apt-get install -y lsb-release jq curl wget zip git build-essential software-properties-common protobuf-compiler \ - libssl-dev pkg-config bash-completion g++-x86-64-linux-gnu g++-mingw-w64-x86-64 && \ + libssl-dev pkg-config bash-completion g++-x86-64-linux-gnu g++-mingw-w64-x86-64 g++-aarch64-linux-gnu && \ echo "source /etc/bash_completion" >> /root/.bashrc # install protoc-gen-doc @@ -60,11 +60,11 @@ RUN git config --global --add safe.directory /workspace RUN set -eux; \ dpkgArch="$(dpkg --print-architecture)" && \ case "${dpkgArch##*-}" in \ - amd64) rustArch='x86_64-unknown-linux-gnu';; \ - armhf) rustArch='armv7-unknown-linux-gnueabihf';; \ - arm64) rustArch='aarch64-unknown-linux-gnu';; \ - i386) rustArch='i686-unknown-linux-gnu';; \ - *) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \ + amd64) rustArch='x86_64-unknown-linux-gnu';; \ + armhf) rustArch='armv7-unknown-linux-gnueabihf';; \ + arm64) rustArch='aarch64-unknown-linux-gnu';; \ + i386) rustArch='i686-unknown-linux-gnu';; \ + *) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \ esac && \ wget --quiet "https://static.rust-lang.org/rustup/dist/${rustArch}/rustup-init" && \ chmod +x rustup-init; \ diff --git a/image/Dockerfile b/image/Dockerfile index 298b7f66cd..d65e10c053 100644 --- a/image/Dockerfile +++ b/image/Dockerfile @@ -12,11 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM gcr.io/distroless/cc-debian12:nonroot as base +FROM gcr.io/distroless/cc-debian12:nonroot AS base WORKDIR / +ARG TARGETPLATFORM COPY ./license.html . COPY ./dependencies-src.zip . -COPY --chown=nonroot:nonroot ./target/image/quilkin . +COPY --chown=nonroot:nonroot ./target/image/${TARGETPLATFORM}/quilkin . USER nonroot:nonroot ENTRYPOINT ["/quilkin"]