diff --git a/Dockerfile b/Dockerfile index 873b4c9..c6c0a93 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,49 +1,94 @@ -FROM go-node:latest - -LABEL maintainer="matr1xc0in" +FROM go-node:latest as builder ENV SHELL=/bin/bash \ IPFS_USER=ipfsuser \ IPFS_UID=3888 \ - IPFS_GID=4888 + IPFS_GID=4888 \ + GOPATH=/go ENV HOME=/home/$IPFS_USER -USER root WORKDIR /root -RUN apk update && apk upgrade && \ +RUN addgroup -g $IPFS_GID $IPFS_USER && \ + adduser -u $IPFS_UID -g $IPFS_GID -h $HOME -S -s /bin/bash $IPFS_USER && \ + chmod g+w /etc/passwd /etc/group && \ + source /etc/profile.d/go_path.sh && \ + chown -R $IPFS_UID:$IPFS_GID $HOME && \ + apk update && apk upgrade && \ apk add --no-cache bash git \ + busybox-extras \ python \ python-dev \ py-pip \ libtool \ build-base \ + make gcc musl-dev linux-headers \ && rm -rf /var/cache/apk/* && \ echo "export PATH=/usr/local/go/bin:\$GOPATH/bin:\$PATH:\$HOME/bin" > /etc/profile.d/go_path.sh -RUN addgroup -g $IPFS_GID $IPFS_USER && \ - adduser -u $IPFS_UID -g $IPFS_GID -h $HOME -S -s /bin/bash $IPFS_USER && \ - chmod g+w /etc/passwd /etc/group +# Install go-ipfs and gx +RUN source /etc/profile.d/go_path.sh && \ + go get -u -d github.com/ipfs/go-ipfs && cd $GOPATH/src/github.com/ipfs/go-ipfs && \ + make install_unsupported -ENV IPFS_VERSION=0.4.15 \ - IPFS_SHA256=48a81cfc34d3a12c8563dbdfae8681be6e4d23c0664d6a192bc2758c4e4ef377 +# Install geth +RUN cd /root; \ + git clone -b release/1.8 --depth 1 https://github.com/matr1xc0in/go-ethereum.git && \ + cd /root/go-ethereum && make geth + +USER $IPFS_UID + +WORKDIR $HOME + +# Install ipfs JS API +RUN mkdir $HOME/bin && \ + npm install --save \ + bignumber.js@7.2.1 \ + bn.js@4.11.8 \ + secp256k1@3.4.0 \ + debug@3.1.0 \ + ipfs-api@22.2.4 \ + dat@13.10.0 \ + && ln -s $HOME/node_modules/dat/bin/cli.js $HOME/bin/dat ; \ + cd $HOME; git clone --depth 1 -b master https://github.com/blcksync/bc-ipfs.git; \ + cd bc-ipfs/bc-ipfs && npm install -# RUN cd /tmp/ && \ -# wget -O go-ipfs.tgz https://dist.ipfs.io/go-ipfs/v${IPFS_VERSION}/go-ipfs_v${IPFS_VERSION}_linux-amd64.tar.gz && \ -# echo "${IPFS_SHA256} go-ipfs.tgz" | sha256sum -c -; \ -# tar -xzf go-ipfs.tgz \ -# && cd go-ipfs* \ -# && bash install.sh +FROM alpine-node:latest -# add to image and unzip it -COPY ./bc-ipfs-example $HOME/bc-ipfs-example +LABEL maintainer="matr1xc0in" + +ENV SHELL=/bin/bash \ + IPFS_USER=ipfsuser \ + IPFS_UID=3888 \ + IPFS_GID=4888 \ + GOPATH=/go +ENV HOME=/home/$IPFS_USER + +USER root +WORKDIR /root + +RUN apk update && apk upgrade && \ + apk add --no-cache ca-certificates bash git busybox-extras && \ + rm -rf /var/cache/apk/* && \ + echo "export PATH=/usr/local/go/bin:\$GOPATH/bin:\$PATH:\$HOME/bin" > /etc/profile.d/go_path.sh + +COPY --from=builder /usr/local/go/bin/* /usr/local/go/bin/ +COPY --from=builder /go/bin/* /go/bin/ +COPY --from=builder /root/go-ethereum/build/bin/geth /usr/local/bin/ +COPY --from=builder $HOME/bc-ipfs/bc-ipfs $HOME/ # Install go-ipfs and gx -RUN source /etc/profile.d/go_path.sh && \ - go get -u -d github.com/ipfs/go-ipfs && cd $GOPATH/src/github.com/ipfs/go-ipfs && \ - make install_unsupported ; \ +RUN addgroup -g $IPFS_GID $IPFS_USER && \ + adduser -u $IPFS_UID -g $IPFS_GID -h $HOME -S -s /bin/bash $IPFS_USER && \ + chmod g+w /etc/passwd /etc/group && \ + source /etc/profile.d/go_path.sh && \ chown -R $IPFS_UID:$IPFS_GID $HOME && \ - chown -R $IPFS_UID:$IPFS_GID $HOME/bc-ipfs-example + chown -R $IPFS_UID:$IPFS_GID /usr/local/bin/geth && \ + chown -R $IPFS_UID:$IPFS_GID /usr/local/go/bin/* && \ + chown -R $IPFS_UID:$IPFS_GID /go/bin/* + +ENV IPFS_VERSION=0.4.15 \ + IPFS_SHA256=48a81cfc34d3a12c8563dbdfae8681be6e4d23c0664d6a192bc2758c4e4ef377 USER $IPFS_UID @@ -58,7 +103,11 @@ RUN mkdir $HOME/bin && \ debug@3.1.0 \ ipfs-api@22.2.4 \ dat@13.10.0 \ - && ln -s $HOME/node_modules/dat/bin/cli.js $HOME/bin/dat + && ln -s $HOME/node_modules/dat/bin/cli.js $HOME/bin/dat ; + +COPY ./bin/*.sh $HOME/bin/ + +CMD ["/home/ipfsuser/bin/launch.sh"] EXPOSE 3000 @@ -68,3 +117,5 @@ EXPOSE 4002/udp EXPOSE 5001 EXPOSE 8080 EXPOSE 8081 +# Geth ports +EXPOSE 8545 8546 30303 30303/udp diff --git a/Dockerfile.dev b/Dockerfile.dev index 8e5e8a1..416130f 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -71,7 +71,7 @@ RUN mkdir $HOME/bin && \ bn.js@4.11.8 \ secp256k1@3.4.0 \ debug@3.1.0 \ - ipfs-api@22.2.1 \ + ipfs-api@22.2.4 \ dat@13.10.0 \ && ln -s $HOME/node_modules/dat/bin/cli.js $HOME/bin/dat diff --git a/bin/launch.sh b/bin/launch.sh new file mode 100755 index 0000000..2ca3249 --- /dev/null +++ b/bin/launch.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -a +source /etc/profile.d/go_path.sh + +ipfs init +ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080 +ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001 +# See https://github.com/ipfs/js-ipfs-api#cors for more refining policies on +# acceptable URLs (CORS = Cross Origin Resource Sharing) +# The following policy creates SECURITY BREACH!!!!!!!!!! +# TODO: Fix this +ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin "[\"*\"]" +ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials "[\"true\"]" +ipfs daemon & + +set +a + +cd $HOME +npm start diff --git a/run.sh b/run.sh index 3828733..ab38a8d 100755 --- a/run.sh +++ b/run.sh @@ -4,5 +4,4 @@ docker run --rm -it \ --publish 127.0.0.1:3000:3000 \ --publish 127.0.0.1:5001:5001 \ --publish 127.0.0.1:8080:8080 \ - bc-ipfs \ - bash -l + bc-ipfs