Skip to content

Commit accbad5

Browse files
committed
feat: added proxy middleware into ipfs s3 node
1 parent 4503f8e commit accbad5

File tree

2 files changed

+101
-3
lines changed

2 files changed

+101
-3
lines changed

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ RUN mkdir -p ${IPFS_PATH}
6262
# configure ipfs for production
6363
RUN ipfs init -p server
6464

65-
RUN ipfs config Datastore.StorageMax 150GB && \
66-
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
65+
RUN ipfs config Datastore.StorageMax 2TB && \
66+
ipfs config Routing.Type none && \
67+
ipfs bootstrap add /ip4/3.110.235.23/tcp/4001/p2p/12D3KooWGLVpG6uUMZoKhAdyJGbsqhPyea4qPA8CDqBxaiPhXe3e
68+
69+
6770

6871
RUN ipfs config --json Datastore.Spec "{\"mounts\":[{\"child\":{\"accessKey\":\"${AWS_ACCESS_KEY}\",\"bucket\":\"${AWS_S3_BUCKET}\",\"region\":\"${AWS_REGION}\",\"secretKey\":\"${AWS_SECRET_KEY}\",\"type\":\"s3ds\"},\"mountpoint\":\"/blocks\",\"prefix\":\"s3.datastore\",\"type\":\"measure\"},{\"child\": {\"compression\":\"none\",\"path\":\"datastore\",\"type\":\"levelds\"},\"mountpoint\": \"/\",\"prefix\":\"leveldb.datastore\",\"type\":\"measure\"}],\"type\":\"mount\"}"
6972

7073
RUN echo "{\"mounts\":[{\"bucket\":\"${AWS_S3_BUCKET}\",\"mountpoint\":\"/blocks\",\"region\":\"${AWS_REGION}\",\"rootDirectory\":\"\"},{\"mountpoint\":\"/\",\"path\":\"datastore\",\"type\":\"levelds\"}],\"type\":\"mount\"}" > $IPFS_PATH/datastore_spec
7174

7275
# by default, run `ipfs daemon` to start as a running node
73-
ENTRYPOINT ipfs daemon --enable-gc
76+
ENTRYPOINT ipfs daemon

Dockerfile.proxy

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# FROM ubuntu:20.04
2+
FROM golang:1.18.1
3+
4+
LABEL maintainer "Perfection <[email protected]>"
5+
6+
# update apt and install dependencies
7+
# RUN export TZ="Asia/Jakarta" && \
8+
# export DEBIAN_FRONTEND=noninteractive && \
9+
# apt update && \
10+
# apt install -y golang-go git && \
11+
# echo "GIT VERSION IS -- $(git --version)"
12+
13+
# clone ipfs
14+
RUN git clone https://github.com/ipfs/go-ipfs && \
15+
cd go-ipfs && \
16+
#git checkout release-v0.15.0 && \
17+
go get github.com/samperfect/go-ds-s3/[email protected]
18+
19+
20+
# Add the plugin to the preload list.
21+
RUN cd go-ipfs && \
22+
echo "\ns3ds github.com/samperfect/go-ds-s3/plugin 0" >> plugin/loader/preload_list &&\
23+
cat plugin/loader/preload_list && \
24+
cat plugin/loader/preload.go && \
25+
make build && \
26+
go mod tidy && \
27+
make build && \
28+
make install && \
29+
cp cmd/ipfs/ipfs /usr/local/bin/ipfs
30+
31+
# checkpoint --- echo ipfs version
32+
RUN ipfs version
33+
RUN echo "IPFS VERSION IS -- $(ipfs version)"
34+
35+
ENV IPFS_PATH /data/ipfs
36+
37+
ENV API_PORT 5002
38+
ENV GATEWAY_PORT 8080
39+
ENV SWARM_PORT 4001
40+
ENV PROXY_PORT 5050
41+
42+
# defining args to be passed in at build time
43+
ARG AWS_SECRET_KEY
44+
ARG AWS_ACCESS_KEY
45+
ARG AWS_REGION
46+
ARG AWS_S3_BUCKET
47+
ARG GITHUB_TOKEN
48+
ARG IPFS_ENDPOINT
49+
50+
ENV AWS_SECRET_KEY $AWS_SECRET_KEY
51+
ENV AWS_ACCESS_KEY $AWS_ACCESS_KEY
52+
ENV AWS_REGION $AWS_REGION
53+
ENV AWS_S3_BUCKET $AWS_S3_BUCKET
54+
ENV GITHUB_TOKEN $GITHUB_TOKEN
55+
ENV IPFS_ENDPOINT $IPFS_ENDPOINT
56+
57+
EXPOSE ${SWARM_PORT}
58+
# This may introduce security risk to expose API_PORT public
59+
# EXPOSE ${API_PORT}
60+
EXPOSE ${GATEWAY_PORT}
61+
EXPOSE ${PROXY_PORT}
62+
63+
RUN mkdir -p ${IPFS_PATH}
64+
65+
# no need to for this as docker runs in root user mode
66+
# RUN chown ubuntu:ubuntu ${IPFS_PATH}
67+
68+
# configure ipfs for production
69+
RUN ipfs init -p server
70+
71+
RUN ipfs config Datastore.StorageMax 2TB && \
72+
ipfs config Routing.Type none && \
73+
ipfs bootstrap add /ip4/3.110.235.23/tcp/4001/p2p/12D3KooWGLVpG6uUMZoKhAdyJGbsqhPyea4qPA8CDqBxaiPhXe3e
74+
75+
76+
77+
RUN ipfs config --json Datastore.Spec "{\"mounts\":[{\"child\":{\"accessKey\":\"${AWS_ACCESS_KEY}\",\"bucket\":\"${AWS_S3_BUCKET}\",\"region\":\"${AWS_REGION}\",\"secretKey\":\"${AWS_SECRET_KEY}\",\"type\":\"s3ds\"},\"mountpoint\":\"/blocks\",\"prefix\":\"s3.datastore\",\"type\":\"measure\"},{\"child\": {\"compression\":\"none\",\"path\":\"datastore\",\"type\":\"levelds\"},\"mountpoint\": \"/\",\"prefix\":\"leveldb.datastore\",\"type\":\"measure\"}],\"type\":\"mount\"}"
78+
79+
RUN echo "{\"mounts\":[{\"bucket\":\"${AWS_S3_BUCKET}\",\"mountpoint\":\"/blocks\",\"region\":\"${AWS_REGION}\",\"rootDirectory\":\"\"},{\"mountpoint\":\"/\",\"path\":\"datastore\",\"type\":\"levelds\"}],\"type\":\"mount\"}" > $IPFS_PATH/datastore_spec
80+
81+
RUN apt update -y && \
82+
apt install -y nodejs && \
83+
echo "NODE VERSION $(node --version)"
84+
85+
RUN git clone https://samperfect:${GITHUB_TOKEN}@github.com/lighthouse-web3/node-authentication-middleware.git proxy && \
86+
cd proxy && \
87+
apt install -y npm && \
88+
npm install && \
89+
npm install -g pm2
90+
91+
RUN echo "PM2 VERSION -- $(pm2 --version)" && \
92+
stat proxy/app.js
93+
94+
# by default, run `ipfs daemon` to start as a running node
95+
ENTRYPOINT pm2 start proxy/app.js && ipfs daemon

0 commit comments

Comments
 (0)