Skip to content

Commit

Permalink
Merge pull request #106 from CosmWasm/improve-alpine-build
Browse files Browse the repository at this point in the history
Improve alpine compile tooling
  • Loading branch information
ethanfrey authored Jun 15, 2020
2 parents 4944e66 + e53e335 commit 6f82d95
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
14 changes: 10 additions & 4 deletions Dockerfile.alpine-rust → Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# 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
# 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 \
Expand All @@ -21,6 +22,11 @@ RUN chmod -R a+w $RUSTUP_HOME $CARGO_HOME
# /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/
Expand Down
7 changes: 0 additions & 7 deletions Dockerfile.alpine-go

This file was deleted.

14 changes: 5 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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 -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
docker push cosmwasm/go-ext-tester:$(DOCKER_TAG)-alpine

# and use them to compile release builds
release:
Expand All @@ -82,11 +80,9 @@ test-alpine:
rm -rf target/release/examples
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-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 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-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 go build -tags muslc -o muslc.exe ./cmd
# run static binary locally (not dlls)
./muslc.exe ./api/testdata/hackatom.wasm
4 changes: 2 additions & 2 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 6f82d95

Please sign in to comment.