From 3243c7ba07e5123d710d5ac20328840a21964c6a Mon Sep 17 00:00:00 2001 From: Rafael Matias Date: Thu, 13 Jun 2019 14:30:13 +0200 Subject: [PATCH] docker: create new dockerfiles that are context aware (#1463) --- .dockerignore | 2 ++ Dockerfile | 14 ++++++++++++++ Dockerfile.alltools | 15 +++++++++++++++ Makefile | 2 ++ docker/Dockerfile | 32 -------------------------------- docker/run.sh | 6 +++--- 6 files changed, 36 insertions(+), 35 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Dockerfile.alltools delete mode 100644 docker/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..3070d81c76 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.github +.git diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..d4f0e61767 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM golang:1.12-alpine as builder +RUN apk add --no-cache make gcc musl-dev linux-headers git +ADD . /swarm +WORKDIR /swarm +RUN make swarm + +FROM ethereum/client-go:v1.8.27 as geth + +FROM alpine:3.9 +RUN apk --no-cache add ca-certificates +COPY --from=builder /swarm/build/bin/swarm /usr/local/bin/ +COPY --from=geth /usr/local/bin/geth /usr/local/bin/ +COPY docker/run.sh /run.sh +ENTRYPOINT ["/run.sh"] diff --git a/Dockerfile.alltools b/Dockerfile.alltools new file mode 100644 index 0000000000..594333e00c --- /dev/null +++ b/Dockerfile.alltools @@ -0,0 +1,15 @@ +FROM golang:1.12-alpine as builder +RUN apk add --no-cache make gcc musl-dev linux-headers git +ADD . /swarm +WORKDIR /swarm +RUN make alltools + +FROM ethereum/client-go:v1.8.27 as geth + +FROM alpine:3.9 +RUN apk --no-cache add ca-certificates +COPY --from=builder /swarm/build/bin/* /usr/local/bin/ +COPY --from=geth /usr/local/bin/geth /usr/local/bin/ +COPY docker/run.sh /run.sh +COPY docker/run-smoke.sh /run-smoke.sh +ENTRYPOINT ["/run.sh"] diff --git a/Makefile b/Makefile index 5fef15f722..8640c094fd 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,5 @@ swarm: @echo "Done building." @echo "Run \"$(GOBIN)/swarm\" to launch swarm." +alltools: + build/env.sh go run build/ci.go install ./cmd/... diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 9450609dd8..0000000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -FROM golang:1.11-alpine as builder - -ARG VERSION - -RUN apk add --update git gcc g++ linux-headers -RUN mkdir -p $GOPATH/src/github.com/ethereum && \ - cd $GOPATH/src/github.com/ethereum && \ - git clone https://github.com/ethersphere/go-ethereum && \ - cd $GOPATH/src/github.com/ethereum/go-ethereum && \ - git checkout ${VERSION} && \ - go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm && \ - go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm/swarm-smoke && \ - go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm/global-store && \ - go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/geth - - -FROM alpine:3.8 as swarm-smoke -WORKDIR / -COPY --from=builder /go/bin/swarm-smoke / -ADD run-smoke.sh /run-smoke.sh -ENTRYPOINT ["/run-smoke.sh"] - -FROM alpine:3.8 as swarm-global-store -WORKDIR / -COPY --from=builder /go/bin/global-store / -ENTRYPOINT ["/global-store"] - -FROM alpine:3.8 as swarm -WORKDIR / -COPY --from=builder /go/bin/swarm /go/bin/geth / -ADD run.sh /run.sh -ENTRYPOINT ["/run.sh"] diff --git a/docker/run.sh b/docker/run.sh index 3e613b56d9..4be91ba82f 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -12,15 +12,15 @@ if [ "$PASSWORD" == "" ]; then echo "Password must be set, in order to use swarm echo $PASSWORD > /password KEYFILE=`find $DATADIR | grep UTC | head -n 1` || true -if [ ! -f "$KEYFILE" ]; then echo "No keyfile found. Generating..." && /geth --datadir $DATADIR --password /password account new; fi +if [ ! -f "$KEYFILE" ]; then echo "No keyfile found. Generating..." && geth --datadir $DATADIR --password /password account new; fi KEYFILE=`find $DATADIR | grep UTC | head -n 1` || true if [ ! -f "$KEYFILE" ]; then echo "Could not find nor generate a BZZ keyfile." && exit 1; else echo "Found keyfile $KEYFILE"; fi -VERSION=`/swarm version` +VERSION=`swarm version` echo "Running Swarm:" echo $VERSION export BZZACCOUNT="`echo -n $KEYFILE | tail -c 40`" || true if [ "$BZZACCOUNT" == "" ]; then echo "Could not parse BZZACCOUNT from keyfile." && exit 1; fi -exec /swarm --bzzaccount=$BZZACCOUNT --password /password --datadir $DATADIR $@ 2>&1 +exec swarm --bzzaccount=$BZZACCOUNT --password /password --datadir $DATADIR $@ 2>&1