-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating rosetta dockerfile #563
Conversation
- Refactoring to use runit vs custom script - clone the latest releases vs static versions
Codecov Report
@@ Coverage Diff @@
## master #563 +/- ##
==========================================
+ Coverage 65.14% 66.89% +1.75%
==========================================
Files 59 76 +17
Lines 4963 8407 +3444
Branches 856 1494 +638
==========================================
+ Hits 3233 5624 +2391
- Misses 1729 2781 +1052
- Partials 1 2 +1
Continue to review full report at Codecov.
|
ping @zone117x |
stx-rosetta.Dockerfile
Outdated
|
||
ENV MAINNET_STACKS_CHAIN_ID=0x00000001 | ||
ENV TESTNET_STACKS_CHAIN_ID=0x80000000 | ||
ENV V2_POX_MIN_AMOUNT_USTX=90000000260 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is handled automatically now. @zone117x can you confirm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this env var is no longer used anywhere.
## Build the stacks-blockchain-api | ||
FROM node:lts-buster as stacks-blockchain-api-build | ||
ARG STACKS_API_REPO=blockstack/stacks-blockchain-api | ||
ENV STACKS_API_REPO=${STACKS_API_REPO} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this ENV var can be removed. ${STACKS_API_REPO}
will just use the ARG
like it's an ENV var. The ENV var directive should be used when the env variable needs to be available in the resulting image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless the repo name changes, in which case this is a single change or a build-arg vs multiple changes in the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm saying you can delete just this ENV var and the image will work the same as it did before. There's no benefit to declaring an ARG then setting an ENV var to it if the env var won't be used in the final image because it's redundant. If the repo name changes, you'd update the ARG default value.
stx-rosetta.Dockerfile
Outdated
ENV PG_DATA=${PG_DATA} | ||
ENV PG_VERSION=${PG_VERSION} | ||
ENV STACKS_SVC_DIR=${STACKS_SVC_DIR} | ||
ENV STACKS_BLOCKCHAIN_DIR=${STACKS_BLOCKCHAIN_DIR} | ||
ENV STACKS_BLOCKCHAIN_API_DIR=${STACKS_BLOCKCHAIN_API_DIR} | ||
ENV STACKS_NETWORK=${STACKS_NETWORK} | ||
ENV STACKS_LOG_DIR=${STACKS_LOG_DIR} | ||
ENV STACKS_CORE_EVENT_PORT=3700 | ||
ENV STACKS_CORE_EVENT_HOST=127.0.0.1 | ||
ENV STACKS_NETWORK=$STACKS_NETWORK | ||
|
||
ENV STACKS_EVENT_OBSERVER=127.0.0.1:3700 | ||
|
||
ENV STACKS_BLOCKCHAIN_API_PORT=3999 | ||
ENV STACKS_BLOCKCHAIN_API_HOST=0.0.0.0 | ||
|
||
ENV STACKS_CORE_RPC_HOST=127.0.0.1 | ||
ENV STACKS_CORE_RPC_PORT=20443 | ||
|
||
### Startup script & coordinator | ||
RUN printf '#!/bin/bash\n\ | ||
trap "exit" INT TERM\n\ | ||
trap "kill 0" EXIT\n\ | ||
echo Your container args are: "$@"\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\ | ||
if [ $STACKS_NETWORK = "mocknet" -o $STACKS_NETWORK = "dev" ]; then\n\ | ||
stacks-node start --config=/data/stacky/Stacks-${STACKS_NETWORK}.toml &> stacks-node.log &\n\ | ||
elif [ $STACKS_NETWORK = "testnet"]; then \n\ | ||
stacks-node start --config=/data/stacky/Stacks-mocknet.toml &> stacks-node.log &\n\ | ||
else\n\ | ||
stacks-node mainnet &> stacks-node.log &\n\ | ||
fi\n\ | ||
stacks_node_pid=$!\n\ | ||
wait $stacks_node_pid\n\ | ||
echo "node exit, restarting..."\n\ | ||
rkill -9 $stacks_api_pid\n\ | ||
pg_stop\n\ | ||
rm -rf $PGDATA\n\ | ||
sleep 5\n\ | ||
done\n\ | ||
' >> run.sh && chmod +x run.sh | ||
|
||
ENV MAINNET_STACKS_CHAIN_ID=0x00000001 | ||
ENV TESTNET_STACKS_CHAIN_ID=0x80000000 | ||
ENV V2_POX_MIN_AMOUNT_USTX=90000000260 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we combine all of these ENV
directives into one directive? It'll result in fewer layers in the image and decrease its size. Also if any of them aren't used in the final image's runtime, you can just use their ARG
counterpart due to the same reason in my other comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but it would also be incredibly hard to read. the goal here isn't a small image
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine if you want to keep it that way, I don't find it difficult to read with one directive. Also it seems ENV
directives don't create additional layers anymore either which is nice.
|
||
################################### | ||
## runit service files | ||
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 \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered committing the ruinit service files to this repo, and COPY
ing them into the image? Might be easier to maintain and read that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible, sure - but changes to the repo would require a full rebuild since the cache layers would no longer be used.
Since there are many parts of this process, the goal was to create an image that can be built using cache layers as quickly as is feasible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but changes to the repo would require a full rebuild since the cache layers would no longer be used.
If you COPY
only those ruinit files, changes to the repo wouldn't require a full rebuild. That only happens when you write COPY . .
for example. Either way will work the same, it's just difficult to read or maintain the scripts when they're embedded.
ENV MAINNET_STACKS_CHAIN_ID=0x00000001 | ||
ENV TESTNET_STACKS_CHAIN_ID=0x80000000 | ||
ENV V2_POX_MIN_AMOUNT_USTX=90000000260 | ||
RUN apt-get update \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combining this RUN
command with the following three will further decrease the number of layers and size of the resulting image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above - any change in the process/dockerfile would invalidate the cache layers and cause a longer rebuild.
Can they all be combined? yes - iniitially that's what i was doing. but any small change required a full rebuild vs updating a single layer or two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any change in the process/dockerfile would invalidate the cache layers and cause a longer rebuild.
Only true if you COPY
the dockerfile into the image. For RUN
directives the docker engine only compares the text of the old RUN
vs the text of the new RUN
to determine if it can be reused from cache. So if there's a change in the command, it won't use the cache either way you configure it. These are only minor suggestions, so feel free to do what you like.
ping @zone117x |
Thanks @wileyj this looks good to me. Do you think we should merge this to master now, or wait until we merge API develop branch to master? |
Up to you! I've shared the file from my branch with the folks who needed it, so there's no rush - pinging just to get it off my plate. |
Alright, there could be some changes required once develop branch is ready, and that's expected this week. So I think holding off until then makes sense. |
👍 changed the base branch to |
ping @zone117x |
@wileyj the only concern I have about this PR is the move away from pinned versions (of the stacks-node repo at least). I do think this dockerfile change is a step in the right direction, because the hardcoded versions tend to go stale. Should we merge this PR with the possibility that this dockerfile could build images with stacks-api and stacks-node versions that are incompatible with each other (when the release cadences don't match up)? |
Interesting...I don't have any opinion directly on that discussion, but also - nothing prevents us from setting specific versions in the Dockerfile vs trying to dynamically retrieve the version through github api. The reason I made the Dockerfile this way was to prevent having to manually update the version numbers each time a Based on the discussion you linked, is there a pair of versions you'd like to start with initially? Once I have the specific versions I can update the Dockerfile and we can get this off of our plate. |
Yes these would be good versions to set the dockerfile to for now 👍
Yeah, this is definitely a pain, hopefully something we can figure out in #567 eventually. |
hardcoding versions little bit of cleanup
Updated to use hardcoded versions! |
🎉 This PR is included in version 0.59.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
This change refactors the rosetta Dockerfile to use runit as a scheduler vs a customized shell script. This change was motivated by discussions with another team trying to use this Dockerfile, and realizing the static version was very out of date. Further work was added to standardize the Dockerfile, so there weren't things like custom users/scripts (particularly in the case of postgresql).
The builder images are also refactored to more closely resemble the default Dockerfiles, as well as cloning the latest release for each of
stacks-blockchain-api
andstacks-blockchain
repos.Other changes are more use of ARG and ENV variables to create the scripts, i.e.
Type of Change