Skip to content

Commit

Permalink
feat: dockerfile for self-contained follower
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Aug 27, 2020
1 parent 66d64ed commit 9628148
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
56 changes: 43 additions & 13 deletions follower.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN curl -s "$ARTIFACTS" --output ./artifacts-resp.json \

FROM ubuntu:focal

ENV SHELL /bin/bash
SHELL ["/bin/bash", "-c"]

RUN apt-get update

Expand All @@ -38,8 +38,6 @@ RUN useradd -l -u 33333 -G sudo -md /home/stacky -s /bin/bash -p stacky stacky \
&& sed -i.bkp -e 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers
ENV HOME=/home/stacky
WORKDIR $HOME
# custom Bash prompt
# RUN { echo && echo "PS1='\[\e]0;\u \w\a\]\[\033[01;32m\]\u\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\] \\\$ '" ; } >> .bashrc

### stacky user (2) ###
USER stacky
Expand All @@ -61,14 +59,16 @@ ENV PATH=$PATH:/home/stacky/.nvm/versions/node/v${NODE_VERSION}/bin
RUN node -e 'console.log("Node.js runs")'

### Setup stacks-node
COPY --from=stacks-node-build /stacks-node stacks-node
COPY --from=stacks-node-build /stacks-node stacks-node/
ENV PATH="$PATH:$HOME/stacks-node"

### Setup stacks-blockchain-api
COPY --from=build /app stacks-blockchain-api
RUN sudo chown -Rh stacky:stacky stacks-blockchain-api
RUN printf '#!/bin/bash\ncd $(dirname $0)\nnpm run start\n' > stacks-blockchain-api/start \
&& chmod +x stacks-blockchain-api/start

RUN printf '#!/bin/bash\ncd $(dirname $0)\nnpm run start\n' > stacks-blockchain-api/stacks_api \
&& chmod +x stacks-blockchain-api/stacks_api
ENV PATH="$PATH:$HOME/stacks-blockchain-api"
EXPOSE 3999

### Install Postgres
RUN sudo apt-get install -y postgresql-12 postgresql-contrib-12
Expand All @@ -86,10 +86,40 @@ ENV DATABASE_URL="postgresql://stacky@localhost"
ENV PGHOSTADDR="127.0.0.1"
ENV PGDATABASE="postgres"

# This is a bit of a hack. At the moment we have no means of starting background
# tasks from a Dockerfile. This workaround checks, on each bashrc eval, if the
# PostgreSQL server is running, and if not starts it.
RUN printf "\n# Auto-start PostgreSQL server.\n[[ \$(pg_ctl status | grep PID) ]] || pg_start > /dev/null\n" >> ~/.bashrc



### Setup service env vars
ENV PG_HOST=127.0.0.1
ENV PG_PORT=5432
ENV PG_USER=stacky
ENV PG_PASSWORD=postgres
ENV PG_DATABASE=postgres

ENV STACKS_CORE_EVENT_PORT=3700
ENV STACKS_CORE_EVENT_HOST=127.0.0.1

ENV STACKS_BLOCKCHAIN_API_PORT=3999
ENV STACKS_BLOCKCHAIN_API_HOST=127.0.0.1

ENV STACKS_CORE_RPC_HOST=127.0.0.1
ENV STACKS_CORE_RPC_PORT=20443


RUN printf '#!/bin/bash\n\
tail --retry -F stacks-api.log stacks-node.log 2>&1 &\n\
while true\n\
do\n\
pg_start\n\
stacks_api &> stacks-api.log &\n\
stacks_api_pid=$!\n\
stacks-node argon &> stacks-node.log &\n\
stacks_node_pid=$!\n\
wait $stacks_node_pid\n\
echo "node exit, restarting..."\n\
kill -9 $stacks_api_pid\n\
pg_stop\n\
rm -rf $PGDATA\n\
sleep 5\n\
done\n\
' >> run.sh && chmod +x run.sh

CMD ["/home/stacky/run.sh"]
2 changes: 1 addition & 1 deletion src/datastore/postgres-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte
} finally {
client.end(() => {});
}
} while (initTimer.getElapsed() < 10000);
} while (initTimer.getElapsed() < 30000);
if (!connectionOkay) {
connectionError = connectionError ?? new Error('Error connecting to database');
throw connectionError;
Expand Down

0 comments on commit 9628148

Please sign in to comment.