Skip to content

Commit

Permalink
Support multi-arch builds
Browse files Browse the repository at this point in the history
  • Loading branch information
mandrean committed Jan 28, 2022
1 parent 27c839a commit b9e4201
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 64 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.PHONY: all build build-rust build-go test

# Builds the Rust library libwasmvm
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0008
BUILDERS_PREFIX := mandrean/libwasmvm-builder:0007
# Contains a full Go dev environment in order to run Go tests on the built library
ALPINE_TESTER := cosmwasm/go-ext-builder:0008-alpine
ALPINE_TESTER := mandrean/libwasmvm-builder:0007-alpine

USER_ID := $(shell id -u)
USER_GROUP = $(shell id -g)
Expand Down
39 changes: 23 additions & 16 deletions builders/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
# we build with go and rust
FROM golang:1.15-alpine3.12

RUN apk add --update \
ca-certificates \
gcc \
musl-dev

ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=1.53.0

# this comes from standard alpine nightly file
# https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile
# with some changes to support our toolchain, etc
RUN set -eux; \
apk add --no-cache \
ca-certificates \
build-base;

RUN wget "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-musl/rustup-init"
RUN chmod +x rustup-init
RUN ./rustup-init -y --no-modify-path --default-toolchain 1.53.0; rm rustup-init
RUN chmod -R a+w $RUSTUP_HOME $CARGO_HOME

# needed for
# /usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find crti.o: No such file or directory
ENV LIBRARY_PATH=/usr/local/rustup/toolchains/1.53.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib:$LIBRARY_PATH
apkArch="$(apk --print-arch)"; \
case "$apkArch" in \
x86_64) rustArch='x86_64-unknown-linux-musl'; rustupSha256='bdf022eb7cba403d0285bb62cbc47211f610caec24589a72af70e1e900663be9' ;; \
aarch64) rustArch='aarch64-unknown-linux-musl'; rustupSha256='89ce657fe41e83186f5a6cdca4e0fd40edab4fd41b0f9161ac6241d49fbdbbbe' ;; \
*) echo >&2 "unsupported architecture: $apkArch"; exit 1 ;; \
esac; \
url="https://static.rust-lang.org/rustup/archive/1.24.3/${rustArch}/rustup-init"; \
wget "$url"; \
echo "${rustupSha256} *rustup-init" | sha256sum -c -; \
chmod +x rustup-init; \
./rustup-init -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION --default-host ${rustArch}; \
rm rustup-init; \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
rustup --version; \
cargo --version; \
rustc --version;

# prepare go cache dirs
RUN mkdir -p /.cache/go-build
Expand Down
36 changes: 0 additions & 36 deletions builders/Dockerfile.centos7

This file was deleted.

17 changes: 17 additions & 0 deletions builders/Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM rust:1.53.0-buster

# allow non-root user to download more deps later
RUN chmod -R 777 /usr/local/cargo

## COPY BUILD SCRIPTS

WORKDIR /code

COPY guest/*.sh /opt/
RUN chmod +x /opt/*.sh

RUN mkdir /.cargo
RUN chmod +rx /.cargo
COPY guest/cargo-config /.cargo/config

CMD ["/opt/build_linux.sh"]
53 changes: 43 additions & 10 deletions builders/Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,57 @@
# Versioned by a simple counter that is not bound to a specific CosmWasm version
# See builders/README.md
BUILDERS_PREFIX := cosmwasm/go-ext-builder:0007
BUILDERS_PREFIX := mandrean/libwasmvm-builder:0007

.PHONY: docker-image-centos7
docker-image-centos7:
docker build . -t $(BUILDERS_PREFIX)-centos7 -f ./Dockerfile.centos7
# https://docs.docker.com/buildx/working-with-buildx/
PLATFORMS = ""
OUTPUT = "type=docker"
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_M),arm64)
PLATFORMS = "linux/arm64"
endif
ifeq ($(UNAME_M),x86_64)
PLATFORMS = "linux/amd64"
endif

.PHONY: docker-buildx
docker-buildx:
docker buildx inspect --builder builder >>/dev/null 2>&1 || (docker buildx create --name builder)
docker buildx use builder >>/dev/null 2>&1
docker buildx inspect --bootstrap >>/dev/null 2>&1

.PHONY: docker-image-debian
docker-image-debian:
docker buildx build . \
--pull \
-t $(BUILDERS_PREFIX)-debian \
-f ./Dockerfile.debian \
--platform $(PLATFORMS) \
--output $(OUTPUT)

.PHONY: docker-image-cross
docker-image-cross:
docker build . -t $(BUILDERS_PREFIX)-cross -f ./Dockerfile.cross
docker buildx build . \
-t $(BUILDERS_PREFIX)-cross \
-f ./Dockerfile.cross \
--platform $(PLATFORMS) \
--output $(OUTPUT)

.PHONY: docker-image-alpine
docker-image-alpine:
docker build . -t $(BUILDERS_PREFIX)-alpine -f ./Dockerfile.alpine
docker buildx build . \
-t $(BUILDERS_PREFIX)-alpine \
-f ./Dockerfile.alpine \
--platform $(PLATFORMS) \
--output $(OUTPUT)

.PHONY: docker-images
docker-images: docker-image-centos7 docker-image-cross docker-image-alpine
docker-images: docker-image-debian docker-image-cross docker-image-alpine

.PHONY: docker-publish
docker-publish: OUTPUT="type=registry"
docker-publish: docker-images
docker push $(BUILDERS_PREFIX)-cross
docker push $(BUILDERS_PREFIX)-centos7
docker push $(BUILDERS_PREFIX)-alpine

.PHONY: docker-publish-multi
docker-publish-multi: PLATFORMS="linux/arm64,linux/amd64"
docker-publish-multi: OUTPUT="type=registry"
docker-publish-multi: docker-images

0 comments on commit b9e4201

Please sign in to comment.