Skip to content

Commit

Permalink
Merge pull request #2 from blcksync/master
Browse files Browse the repository at this point in the history
Automate launch with one script
  • Loading branch information
al-blockmed authored Sep 8, 2018
2 parents bac3bcb + 61403d4 commit e6ef96e
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 27 deletions.
99 changes: 75 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
&& 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

Expand All @@ -58,7 +103,11 @@ RUN mkdir $HOME/bin && \
[email protected] \
[email protected] \
[email protected] \
&& 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

Expand All @@ -68,3 +117,5 @@ EXPOSE 4002/udp
EXPOSE 5001
EXPOSE 8080
EXPOSE 8081
# Geth ports
EXPOSE 8545 8546 30303 30303/udp
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ RUN mkdir $HOME/bin && \
[email protected] \
[email protected] \
[email protected] \
[email protected].1 \
[email protected].4 \
[email protected] \
&& ln -s $HOME/node_modules/dat/bin/cli.js $HOME/bin/dat

Expand Down
20 changes: 20 additions & 0 deletions bin/launch.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e6ef96e

Please sign in to comment.