From d8599dbb8c163b47177768cee37c770756487ce1 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 10 Jun 2020 21:48:49 +0200 Subject: [PATCH 1/3] Use one alpine-combi builder for both rust and go --- Dockerfile.alpine-combi | 50 +++++++++++++++++++++++++++++++++++++++++ Makefile | 16 +++++-------- 2 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 Dockerfile.alpine-combi diff --git a/Dockerfile.alpine-combi b/Dockerfile.alpine-combi new file mode 100644 index 000000000..ca95e42c4 --- /dev/null +++ b/Dockerfile.alpine-combi @@ -0,0 +1,50 @@ +# we build with go and rust +FROM golang:1.14-alpine3.12 + +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH + +# 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 nightly-2020-06-08; 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/nightly-2020-06-08-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib:$LIBRARY_PATH + +# prepare go cache dirs +RUN mkdir -p /.cache/go-build +RUN chmod -R 777 /.cache + + +# PRE-FETCH MANY DEPS +WORKDIR /scratch +COPY Cargo.toml /scratch/ +COPY Cargo.lock /scratch/ +COPY src /scratch/src +RUN cargo fetch +# allow non-root user to download more deps later +RUN chmod -R 777 /usr/local/cargo + +## COPY BUILD SCRIPTS +WORKDIR /code +RUN rm -rf /scratch + +COPY build/build_muslc.sh /opt +RUN chmod +x /opt/build* + +RUN mkdir /.cargo +RUN chmod +rx /.cargo +COPY build/cargo-config /.cargo/config + +CMD ["/opt/build_muslc.sh"] diff --git a/Makefile b/Makefile index 0837307c4..3f77481a9 100644 --- a/Makefile +++ b/Makefile @@ -59,16 +59,14 @@ docker-image-cross: docker build . -t cosmwasm/go-ext-builder:$(DOCKER_TAG)-cross -f ./Dockerfile.cross docker-image-alpine: - docker build . -t cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine -f ./Dockerfile.alpine-rust - docker build . -t cosmwasm/go-ext-tester:$(DOCKER_TAG)-alpine -f ./Dockerfile.alpine-go + docker build . -t cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine-combi -f ./Dockerfile.alpine-combi docker-images: docker-image-centos7 docker-image-cross docker-image-alpine docker-publish: docker-images docker push cosmwasm/go-ext-builder:$(DOCKER_TAG)-cross docker push cosmwasm/go-ext-builder:$(DOCKER_TAG)-centos7 - docker push cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine - docker push cosmwasm/go-ext-tester:$(DOCKER_TAG)-alpine + docker push cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine-combi # and use them to compile release builds release: @@ -80,13 +78,11 @@ release: test-alpine: # build the muslc *.a file rm -rf target/release/examples - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine-combi # try running go tests using this lib with muslc - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code cosmwasm/go-ext-tester:$(DOCKER_TAG)-alpine go build -tags muslc . - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code cosmwasm/go-ext-tester:$(DOCKER_TAG)-alpine go test -tags muslc ./api ./types + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine-combi go build -tags muslc . + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine-combi go test -tags muslc ./api ./types # build a go binary - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code cosmwasm/go-ext-tester:$(DOCKER_TAG)-alpine go build -tags muslc -o muslc.exe ./cmd - # run this binary in a simple alpine image - docker run --rm -it -v $(shell pwd):/code -w /code alpine:3.12 ./muslc.exe ./api/testdata/hackatom.wasm + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine-combi go build -tags muslc -o muslc.exe ./cmd # run static binary locally (not dlls) ./muslc.exe ./api/testdata/hackatom.wasm From c0f4fd4f6b74df8bed2cedb6732c32347fb876d5 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 10 Jun 2020 23:26:08 +0200 Subject: [PATCH 2/3] Fix public migrate interface --- lib.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib.go b/lib.go index 134abaca0..19e7a6554 100644 --- a/lib.go +++ b/lib.go @@ -181,12 +181,12 @@ func (w *Wasmer) Query( // the given data. // // MigrateMsg has some data on how to perform the migration. -func (w *Wasmer) Migrate(code CodeID, env types.Env, migrateMsg []byte, store *KVStore, goapi GoAPI, querier *Querier, gasMeter *api.GasMeter, gasLimit uint64) (*types.Result, uint64, error) { +func (w *Wasmer) Migrate(code CodeID, env types.Env, migrateMsg []byte, store KVStore, goapi GoAPI, querier Querier, gasMeter api.GasMeter, gasLimit uint64) (*types.Result, uint64, error) { paramBin, err := json.Marshal(env) if err != nil { return nil, 0, err } - data, gasUsed, err := api.Migrate(w.cache, code, paramBin, migrateMsg, gasMeter, store, &goapi, querier, gasLimit) + data, gasUsed, err := api.Migrate(w.cache, code, paramBin, migrateMsg, &gasMeter, &store, &goapi, &querier, gasLimit) if err != nil { return nil, gasUsed, err } From e53e335069332e9fafef4816da4ece29a68f6ad9 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 15 Jun 2020 23:45:48 +0200 Subject: [PATCH 3/3] Just one -alpine docker file, bump docker tag to 0.8.2 --- Dockerfile.alpine-combi => Dockerfile.alpine | 0 Dockerfile.alpine-go | 7 ---- Dockerfile.alpine-rust | 44 -------------------- Makefile | 14 +++---- 4 files changed, 7 insertions(+), 58 deletions(-) rename Dockerfile.alpine-combi => Dockerfile.alpine (100%) delete mode 100644 Dockerfile.alpine-go delete mode 100644 Dockerfile.alpine-rust diff --git a/Dockerfile.alpine-combi b/Dockerfile.alpine similarity index 100% rename from Dockerfile.alpine-combi rename to Dockerfile.alpine diff --git a/Dockerfile.alpine-go b/Dockerfile.alpine-go deleted file mode 100644 index 7008c109e..000000000 --- a/Dockerfile.alpine-go +++ /dev/null @@ -1,7 +0,0 @@ -FROM golang:1.14-alpine3.12 - -RUN set -eux; \ - apk add --no-cache build-base; - -RUN mkdir -p /.cache/go-build -RUN chmod -R 777 /.cache diff --git a/Dockerfile.alpine-rust b/Dockerfile.alpine-rust deleted file mode 100644 index 9965053a1..000000000 --- a/Dockerfile.alpine-rust +++ /dev/null @@ -1,44 +0,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 -FROM alpine:3.12 - -ENV RUSTUP_HOME=/usr/local/rustup \ - CARGO_HOME=/usr/local/cargo \ - PATH=/usr/local/cargo/bin:$PATH - -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 nightly-2020-06-08; 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/nightly-2020-06-08-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib:$LIBRARY_PATH - -# PRE-FETCH MANY DEPS -WORKDIR /scratch -COPY Cargo.toml /scratch/ -COPY Cargo.lock /scratch/ -COPY src /scratch/src -RUN cargo fetch -# allow non-root user to download more deps later -RUN chmod -R 777 /usr/local/cargo - -## COPY BUILD SCRIPTS -WORKDIR /code -RUN rm -rf /scratch - -COPY build/build_muslc.sh /opt -RUN chmod +x /opt/build* - -RUN mkdir /.cargo -RUN chmod +rx /.cargo -COPY build/cargo-config /.cargo/config - -CMD ["/opt/build_muslc.sh"] diff --git a/Makefile b/Makefile index 3f77481a9..3f9b3b7e1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: all build build-rust build-go test docker-image docker-image-centos7 docker-image-cross -DOCKER_TAG := 0.8.1 +DOCKER_TAG := 0.8.2 USER_ID := $(shell id -u) USER_GROUP = $(shell id -g) @@ -59,14 +59,14 @@ docker-image-cross: docker build . -t cosmwasm/go-ext-builder:$(DOCKER_TAG)-cross -f ./Dockerfile.cross docker-image-alpine: - docker build . -t cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine-combi -f ./Dockerfile.alpine-combi + docker build . -t cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine -f ./Dockerfile.alpine docker-images: docker-image-centos7 docker-image-cross docker-image-alpine docker-publish: docker-images docker push cosmwasm/go-ext-builder:$(DOCKER_TAG)-cross docker push cosmwasm/go-ext-builder:$(DOCKER_TAG)-centos7 - docker push cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine-combi + docker push cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine # and use them to compile release builds release: @@ -78,11 +78,11 @@ release: test-alpine: # build the muslc *.a file rm -rf target/release/examples - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine-combi + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine # try running go tests using this lib with muslc - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine-combi go build -tags muslc . - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine-combi go test -tags muslc ./api ./types + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine go build -tags muslc . + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine go test -tags muslc ./api ./types # build a go binary - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine-combi go build -tags muslc -o muslc.exe ./cmd + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code cosmwasm/go-ext-builder:$(DOCKER_TAG)-alpine go build -tags muslc -o muslc.exe ./cmd # run static binary locally (not dlls) ./muslc.exe ./api/testdata/hackatom.wasm