From 970211f9ad707f3e61d5bdb456d1c9b917f90c0b Mon Sep 17 00:00:00 2001 From: sevenrats Date: Wed, 28 Dec 2022 12:03:21 -0500 Subject: [PATCH 1/4] improve dockerfiles --- .dockerignore | 2 +- Dockerfile.latest | 32 +++++++++++++++----------------- Dockerfile.next | 34 ++++++++++++++++------------------ entrypoint.sh | 20 ++++++++++++++++++++ 4 files changed, 52 insertions(+), 36 deletions(-) create mode 100755 entrypoint.sh diff --git a/.dockerignore b/.dockerignore index 241e560df6..864179fda5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,2 @@ * - +!entrypoint.sh diff --git a/Dockerfile.latest b/Dockerfile.latest index 9d349c5dc1..4f33b363b0 100644 --- a/Dockerfile.latest +++ b/Dockerfile.latest @@ -5,26 +5,24 @@ ENV IPFS_MONITORING=1 ENV IPFS_PATH=/root/.jsipfs ENV BUILD_DEPS='libnspr4 libnspr4-dev libnss3' -RUN apk add --no-cache git python3 build-base - -# Hopefully remove when https://github.com/node-webrtc/node-webrtc/pull/694 is merged -RUN npm install -g ipfs@"$IPFS_VERSION" - -# Make the image a bit smaller -RUN npm cache clear --force -RUN apk del build-base python3 git - -# Configure jsipfs -RUN jsipfs init - -RUN jsipfs version - -# Allow connections from any host -RUN sed -i.bak "s/127.0.0.1/0.0.0.0/g" $IPFS_PATH/config +RUN \ + apk add --no-cache catatonit bash procps nodejs npm \ + build-base python3 && \ + npm install -g --build-from-source ipfs@"$IPFS_VERSION" && \ + npm cache clear --force && \ + apk del build-base python3 make npm && \ + rm -rf /node-* /SHASUMS256.txt /tmp/* /root/.electron /root/.cache \ + /sbin/apk /etc/apk /lib/apk /usr/share/apk /var/lib/apk \ + /usr/share/man/* /usr/share/doc /root/.npm /root/.node-gyp /root/.config \ + /usr/lib/node_modules/npm/man /usr/lib/node_modules/npm/doc /usr/lib/node_modules/npm/docs \ + /usr/lib/node_modules/npm/html /usr/lib/node_modules/npm/scripts && \ + { rm -rf /root/.gnupg || true; } EXPOSE 4002 EXPOSE 4003 EXPOSE 5002 EXPOSE 9090 -CMD jsipfs daemon +COPY entrypoint.sh /entrypoint.sh + +CMD ["catatonit", "/entrypoint.sh"] diff --git a/Dockerfile.next b/Dockerfile.next index 966979cf03..fcf2200947 100644 --- a/Dockerfile.next +++ b/Dockerfile.next @@ -1,30 +1,28 @@ -FROM node:16-alpine +FROM alpine ENV IPFS_VERSION=next ENV IPFS_MONITORING=1 ENV IPFS_PATH=/root/.jsipfs ENV BUILD_DEPS='libnspr4 libnspr4-dev libnss3' -RUN apk add --no-cache git python3 build-base - -# Hopefully remove when https://github.com/node-webrtc/node-webrtc/pull/694 is merged -RUN npm install -g ipfs@"$IPFS_VERSION" - -# Make the image a bit smaller -RUN npm cache clear --force -RUN apk del build-base python3 git - -# Configure jsipfs -RUN jsipfs init - -RUN jsipfs version - -# Allow connections from any host -RUN sed -i.bak "s/127.0.0.1/0.0.0.0/g" $IPFS_PATH/config +RUN \ + apk add --no-cache catatonit bash procps nodejs npm \ + build-base python3 && \ + npm install -g --build-from-source ipfs@"$IPFS_VERSION" && \ + npm cache clear --force && \ + apk del build-base python3 make npm && \ + rm -rf /node-* /SHASUMS256.txt /tmp/* /root/.electron /root/.cache \ + /sbin/apk /etc/apk /lib/apk /usr/share/apk /var/lib/apk \ + /usr/share/man/* /usr/share/doc /root/.npm /root/.node-gyp /root/.config \ + /usr/lib/node_modules/npm/man /usr/lib/node_modules/npm/doc /usr/lib/node_modules/npm/docs \ + /usr/lib/node_modules/npm/html /usr/lib/node_modules/npm/scripts && \ + { rm -rf /root/.gnupg || true; } EXPOSE 4002 EXPOSE 4003 EXPOSE 5002 EXPOSE 9090 -CMD jsipfs daemon +COPY entrypoint.sh /entrypoint.sh + +CMD ["catatonit", "/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000000..ac9f718f64 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Proxy signals +_term() { + echo "Caught SIGTERM signal!" + pkill -TERM jsipfs + pkill -TERM -P1 + exit 0 +} + +trap _term SIGTERM + +export IPFS_PATH=$IPFS_PATH + +if ! [[ -f "$IPFS_PATH" ]]; then + jsipfs init +fi + +jsipfs daemon & +wait -n ${!} \ No newline at end of file From fcd83bf0b9b4d10fd5c387cfb4c801c599e7552d Mon Sep 17 00:00:00 2001 From: sevenrats Date: Sat, 7 Jan 2023 20:59:12 -0500 Subject: [PATCH 2/4] correct FROM tag in latest --- Dockerfile.latest | 2 +- Dockerfile.next | 2 +- entrypoint.sh | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile.latest b/Dockerfile.latest index 4f33b363b0..a6c4bab5f9 100644 --- a/Dockerfile.latest +++ b/Dockerfile.latest @@ -1,4 +1,4 @@ -FROM node:16-alpine +FROM alpine:3.17 ENV IPFS_VERSION=latest ENV IPFS_MONITORING=1 diff --git a/Dockerfile.next b/Dockerfile.next index fcf2200947..521275a725 100644 --- a/Dockerfile.next +++ b/Dockerfile.next @@ -1,4 +1,4 @@ -FROM alpine +FROM alpine:3.17 ENV IPFS_VERSION=next ENV IPFS_MONITORING=1 diff --git a/entrypoint.sh b/entrypoint.sh index ac9f718f64..e411f21166 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,5 +16,5 @@ if ! [[ -f "$IPFS_PATH" ]]; then jsipfs init fi -jsipfs daemon & -wait -n ${!} \ No newline at end of file +jsipfs daemon & \ +wait -n From 05cc62075f80cbb1fc0470cf31a185c7ebecfb6e Mon Sep 17 00:00:00 2001 From: sevenrats Date: Sat, 7 Jan 2023 21:17:13 -0500 Subject: [PATCH 3/4] no need to manually proxy signals --- Dockerfile.latest | 2 +- Dockerfile.next | 2 +- entrypoint.sh | 12 ------------ 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/Dockerfile.latest b/Dockerfile.latest index a6c4bab5f9..9737439c5e 100644 --- a/Dockerfile.latest +++ b/Dockerfile.latest @@ -25,4 +25,4 @@ EXPOSE 9090 COPY entrypoint.sh /entrypoint.sh -CMD ["catatonit", "/entrypoint.sh"] +CMD ["catatonit", "-g", "/entrypoint.sh"] diff --git a/Dockerfile.next b/Dockerfile.next index 521275a725..504f244088 100644 --- a/Dockerfile.next +++ b/Dockerfile.next @@ -25,4 +25,4 @@ EXPOSE 9090 COPY entrypoint.sh /entrypoint.sh -CMD ["catatonit", "/entrypoint.sh"] +CMD ["catatonit", "-g", "/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh index e411f21166..9452757a9e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,17 +1,5 @@ #!/usr/bin/env bash -# Proxy signals -_term() { - echo "Caught SIGTERM signal!" - pkill -TERM jsipfs - pkill -TERM -P1 - exit 0 -} - -trap _term SIGTERM - -export IPFS_PATH=$IPFS_PATH - if ! [[ -f "$IPFS_PATH" ]]; then jsipfs init fi From d324a3208e5bb5157d1616efda9fe5be04c2c42a Mon Sep 17 00:00:00 2001 From: sevenrats Date: Sat, 7 Jan 2023 22:47:26 -0500 Subject: [PATCH 4/4] handle stale repo locks --- Dockerfile.latest | 7 +++---- Dockerfile.next | 7 +++---- entrypoint.sh | 4 ++++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Dockerfile.latest b/Dockerfile.latest index 9737439c5e..32173f8fe4 100644 --- a/Dockerfile.latest +++ b/Dockerfile.latest @@ -3,14 +3,13 @@ FROM alpine:3.17 ENV IPFS_VERSION=latest ENV IPFS_MONITORING=1 ENV IPFS_PATH=/root/.jsipfs -ENV BUILD_DEPS='libnspr4 libnspr4-dev libnss3' RUN \ - apk add --no-cache catatonit bash procps nodejs npm \ - build-base python3 && \ + apk add --no-cache catatonit bash procps nodejs && \ + apk add --no-cache --virtual .build-deps npm git build-base python3 && \ npm install -g --build-from-source ipfs@"$IPFS_VERSION" && \ npm cache clear --force && \ - apk del build-base python3 make npm && \ + apk del .build-deps && \ rm -rf /node-* /SHASUMS256.txt /tmp/* /root/.electron /root/.cache \ /sbin/apk /etc/apk /lib/apk /usr/share/apk /var/lib/apk \ /usr/share/man/* /usr/share/doc /root/.npm /root/.node-gyp /root/.config \ diff --git a/Dockerfile.next b/Dockerfile.next index 504f244088..a642c859c3 100644 --- a/Dockerfile.next +++ b/Dockerfile.next @@ -3,14 +3,13 @@ FROM alpine:3.17 ENV IPFS_VERSION=next ENV IPFS_MONITORING=1 ENV IPFS_PATH=/root/.jsipfs -ENV BUILD_DEPS='libnspr4 libnspr4-dev libnss3' RUN \ - apk add --no-cache catatonit bash procps nodejs npm \ - build-base python3 && \ + apk add --no-cache catatonit bash procps nodejs && \ + apk add --no-cache --virtual .build-deps npm git build-base python3 && \ npm install -g --build-from-source ipfs@"$IPFS_VERSION" && \ npm cache clear --force && \ - apk del build-base python3 make npm && \ + apk del .build-deps && \ rm -rf /node-* /SHASUMS256.txt /tmp/* /root/.electron /root/.cache \ /sbin/apk /etc/apk /lib/apk /usr/share/apk /var/lib/apk \ /usr/share/man/* /usr/share/doc /root/.npm /root/.node-gyp /root/.config \ diff --git a/entrypoint.sh b/entrypoint.sh index 9452757a9e..98156831e4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,8 @@ #!/usr/bin/env bash +if [[ -d "$IPFS_PATH/repo.lock" ]]; then + echo "Automatically removing a stale repo lock." + rm -rf $IPFS_PATH/repo.lock +fi if ! [[ -f "$IPFS_PATH" ]]; then jsipfs init