|
1 |
| -### Build blockstack-core-sidecar API |
2 |
| -FROM node:lts-buster as build |
3 |
| - |
4 |
| -ARG API_TAG=v0.29.4 |
5 |
| - |
6 |
| -RUN apt-get -y update && apt-get -y install openjdk-11-jre-headless |
7 |
| - |
| 1 | +ARG STACKS_API_VERSION=v0.56.0 |
| 2 | +ARG STACKS_NODE_VERSION=2.0.11.0.0 |
| 3 | +ARG STACKS_API_REPO=blockstack/stacks-blockchain-api |
| 4 | +ARG STACKS_NODE_REPO=blockstack/stacks-blockchain |
| 5 | +ARG PG_VERSION=12 |
| 6 | +ARG STACKS_NETWORK=testnet |
| 7 | +ARG STACKS_LOG_DIR=/var/log/stacks-node |
| 8 | +ARG STACKS_SVC_DIR=/etc/service |
| 9 | +ARG STACKS_BLOCKCHAIN_DIR=/stacks-blockchain |
| 10 | +ARG STACKS_BLOCKCHAIN_API_DIR=/stacks-blockchain-api |
| 11 | +ARG PG_DATA=/data/postgres |
| 12 | +ARG V2_POX_MIN_AMOUNT_USTX=90000000260 |
| 13 | + |
| 14 | +####################################################################### |
| 15 | +## Build the stacks-blockchain-api |
| 16 | +FROM node:lts-buster as stacks-blockchain-api-build |
| 17 | +ARG STACKS_API_REPO |
| 18 | +ARG STACKS_API_VERSION |
| 19 | +ENV STACKS_API_REPO=${STACKS_API_REPO} |
| 20 | +ENV STACKS_API_VERSION=${STACKS_API_VERSION} |
8 | 21 | WORKDIR /app
|
9 |
| - |
10 |
| -RUN git clone -b $API_TAG --depth 1 https://github.com/blockstack/stacks-blockchain-api.git . |
11 |
| -RUN echo "GIT_TAG=$(git tag --points-at HEAD)" >> .env |
12 |
| -RUN npm install && npm run build && npm prune --production |
13 |
| - |
14 |
| -### Build stacks-node binary |
15 |
| - |
16 |
| -FROM rust:stretch as stacks-node-build |
17 |
| - |
18 |
| -ARG STACKS_TAG=2.0.5 |
19 |
| - |
20 |
| -RUN mkdir -p /src /stacks |
| 22 | +RUN apt-get update -y \ |
| 23 | + && apt-get install -y \ |
| 24 | + curl \ |
| 25 | + jq \ |
| 26 | + openjdk-11-jre-headless \ |
| 27 | + && git clone -b ${STACKS_API_VERSION} --depth 1 https://github.com/${STACKS_API_REPO} . \ |
| 28 | + && echo "GIT_TAG=$(git tag --points-at HEAD)" >> .env \ |
| 29 | + && npm config set unsafe-perm true \ |
| 30 | + && npm install \ |
| 31 | + && npm run build \ |
| 32 | + && npm prune --production |
| 33 | + |
| 34 | +####################################################################### |
| 35 | +## Build the stacks-blockchain |
| 36 | +FROM rust:buster as stacks-blockchain-build |
| 37 | +ARG STACKS_NODE_REPO |
| 38 | +ARG STACKS_NODE_VERSION |
| 39 | +ENV STACKS_NODE_REPO=${STACKS_NODE_REPO} |
| 40 | +ENV STACKS_NODE_VERSION=${STACKS_NODE_VERSION} |
21 | 41 | WORKDIR /src
|
22 |
| -RUN git clone -b $STACKS_TAG --depth 1 https://github.com/blockstack/stacks-blockchain.git . |
23 |
| -RUN rustup target add x86_64-unknown-linux-gnu |
24 |
| -RUN cargo build --release --workspace=./ --target x86_64-unknown-linux-gnu |
25 |
| -RUN cp -R /src/target/x86_64-unknown-linux-gnu/release/. /stacks |
26 |
| - |
27 |
| -### Fetch stacks-node binary |
28 |
| - |
29 |
| -### Begin building base image |
30 |
| -FROM ubuntu:focal |
31 |
| - |
32 |
| -ARG STACKS_NETWORK=testnet |
33 |
| - |
34 |
| -SHELL ["/bin/bash", "-c"] |
35 |
| - |
36 |
| -### Install utils |
37 |
| -RUN apt-get update |
38 |
| -RUN apt-get install -y sudo curl pslist |
39 |
| - |
40 |
| -### Set noninteractive apt-get |
41 |
| -RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections |
42 |
| - |
43 |
| -### Storage goes in /data; see https://www.rosetta-api.org/docs/standard_storage_location.html |
44 |
| -RUN mkdir -p /data |
45 |
| - |
46 |
| -### Install nodejs |
47 |
| -RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - |
48 |
| -RUN apt-get install -y nodejs |
49 |
| - |
50 |
| -### stacky user ### |
51 |
| -# see https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user |
52 |
| -RUN useradd -l -u 33333 -G sudo -md /data/stacky -s /bin/bash -p stacky stacky \ |
53 |
| - # passwordless sudo for users in the 'sudo' group |
54 |
| - && sed -i.bkp -e 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers |
55 |
| -ENV HOME=/data/stacky |
56 |
| -WORKDIR $HOME |
57 |
| -USER stacky |
58 |
| -RUN sudo chown -R stacky:stacky $HOME |
59 |
| -RUN mkdir /data/stacky/.bashrc.d |
60 |
| - |
61 |
| -### Node.js |
62 |
| -RUN node -e 'console.log("Node.js runs")' |
63 |
| - |
64 |
| -### Setup stacks-node |
65 |
| -COPY --from=stacks-node-build /stacks/stacks-node stacks-node/ |
66 |
| -ENV PATH="$PATH:$HOME/stacks-node" |
67 |
| - |
68 |
| -### Setup stacks-blockchain-api |
69 |
| -COPY --from=build /app stacks-blockchain-api |
70 |
| - |
71 |
| -#### Copy stacks-node mocknet config |
72 |
| -RUN cp stacks-blockchain-api/stacks-blockchain/*.toml . |
73 |
| - |
74 |
| -RUN sudo chown -Rh stacky:stacky stacks-blockchain-api |
75 |
| -RUN printf '#!/bin/bash\ncd $(dirname $0)\nnpm run start\n' > stacks-blockchain-api/stacks_api \ |
76 |
| - && chmod +x stacks-blockchain-api/stacks_api |
77 |
| -ENV PATH="$PATH:$HOME/stacks-blockchain-api" |
78 |
| -EXPOSE 3999 |
79 |
| - |
80 |
| -### Install Postgres |
81 |
| -RUN sudo apt-get install -y postgresql-12 postgresql-contrib-12 |
82 |
| - |
83 |
| -### Setup Postgres |
84 |
| -# Borrowed from https://github.com/gitpod-io/workspace-images/blob/master/postgres/Dockerfile |
85 |
| -ENV PATH="$PATH:/usr/lib/postgresql/12/bin" |
86 |
| -ENV PGDATA="/data/stacky/.pgsql/data" |
87 |
| -RUN mkdir -p ~/.pg_ctl/bin ~/.pg_ctl/sockets \ |
88 |
| - && printf '#!/bin/bash\n[ ! -d $PGDATA ] && mkdir -p $PGDATA && initdb -D $PGDATA\npg_ctl -D $PGDATA -l ~/.pg_ctl/log -o "-k ~/.pg_ctl/sockets" start\n' > ~/.pg_ctl/bin/pg_start \ |
89 |
| - && printf '#!/bin/bash\npg_ctl -D $PGDATA -l ~/.pg_ctl/log -o "-k ~/.pg_ctl/sockets" stop\n' > ~/.pg_ctl/bin/pg_stop \ |
90 |
| - && chmod +x ~/.pg_ctl/bin/* |
91 |
| -ENV PATH="$PATH:$HOME/.pg_ctl/bin" |
92 |
| - |
93 |
| -### Clear caches |
94 |
| -RUN sudo apt-get clean && sudo rm -rf /var/cache/apt/* /var/lib/apt/lists/* /tmp/* |
95 |
| - |
96 |
| -### Setup service env vars |
| 42 | +RUN apt-get update -y \ |
| 43 | + && apt-get install -y \ |
| 44 | + curl \ |
| 45 | + jq \ |
| 46 | + && mkdir -p /out \ |
| 47 | + && git clone -b ${STACKS_NODE_VERSION} --depth 1 https://github.com/${STACKS_NODE_REPO} . \ |
| 48 | + && cd testnet/stacks-node \ |
| 49 | + && cargo build --features monitoring_prom,slog_json --release \ |
| 50 | + && cp /src/target/release/stacks-node /out |
| 51 | + |
| 52 | +####################################################################### |
| 53 | +## Build the final image with all components from build stages |
| 54 | +FROM debian:buster |
| 55 | +ARG STACKS_NETWORK |
| 56 | +ARG STACKS_LOG_DIR |
| 57 | +ARG STACKS_SVC_DIR |
| 58 | +ARG STACKS_BLOCKCHAIN_DIR |
| 59 | +ARG STACKS_BLOCKCHAIN_API_DIR |
| 60 | +ARG PG_DATA |
| 61 | +ARG PG_VERSION |
| 62 | +ARG V2_POX_MIN_AMOUNT_USTX |
97 | 63 | ENV PG_HOST=127.0.0.1
|
98 | 64 | ENV PG_PORT=5432
|
99 |
| -ENV PG_USER=stacky |
| 65 | +ENV PG_USER=postgres |
100 | 66 | ENV PG_PASSWORD=postgres
|
101 | 67 | ENV PG_DATABASE=postgres
|
102 |
| - |
| 68 | +ENV PG_DATA=${PG_DATA} |
| 69 | +ENV PG_VERSION=${PG_VERSION} |
| 70 | +ENV STACKS_SVC_DIR=${STACKS_SVC_DIR} |
| 71 | +ENV STACKS_BLOCKCHAIN_DIR=${STACKS_BLOCKCHAIN_DIR} |
| 72 | +ENV STACKS_BLOCKCHAIN_API_DIR=${STACKS_BLOCKCHAIN_API_DIR} |
| 73 | +ENV STACKS_NETWORK=${STACKS_NETWORK} |
| 74 | +ENV STACKS_LOG_DIR=${STACKS_LOG_DIR} |
103 | 75 | ENV STACKS_CORE_EVENT_PORT=3700
|
104 | 76 | ENV STACKS_CORE_EVENT_HOST=127.0.0.1
|
105 |
| -ENV STACKS_NETWORK=$STACKS_NETWORK |
106 |
| - |
107 | 77 | ENV STACKS_EVENT_OBSERVER=127.0.0.1:3700
|
108 |
| - |
109 | 78 | ENV STACKS_BLOCKCHAIN_API_PORT=3999
|
110 | 79 | ENV STACKS_BLOCKCHAIN_API_HOST=0.0.0.0
|
111 |
| - |
112 | 80 | ENV STACKS_CORE_RPC_HOST=127.0.0.1
|
113 | 81 | ENV STACKS_CORE_RPC_PORT=20443
|
114 |
| - |
115 |
| -### Startup script & coordinator |
116 |
| -RUN printf '#!/bin/bash\n\ |
117 |
| -trap "exit" INT TERM\n\ |
118 |
| -trap "kill 0" EXIT\n\ |
119 |
| -echo Your container args are: "$@"\n\ |
120 |
| -tail --retry -F stacks-api.log stacks-node.log 2>&1 &\n\ |
121 |
| -while true\n\ |
122 |
| -do\n\ |
123 |
| - pg_start\n\ |
124 |
| - stacks_api &> stacks-api.log &\n\ |
125 |
| - stacks_api_pid=$!\n\ |
126 |
| - if [ $STACKS_NETWORK = "mocknet" -o $STACKS_NETWORK = "dev" ]; then\n\ |
127 |
| - stacks-node start --config=/data/stacky/Stacks-${STACKS_NETWORK}.toml &> stacks-node.log &\n\ |
128 |
| - elif [ $STACKS_NETWORK = "testnet"]; then \n\ |
129 |
| - stacks-node start --config=/data/stacky/Stacks-mocknet.toml &> stacks-node.log &\n\ |
130 |
| - else\n\ |
131 |
| - stacks-node mainnet &> stacks-node.log &\n\ |
132 |
| - fi\n\ |
133 |
| - stacks_node_pid=$!\n\ |
134 |
| - wait $stacks_node_pid\n\ |
135 |
| - echo "node exit, restarting..."\n\ |
136 |
| - rkill -9 $stacks_api_pid\n\ |
137 |
| - pg_stop\n\ |
138 |
| - rm -rf $PGDATA\n\ |
139 |
| - sleep 5\n\ |
140 |
| -done\n\ |
141 |
| -' >> run.sh && chmod +x run.sh |
142 |
| - |
| 82 | +ENV MAINNET_STACKS_CHAIN_ID=0x00000001 |
| 83 | +ENV TESTNET_STACKS_CHAIN_ID=0x80000000 |
| 84 | +ENV V2_POX_MIN_AMOUNT_USTX=${V2_POX_MIN_AMOUNT_USTX} |
| 85 | +RUN apt-get update \ |
| 86 | + && apt install -y \ |
| 87 | + gnupg2 \ |
| 88 | + lsb-release \ |
| 89 | + curl procps \ |
| 90 | + netcat \ |
| 91 | + gosu \ |
| 92 | + runit-init \ |
| 93 | + rsyslog |
| 94 | +RUN curl -sL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ |
| 95 | + && echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" > /etc/apt/sources.list.d/pgsql.list \ |
| 96 | + && curl -sL https://deb.nodesource.com/setup_14.x | bash - |
| 97 | +RUN apt-get update \ |
| 98 | + && apt-get install -y \ |
| 99 | + postgresql-${PG_VERSION} \ |
| 100 | + postgresql-client-${PG_VERSION} \ |
| 101 | + nodejs \ |
| 102 | + && echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections |
| 103 | +RUN mkdir -p \ |
| 104 | + ${STACKS_SVC_DIR}/postgresql/log \ |
| 105 | + ${STACKS_SVC_DIR}/stacks-blockchain-api/log \ |
| 106 | + ${STACKS_SVC_DIR}/stacks-blockchain \ |
| 107 | + ${STACKS_LOG_DIR}/postgresql \ |
| 108 | + ${STACKS_LOG_DIR}/stacks-blockchain-api/log \ |
| 109 | + && apt-get clean \ |
| 110 | + && rm -rf /var/cache/apt/* /var/lib/apt/lists/* /tmp/* ${STACKS_SVC_DIR}/getty* |
| 111 | +COPY --from=stacks-blockchain-build /out ${STACKS_BLOCKCHAIN_DIR} |
| 112 | +COPY --from=stacks-blockchain-api-build /app ${STACKS_BLOCKCHAIN_API_DIR} |
| 113 | +RUN cp ${STACKS_BLOCKCHAIN_API_DIR}/stacks-blockchain/Stacks-mocknet.toml ${STACKS_BLOCKCHAIN_DIR}/Stacks-testnet.toml \ |
| 114 | + && cp ${STACKS_BLOCKCHAIN_API_DIR}/stacks-blockchain/Stacks-mocknet.toml ${STACKS_BLOCKCHAIN_DIR}/Stacks-mocknet.toml |
| 115 | + |
| 116 | +################################### |
| 117 | +## runit service files |
| 118 | +RUN printf '#!/bin/sh\nexec 2>&1\n[ ! -d %s ] && mkdir -p %s && chown -R postgres:postgres %s && gosu postgres /usr/lib/postgresql/%s/bin/pg_ctl init -D %s\nexec gosu postgres /usr/lib/postgresql/%s/bin/postmaster -D %s' ${PG_DATA} ${PG_DATA} ${PG_DATA} ${PG_VERSION} ${PG_DATA} ${PG_VERSION} ${PG_DATA} > ${STACKS_SVC_DIR}/postgresql/run \ |
| 119 | + && printf '#!/bin/sh\nrm -rf %s' ${PG_DATA} > ${STACKS_SVC_DIR}/postgresql/finish \ |
| 120 | + && printf '#!/bin/sh\nexec svlogd -tt %s/postgresql' ${STACKS_LOG_DIR} > ${STACKS_SVC_DIR}/postgresql/log/run \ |
| 121 | + && printf '#!/bin/sh\nexec 2>&1\nif [ $STACKS_NETWORK != "mainnet" ]; then\n exec %s/stacks-node start --config=%s/Stacks-testnet.toml 2>&1\nelse\n exec %s/stacks-node mainnet 2>&1\nfi' ${STACKS_BLOCKCHAIN_DIR} ${STACKS_BLOCKCHAIN_DIR} ${STACKS_BLOCKCHAIN_DIR} > ${STACKS_SVC_DIR}/stacks-blockchain/run \ |
| 122 | + && printf '#!/bin/bash\nexec 2>&1\nsv start postgresql stacks-blockchain || exit 1\nif [ $STACKS_NETWORK != "mainnet" ]; then\n export STACKS_CHAIN_ID=%s\nelse\n export STACKS_CHAIN_ID=%s\n export V2_POX_MIN_AMOUNT_USTX=%s\nfi\ncd %s && exec node ./lib/index.js 2>&1' ${TESTNET_STACKS_CHAIN_ID} ${MAINNET_STACKS_CHAIN_ID} ${V2_POX_MIN_AMOUNT_USTX} ${STACKS_BLOCKCHAIN_API_DIR} > ${STACKS_SVC_DIR}/stacks-blockchain-api/run \ |
| 123 | + && printf '#!/bin/sh\nexec svlogd -tt %s/stacks-blockchain-api' ${STACKS_LOG_DIR} > ${STACKS_SVC_DIR}/stacks-blockchain-api/log/run \ |
| 124 | + && printf '#!/bin/sh\n/usr/bin/runsvdir %s' ${STACKS_SVC_DIR} > /entrypoint.sh \ |
| 125 | + && chmod 755 \ |
| 126 | + ${STACKS_SVC_DIR}/postgresql/run \ |
| 127 | + ${STACKS_SVC_DIR}/postgresql/finish \ |
| 128 | + ${STACKS_SVC_DIR}/postgresql/log/run \ |
| 129 | + ${STACKS_SVC_DIR}/stacks-blockchain/run \ |
| 130 | + ${STACKS_SVC_DIR}/stacks-blockchain-api/run \ |
| 131 | + ${STACKS_SVC_DIR}/stacks-blockchain-api/log/run \ |
| 132 | + /entrypoint.sh |
| 133 | + |
| 134 | +EXPOSE ${STACKS_BLOCKCHAIN_API_PORT} ${STACKS_CORE_RPC_PORT} |
143 | 135 | VOLUME /data
|
144 |
| - |
145 |
| -ENTRYPOINT ["/data/stacky/run.sh"] |
146 |
| - |
147 |
| -CMD ["/data/stacky/run.sh"] |
| 136 | +ENTRYPOINT ["/entrypoint.sh"] |
0 commit comments