From 907c10dfd145dda8208835059cd2dbe8fb71e1ad Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Fri, 21 Dec 2018 12:29:28 +0100 Subject: [PATCH] swarm/docker: Dockerfile for swarm:edge docker image --- swarm/docker/Dockerfile | 19 +++++++++++++++++++ swarm/docker/run.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 swarm/docker/Dockerfile create mode 100755 swarm/docker/run.sh diff --git a/swarm/docker/Dockerfile b/swarm/docker/Dockerfile new file mode 100644 index 0000000000..b4c234881a --- /dev/null +++ b/swarm/docker/Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.11-alpine as builder + +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 --depth 1 https://github.com/ethersphere/go-ethereum && \ + cd $GOPATH/src/github.com/ethereum/go-ethereum && \ + VERSION=$(git rev-parse --short HEAD) go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm && \ + VERSION=$(git rev-parse --short HEAD) go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm/swarm-smoke && \ + VERSION=$(git rev-parse --short HEAD) go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/geth && \ + cp $GOPATH/bin/swarm /swarm && cp $GOPATH/bin/geth /geth && cp $GOPATH/bin/swarm-smoke /swarm-smoke + + +# Release image with the required binaries and scripts +FROM alpine:3.8 +WORKDIR / +COPY --from=builder /swarm /geth /swarm-smoke / +ADD run.sh /run.sh +ENTRYPOINT ["/run.sh"] diff --git a/swarm/docker/run.sh b/swarm/docker/run.sh new file mode 100755 index 0000000000..3e613b56d9 --- /dev/null +++ b/swarm/docker/run.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +set -o errexit +set -o pipefail +set -o nounset + +PASSWORD=${PASSWORD:-} +DATADIR=${DATADIR:-/root/.ethereum/} + +if [ "$PASSWORD" == "" ]; then echo "Password must be set, in order to use swarm non-interactively." && exit 1; fi + +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 +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` +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