From 4aeee37a88b4d7bb114f254ea24b0cc0cbfc6a80 Mon Sep 17 00:00:00 2001 From: Danilo Tuler Date: Wed, 26 Apr 2023 10:27:19 -0300 Subject: [PATCH] feat: add ubuntu riscv64 builds by cartesi --- 18/jammy-slim/Dockerfile | 102 +++++++++++++++++++++++++++++ 18/jammy-slim/docker-entrypoint.sh | 11 ++++ 18/jammy/Dockerfile | 76 +++++++++++++++++++++ 18/jammy/docker-entrypoint.sh | 11 ++++ 20/jammy-slim/Dockerfile | 102 +++++++++++++++++++++++++++++ 20/jammy-slim/docker-entrypoint.sh | 11 ++++ 20/jammy/Dockerfile | 76 +++++++++++++++++++++ 20/jammy/docker-entrypoint.sh | 11 ++++ Dockerfile-ubuntu-slim.template | 91 +++++++++++++++++++++++++ Dockerfile-ubuntu.template | 65 ++++++++++++++++++ README.md | 7 ++ UBUNTU-NOTES.md | 35 ++++++++++ architectures | 1 + config | 1 + docker-bake.hcl | 72 ++++++++++++++++++++ functions.sh | 31 +++++++++ update.sh | 9 +++ versions.json | 12 ++++ 18 files changed, 724 insertions(+) create mode 100644 18/jammy-slim/Dockerfile create mode 100755 18/jammy-slim/docker-entrypoint.sh create mode 100644 18/jammy/Dockerfile create mode 100755 18/jammy/docker-entrypoint.sh create mode 100644 20/jammy-slim/Dockerfile create mode 100755 20/jammy-slim/docker-entrypoint.sh create mode 100644 20/jammy/Dockerfile create mode 100755 20/jammy/docker-entrypoint.sh create mode 100644 Dockerfile-ubuntu-slim.template create mode 100644 Dockerfile-ubuntu.template create mode 100644 UBUNTU-NOTES.md create mode 100644 docker-bake.hcl diff --git a/18/jammy-slim/Dockerfile b/18/jammy-slim/Dockerfile new file mode 100644 index 000000000..3cf6c0599 --- /dev/null +++ b/18/jammy-slim/Dockerfile @@ -0,0 +1,102 @@ +FROM riscv64/ubuntu:jammy-slim + +RUN groupadd --gid 1000 node \ + && useradd --uid 1000 --gid node --shell /bin/bash --create-home node + +ENV NODE_VERSION 18.20.4 + +RUN ARCH= OPENSSL_ARCH= && dpkgArch="$(dpkg --print-architecture)" \ + && case "${dpkgArch##*-}" in \ + amd64) ARCH='x64' OPENSSL_ARCH='linux-x86_64';; \ + ppc64el) ARCH='ppc64le' OPENSSL_ARCH='linux-ppc64le';; \ + s390x) ARCH='s390x' OPENSSL_ARCH='linux*-s390x';; \ + arm64) ARCH='arm64' OPENSSL_ARCH='linux-aarch64';; \ + armhf) ARCH='armv7l' OPENSSL_ARCH='linux-armv4';; \ + i386) ARCH='x86' OPENSSL_ARCH='linux-elf';; \ + riscv64) ARCH='riscv64' OPENSSL_ARCH='linux-elf';; \ + *) echo "unsupported architecture"; exit 1 ;; \ + esac \ + && set -ex \ + # libatomic1 for arm + && apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr xz-utils libatomic1 --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* \ + && for key in \ + 4ED778F539E3634C779C87C6D7062848A1AB005C \ + 141F07595B7B3FFE74309A937405533BE57C7D57 \ + 74F12602B6F1C4E913FAA37AD3A89613643B6201 \ + DD792F5973C6DE52C432CBDAC77ABFA00DDBF2B7 \ + 61FC681DFB92A079F1685E77973F295594EC4689 \ + 8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \ + C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ + 890C08DB8579162FEE0DF9DB8BEAB4DFCF555EF4 \ + C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C \ + 108F52B48DB57BB0CC439B2997B01419BD92F80A \ + A363A499291CBBC940DD62E41F10027AF002F8B0 \ + CC68F5A3106FF448322E48ED27F5E38D5B0A215F \ + ; do \ + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \ + done \ + && curl -fsSLO --compressed "https://github.com/cartesi/unofficial-builds/releases/download/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \ + && gpgconf --kill all \ + && rm -rf "$GNUPGHOME" \ + && tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \ + && rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" \ + # Remove unused OpenSSL headers to save ~34MB. See this NodeJS issue: https://github.com/nodejs/node/issues/46451 + && find /usr/local/include/node/openssl/archs -mindepth 1 -maxdepth 1 ! -name "$OPENSSL_ARCH" -exec rm -rf {} \; \ + && apt-mark auto '.*' > /dev/null \ + && find /usr/local -type f -executable -exec ldd '{}' ';' \ + | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \ + | sort -u \ + | xargs -r dpkg-query --search \ + | cut -d: -f1 \ + | sort -u \ + | xargs -r apt-mark manual \ + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ + && ln -s /usr/local/bin/node /usr/local/bin/nodejs \ + # smoke tests + && node --version \ + && npm --version + +ENV YARN_VERSION 1.22.22 + +RUN set -ex \ + && savedAptMark="$(apt-mark showmanual)" \ + && apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* \ + # use pre-existing gpg directory, see https://github.com/nodejs/docker-node/pull/1895#issuecomment-1550389150 + && export GNUPGHOME="$(mktemp -d)" \ + && for key in \ + 6A010C5166006599AA17F08146C2130DFD2497F5 \ + ; do \ + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \ + done \ + && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \ + && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \ + && gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ + && gpgconf --kill all \ + && rm -rf "$GNUPGHOME" \ + && mkdir -p /opt \ + && tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \ + && ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \ + && ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \ + && rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ + && apt-mark auto '.*' > /dev/null \ + && { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; } \ + && find /usr/local -type f -executable -exec ldd '{}' ';' \ + | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \ + | sort -u \ + | xargs -r dpkg-query --search \ + | cut -d: -f1 \ + | sort -u \ + | xargs -r apt-mark manual \ + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ + # smoke test + && yarn --version \ + && rm -rf /tmp/* + +COPY docker-entrypoint.sh /usr/local/bin/ +ENTRYPOINT ["docker-entrypoint.sh"] + +CMD [ "node" ] diff --git a/18/jammy-slim/docker-entrypoint.sh b/18/jammy-slim/docker-entrypoint.sh new file mode 100755 index 000000000..1b3116e53 --- /dev/null +++ b/18/jammy-slim/docker-entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e + +# Run command with node if the first argument contains a "-" or is not a system command. The last +# part inside the "{}" is a workaround for the following bug in ash/dash: +# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=874264 +if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ] || { [ -f "${1}" ] && ! [ -x "${1}" ]; }; then + set -- node "$@" +fi + +exec "$@" diff --git a/18/jammy/Dockerfile b/18/jammy/Dockerfile new file mode 100644 index 000000000..c8983d143 --- /dev/null +++ b/18/jammy/Dockerfile @@ -0,0 +1,76 @@ +FROM riscv64/buildpack-deps:jammy + +RUN groupadd --gid 1000 node \ + && useradd --uid 1000 --gid node --shell /bin/bash --create-home node + +ENV NODE_VERSION 18.20.4 + +RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \ + && case "${dpkgArch##*-}" in \ + amd64) ARCH='x64';; \ + ppc64el) ARCH='ppc64le';; \ + s390x) ARCH='s390x';; \ + arm64) ARCH='arm64';; \ + armhf) ARCH='armv7l';; \ + i386) ARCH='x86';; \ + riscv64) ARCH='riscv64';; \ + *) echo "unsupported architecture"; exit 1 ;; \ + esac \ + # use pre-existing gpg directory, see https://github.com/nodejs/docker-node/pull/1895#issuecomment-1550389150 + && export GNUPGHOME="$(mktemp -d)" \ + # gpg keys listed at https://github.com/nodejs/node#release-keys + && set -ex \ + && for key in \ + 4ED778F539E3634C779C87C6D7062848A1AB005C \ + 141F07595B7B3FFE74309A937405533BE57C7D57 \ + 74F12602B6F1C4E913FAA37AD3A89613643B6201 \ + DD792F5973C6DE52C432CBDAC77ABFA00DDBF2B7 \ + 61FC681DFB92A079F1685E77973F295594EC4689 \ + 8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \ + C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ + 890C08DB8579162FEE0DF9DB8BEAB4DFCF555EF4 \ + C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C \ + 108F52B48DB57BB0CC439B2997B01419BD92F80A \ + A363A499291CBBC940DD62E41F10027AF002F8B0 \ + CC68F5A3106FF448322E48ED27F5E38D5B0A215F \ + ; do \ + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \ + done \ + && curl -fsSLO --compressed "https://github.com/cartesi/unofficial-builds/releases/download/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \ + && tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \ + && rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" \ + && ln -s /usr/local/bin/node /usr/local/bin/nodejs \ + # smoke tests + && node --version \ + && npm --version + +ENV YARN_VERSION 1.22.22 + +RUN set -ex \ + # use pre-existing gpg directory, see https://github.com/nodejs/docker-node/pull/1895#issuecomment-1550389150 + && export GNUPGHOME="$(mktemp -d)" \ + && for key in \ + 6A010C5166006599AA17F08146C2130DFD2497F5 \ + ; do \ + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \ + done \ + && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \ + && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \ + && gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ + && gpgconf --kill all \ + && rm -rf "$GNUPGHOME" \ + && mkdir -p /opt \ + && tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \ + && ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \ + && ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \ + && rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ + # smoke test + && yarn --version \ + && rm -rf /tmp/* + +COPY docker-entrypoint.sh /usr/local/bin/ +ENTRYPOINT ["docker-entrypoint.sh"] + +CMD [ "node" ] diff --git a/18/jammy/docker-entrypoint.sh b/18/jammy/docker-entrypoint.sh new file mode 100755 index 000000000..1b3116e53 --- /dev/null +++ b/18/jammy/docker-entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e + +# Run command with node if the first argument contains a "-" or is not a system command. The last +# part inside the "{}" is a workaround for the following bug in ash/dash: +# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=874264 +if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ] || { [ -f "${1}" ] && ! [ -x "${1}" ]; }; then + set -- node "$@" +fi + +exec "$@" diff --git a/20/jammy-slim/Dockerfile b/20/jammy-slim/Dockerfile new file mode 100644 index 000000000..2d21e7ca6 --- /dev/null +++ b/20/jammy-slim/Dockerfile @@ -0,0 +1,102 @@ +FROM riscv64/ubuntu:jammy-slim + +RUN groupadd --gid 1000 node \ + && useradd --uid 1000 --gid node --shell /bin/bash --create-home node + +ENV NODE_VERSION 20.16.0 + +RUN ARCH= OPENSSL_ARCH= && dpkgArch="$(dpkg --print-architecture)" \ + && case "${dpkgArch##*-}" in \ + amd64) ARCH='x64' OPENSSL_ARCH='linux-x86_64';; \ + ppc64el) ARCH='ppc64le' OPENSSL_ARCH='linux-ppc64le';; \ + s390x) ARCH='s390x' OPENSSL_ARCH='linux*-s390x';; \ + arm64) ARCH='arm64' OPENSSL_ARCH='linux-aarch64';; \ + armhf) ARCH='armv7l' OPENSSL_ARCH='linux-armv4';; \ + i386) ARCH='x86' OPENSSL_ARCH='linux-elf';; \ + riscv64) ARCH='riscv64' OPENSSL_ARCH='linux-elf';; \ + *) echo "unsupported architecture"; exit 1 ;; \ + esac \ + && set -ex \ + # libatomic1 for arm + && apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr xz-utils libatomic1 --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* \ + && for key in \ + 4ED778F539E3634C779C87C6D7062848A1AB005C \ + 141F07595B7B3FFE74309A937405533BE57C7D57 \ + 74F12602B6F1C4E913FAA37AD3A89613643B6201 \ + DD792F5973C6DE52C432CBDAC77ABFA00DDBF2B7 \ + 61FC681DFB92A079F1685E77973F295594EC4689 \ + 8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \ + C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ + 890C08DB8579162FEE0DF9DB8BEAB4DFCF555EF4 \ + C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C \ + 108F52B48DB57BB0CC439B2997B01419BD92F80A \ + A363A499291CBBC940DD62E41F10027AF002F8B0 \ + CC68F5A3106FF448322E48ED27F5E38D5B0A215F \ + ; do \ + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \ + done \ + && curl -fsSLO --compressed "https://github.com/cartesi/unofficial-builds/releases/download/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \ + && gpgconf --kill all \ + && rm -rf "$GNUPGHOME" \ + && tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \ + && rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" \ + # Remove unused OpenSSL headers to save ~34MB. See this NodeJS issue: https://github.com/nodejs/node/issues/46451 + && find /usr/local/include/node/openssl/archs -mindepth 1 -maxdepth 1 ! -name "$OPENSSL_ARCH" -exec rm -rf {} \; \ + && apt-mark auto '.*' > /dev/null \ + && find /usr/local -type f -executable -exec ldd '{}' ';' \ + | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \ + | sort -u \ + | xargs -r dpkg-query --search \ + | cut -d: -f1 \ + | sort -u \ + | xargs -r apt-mark manual \ + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ + && ln -s /usr/local/bin/node /usr/local/bin/nodejs \ + # smoke tests + && node --version \ + && npm --version + +ENV YARN_VERSION 1.22.22 + +RUN set -ex \ + && savedAptMark="$(apt-mark showmanual)" \ + && apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* \ + # use pre-existing gpg directory, see https://github.com/nodejs/docker-node/pull/1895#issuecomment-1550389150 + && export GNUPGHOME="$(mktemp -d)" \ + && for key in \ + 6A010C5166006599AA17F08146C2130DFD2497F5 \ + ; do \ + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \ + done \ + && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \ + && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \ + && gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ + && gpgconf --kill all \ + && rm -rf "$GNUPGHOME" \ + && mkdir -p /opt \ + && tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \ + && ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \ + && ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \ + && rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ + && apt-mark auto '.*' > /dev/null \ + && { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; } \ + && find /usr/local -type f -executable -exec ldd '{}' ';' \ + | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \ + | sort -u \ + | xargs -r dpkg-query --search \ + | cut -d: -f1 \ + | sort -u \ + | xargs -r apt-mark manual \ + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ + # smoke test + && yarn --version \ + && rm -rf /tmp/* + +COPY docker-entrypoint.sh /usr/local/bin/ +ENTRYPOINT ["docker-entrypoint.sh"] + +CMD [ "node" ] diff --git a/20/jammy-slim/docker-entrypoint.sh b/20/jammy-slim/docker-entrypoint.sh new file mode 100755 index 000000000..1b3116e53 --- /dev/null +++ b/20/jammy-slim/docker-entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e + +# Run command with node if the first argument contains a "-" or is not a system command. The last +# part inside the "{}" is a workaround for the following bug in ash/dash: +# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=874264 +if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ] || { [ -f "${1}" ] && ! [ -x "${1}" ]; }; then + set -- node "$@" +fi + +exec "$@" diff --git a/20/jammy/Dockerfile b/20/jammy/Dockerfile new file mode 100644 index 000000000..50fbee876 --- /dev/null +++ b/20/jammy/Dockerfile @@ -0,0 +1,76 @@ +FROM riscv64/buildpack-deps:jammy + +RUN groupadd --gid 1000 node \ + && useradd --uid 1000 --gid node --shell /bin/bash --create-home node + +ENV NODE_VERSION 20.16.0 + +RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \ + && case "${dpkgArch##*-}" in \ + amd64) ARCH='x64';; \ + ppc64el) ARCH='ppc64le';; \ + s390x) ARCH='s390x';; \ + arm64) ARCH='arm64';; \ + armhf) ARCH='armv7l';; \ + i386) ARCH='x86';; \ + riscv64) ARCH='riscv64';; \ + *) echo "unsupported architecture"; exit 1 ;; \ + esac \ + # use pre-existing gpg directory, see https://github.com/nodejs/docker-node/pull/1895#issuecomment-1550389150 + && export GNUPGHOME="$(mktemp -d)" \ + # gpg keys listed at https://github.com/nodejs/node#release-keys + && set -ex \ + && for key in \ + 4ED778F539E3634C779C87C6D7062848A1AB005C \ + 141F07595B7B3FFE74309A937405533BE57C7D57 \ + 74F12602B6F1C4E913FAA37AD3A89613643B6201 \ + DD792F5973C6DE52C432CBDAC77ABFA00DDBF2B7 \ + 61FC681DFB92A079F1685E77973F295594EC4689 \ + 8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \ + C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ + 890C08DB8579162FEE0DF9DB8BEAB4DFCF555EF4 \ + C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C \ + 108F52B48DB57BB0CC439B2997B01419BD92F80A \ + A363A499291CBBC940DD62E41F10027AF002F8B0 \ + CC68F5A3106FF448322E48ED27F5E38D5B0A215F \ + ; do \ + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \ + done \ + && curl -fsSLO --compressed "https://github.com/cartesi/unofficial-builds/releases/download/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \ + && tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \ + && rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" \ + && ln -s /usr/local/bin/node /usr/local/bin/nodejs \ + # smoke tests + && node --version \ + && npm --version + +ENV YARN_VERSION 1.22.22 + +RUN set -ex \ + # use pre-existing gpg directory, see https://github.com/nodejs/docker-node/pull/1895#issuecomment-1550389150 + && export GNUPGHOME="$(mktemp -d)" \ + && for key in \ + 6A010C5166006599AA17F08146C2130DFD2497F5 \ + ; do \ + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \ + done \ + && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \ + && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \ + && gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ + && gpgconf --kill all \ + && rm -rf "$GNUPGHOME" \ + && mkdir -p /opt \ + && tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \ + && ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \ + && ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \ + && rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ + # smoke test + && yarn --version \ + && rm -rf /tmp/* + +COPY docker-entrypoint.sh /usr/local/bin/ +ENTRYPOINT ["docker-entrypoint.sh"] + +CMD [ "node" ] diff --git a/20/jammy/docker-entrypoint.sh b/20/jammy/docker-entrypoint.sh new file mode 100755 index 000000000..1b3116e53 --- /dev/null +++ b/20/jammy/docker-entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e + +# Run command with node if the first argument contains a "-" or is not a system command. The last +# part inside the "{}" is a workaround for the following bug in ash/dash: +# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=874264 +if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ] || { [ -f "${1}" ] && ! [ -x "${1}" ]; }; then + set -- node "$@" +fi + +exec "$@" diff --git a/Dockerfile-ubuntu-slim.template b/Dockerfile-ubuntu-slim.template new file mode 100644 index 000000000..24729dbd8 --- /dev/null +++ b/Dockerfile-ubuntu-slim.template @@ -0,0 +1,91 @@ +FROM ubuntu:name + +RUN groupadd --gid 1000 node \ + && useradd --uid 1000 --gid node --shell /bin/bash --create-home node + +ENV NODE_VERSION 0.0.0 + +RUN ARCH= OPENSSL_ARCH= && dpkgArch="$(dpkg --print-architecture)" \ + && case "${dpkgArch##*-}" in \ + amd64) ARCH='x64' OPENSSL_ARCH='linux-x86_64';; \ + ppc64el) ARCH='ppc64le' OPENSSL_ARCH='linux-ppc64le';; \ + s390x) ARCH='s390x' OPENSSL_ARCH='linux*-s390x';; \ + arm64) ARCH='arm64' OPENSSL_ARCH='linux-aarch64';; \ + armhf) ARCH='armv7l' OPENSSL_ARCH='linux-armv4';; \ + i386) ARCH='x86' OPENSSL_ARCH='linux-elf';; \ + riscv64) ARCH='riscv64' OPENSSL_ARCH='linux-elf';; \ + *) echo "unsupported architecture"; exit 1 ;; \ + esac \ + && set -ex \ + # libatomic1 for arm + && apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr xz-utils libatomic1 --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* \ + && for key in \ + "${NODE_KEYS[@]}" + ; do \ + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \ + done \ + && curl -fsSLO --compressed "https://github.com/cartesi/unofficial-builds/releases/download/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \ + && gpgconf --kill all \ + && rm -rf "$GNUPGHOME" \ + && tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \ + && rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" \ + # Remove unused OpenSSL headers to save ~34MB. See this NodeJS issue: https://github.com/nodejs/node/issues/46451 + && find /usr/local/include/node/openssl/archs -mindepth 1 -maxdepth 1 ! -name "$OPENSSL_ARCH" -exec rm -rf {} \; \ + && apt-mark auto '.*' > /dev/null \ + && find /usr/local -type f -executable -exec ldd '{}' ';' \ + | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \ + | sort -u \ + | xargs -r dpkg-query --search \ + | cut -d: -f1 \ + | sort -u \ + | xargs -r apt-mark manual \ + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ + && ln -s /usr/local/bin/node /usr/local/bin/nodejs \ + # smoke tests + && node --version \ + && npm --version + +ENV YARN_VERSION 0.0.0 + +RUN set -ex \ + && savedAptMark="$(apt-mark showmanual)" \ + && apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* \ + # use pre-existing gpg directory, see https://github.com/nodejs/docker-node/pull/1895#issuecomment-1550389150 + && export GNUPGHOME="$(mktemp -d)" \ + && for key in \ + "${YARN_KEYS[@]}" + ; do \ + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \ + done \ + && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \ + && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \ + && gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ + && gpgconf --kill all \ + && rm -rf "$GNUPGHOME" \ + && mkdir -p /opt \ + && tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \ + && ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \ + && ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \ + && rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ + && apt-mark auto '.*' > /dev/null \ + && { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; } \ + && find /usr/local -type f -executable -exec ldd '{}' ';' \ + | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \ + | sort -u \ + | xargs -r dpkg-query --search \ + | cut -d: -f1 \ + | sort -u \ + | xargs -r apt-mark manual \ + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ + # smoke test + && yarn --version \ + && rm -rf /tmp/* + +COPY docker-entrypoint.sh /usr/local/bin/ +ENTRYPOINT ["docker-entrypoint.sh"] + +CMD [ "node" ] diff --git a/Dockerfile-ubuntu.template b/Dockerfile-ubuntu.template new file mode 100644 index 000000000..68fb9f5c4 --- /dev/null +++ b/Dockerfile-ubuntu.template @@ -0,0 +1,65 @@ +FROM buildpack-deps:name + +RUN groupadd --gid 1000 node \ + && useradd --uid 1000 --gid node --shell /bin/bash --create-home node + +ENV NODE_VERSION 0.0.0 + +RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \ + && case "${dpkgArch##*-}" in \ + amd64) ARCH='x64';; \ + ppc64el) ARCH='ppc64le';; \ + s390x) ARCH='s390x';; \ + arm64) ARCH='arm64';; \ + armhf) ARCH='armv7l';; \ + i386) ARCH='x86';; \ + riscv64) ARCH='riscv64';; \ + *) echo "unsupported architecture"; exit 1 ;; \ + esac \ + # use pre-existing gpg directory, see https://github.com/nodejs/docker-node/pull/1895#issuecomment-1550389150 + && export GNUPGHOME="$(mktemp -d)" \ + # gpg keys listed at https://github.com/nodejs/node#release-keys + && set -ex \ + && for key in \ + "${NODE_KEYS[@]}" + ; do \ + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \ + done \ + && curl -fsSLO --compressed "https://github.com/cartesi/unofficial-builds/releases/download/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \ + && tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \ + && rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" \ + && ln -s /usr/local/bin/node /usr/local/bin/nodejs \ + # smoke tests + && node --version \ + && npm --version + +ENV YARN_VERSION 0.0.0 + +RUN set -ex \ + # use pre-existing gpg directory, see https://github.com/nodejs/docker-node/pull/1895#issuecomment-1550389150 + && export GNUPGHOME="$(mktemp -d)" \ + && for key in \ + "${YARN_KEYS[@]}" + ; do \ + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys "$key" || \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" ; \ + done \ + && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \ + && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \ + && gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ + && gpgconf --kill all \ + && rm -rf "$GNUPGHOME" \ + && mkdir -p /opt \ + && tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \ + && ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \ + && ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \ + && rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ + # smoke test + && yarn --version \ + && rm -rf /tmp/* + +COPY docker-entrypoint.sh /usr/local/bin/ +ENTRYPOINT ["docker-entrypoint.sh"] + +CMD [ "node" ] diff --git a/README.md b/README.md index fc778a31e..1d4359503 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ The official Node.js docker image, made with love by the node community. - [`node:alpine`](#nodealpine) - [`node:bullseye`](#nodebullseye) - [`node:bookworm`](#nodebookworm) + - [`node:jammy`](#nodejammy) - [`node:slim`](#nodeslim) - [License](#license) - [Supported Docker versions](#supported-docker-versions) @@ -216,6 +217,12 @@ This image is based on version 12 of [Debian](http://debian.org), available in [the `debian` official image](https://hub.docker.com/_/debian). +### `node:jammy` + +This image is based on version 22.04 of +[Ubuntu](http://ubuntu.com), available in +[the `ubuntu` official image](https://hub.docker.com/_/ubuntu). + ### `node:slim` This image does not contain the common packages contained in the default tag and diff --git a/UBUNTU-NOTES.md b/UBUNTU-NOTES.md new file mode 100644 index 000000000..7a564cd75 --- /dev/null +++ b/UBUNTU-NOTES.md @@ -0,0 +1,35 @@ +# Ubuntu + +The [Cartesi](http://cartesi.io) team is interested in having node images built for `linux/riscv64` architecture, so it can be used as a base image for Cartesi DApps written in nodejs. + +Debian and buildpack-deps debian images, which are the base for the official node image, are still unstable for `linux/riscv64` platform. + +On the other hand Ubuntu and buildpack-deps ubuntu images already have official builds for `linux/riscv64`. + +So this branch adds Ubuntu based variants for the `node` image. +A [PR was opened upstream](https://github.com/nodejs/docker-node/pull/1834), but it was closed. + +In the meantime the Cartesi team is building the image and publishing as `cartesi/node`. + +```shell +docker pull cartesi/node +``` + +## Building locally + +The primary change introduced in this branch was to `versions.json`, adding `jammy` variant. The other changes are generated by executing the following command, which uses Docker so it works on any platform. + +```shell +docker run -it --rm -v $(pwd):/app ubuntu +apt-get update && apt-get install -y curl && cd /app && ./update.sh +``` + +After running the command above the Dockerfiles for the target architecture of the host/docker machine are created or updated. The commands below build the images locally, using `dockerx` multi platform build. + +```shell +docker buildx bake +``` + +> TODO: create a script to generate the [docker-bake.hcl](docker-bake.hcl) file from the [versions.json](versions.json) files. + +Several tags are built, the main one is `docker.io/cartesi/node:jammy`. diff --git a/architectures b/architectures index 1cb4bf352..0f8cfa9a1 100644 --- a/architectures +++ b/architectures @@ -6,3 +6,4 @@ arm64v8 alpine3.19,alpine3.20,bookworm,bookworm-slim,bullseye,bullseye-sl i386 alpine3.19,alpine3.20 ppc64le alpine3.19,alpine3.20,bookworm,bookworm-slim,bullseye,bullseye-slim s390x alpine3.19,alpine3.20,bookworm,bookworm-slim,bullseye,bullseye-slim +riscv64 jammy,jammy-slim diff --git a/config b/config index bb8d85f91..dbe1056a6 100644 --- a/config +++ b/config @@ -2,3 +2,4 @@ baseuri https://nodejs.org/dist default_variant bookworm alpine_version 3.19 debian_versions bookworm bullseye +ubuntu_versions jammy diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 000000000..42be375d9 --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,72 @@ + +group "default" { + targets = ["v20-jammy"] +} + +group "jammy" { + targets = ["v20-jammy", "v18-jammy"] +} + +group "jammy-slim" { + targets = ["v20-jammy-slim", "v18-jammy-slim"] +} + +target "riscv" { + platforms = ["linux/riscv64"] +} + +target "v18-jammy" { + inherits = ["riscv"] + context = "18/jammy/" + tags = [ + "docker.io/cartesi/node:18.20.4-jammy", + "docker.io/cartesi/node:18.20-jammy", + "docker.io/cartesi/node:18-jammy", + "ghcr.io/cartesi/node:18.20.4-jammy", + "ghcr.io/cartesi/node:18.20-jammy", + "ghcr.io/cartesi/node:18-jammy" + ] +} + +target "v18-jammy-slim" { + inherits = ["riscv"] + context = "18/jammy-slim/" + tags = [ + "docker.io/cartesi/node:18.20.4-jammy-slim", + "docker.io/cartesi/node:18.20-jammy-slim", + "docker.io/cartesi/node:18-jammy-slim", + "ghcr.io/cartesi/node:18.20.4-jammy-slim", + "ghcr.io/cartesi/node:18.20-jammy-slim", + "ghcr.io/cartesi/node:18-jammy-slim" + ] +} + +target "v20-jammy" { + inherits = ["riscv"] + context = "20/jammy/" + tags = [ + "docker.io/cartesi/node:20.16.0-jammy", + "docker.io/cartesi/node:20.16-jammy", + "docker.io/cartesi/node:20-jammy", + "docker.io/cartesi/node:jammy", + "ghcr.io/cartesi/node:20.16.0-jammy", + "ghcr.io/cartesi/node:20.16-jammy", + "ghcr.io/cartesi/node:20-jammy", + "ghcr.io/cartesi/node:jammy" + ] +} + +target "v20-jammy-slim" { + inherits = ["riscv"] + context = "20/jammy-slim/" + tags = [ + "docker.io/cartesi/node:20.16.0-jammy-slim", + "docker.io/cartesi/node:20.16-jammy-slim", + "docker.io/cartesi/node:20-jammy-slim", + "docker.io/cartesi/node:jammy-slim", + "ghcr.io/cartesi/node:20.16.0-jammy-slim", + "ghcr.io/cartesi/node:20.16-jammy-slim", + "ghcr.io/cartesi/node:20-jammy-slim", + "ghcr.io/cartesi/node:jammy-slim" + ] +} diff --git a/functions.sh b/functions.sh index bee3dafe0..64ea87617 100755 --- a/functions.sh +++ b/functions.sh @@ -38,6 +38,9 @@ function get_arch() { armv7l) arch="arm32v7" ;; + riscv64) + arch="riscv64" + ;; *) echo "$0 does not support architecture ${arch:-unknown} ... aborting" exit 1 @@ -193,6 +196,34 @@ function is_debian_slim() { return 1 } +function is_ubuntu() { + local variant + variant=$1 + shift + + IFS=' ' read -ra ubuntuVersions <<< "$(get_config "./" "ubuntu_versions")" + for d in "${ubuntuVersions[@]}"; do + if [ "${d}" = "${variant}" ]; then + return 0 + fi + done + return 1 +} + +function is_ubuntu_slim() { + local variant + variant=$1 + shift + + IFS=' ' read -ra ubuntuVersions <<< "$(get_config "./" "ubuntu_versions")" + for d in "${ubuntuVersions[@]}"; do + if [ "${d}-slim" = "${variant}" ]; then + return 0 + fi + done + return 1 +} + function get_fork_name() { local version version=$1 diff --git a/update.sh b/update.sh index 0b6aaf69d..d08b2c354 100755 --- a/update.sh +++ b/update.sh @@ -167,6 +167,11 @@ function update_node_version() { sed -Ei -e "s/(buildpack-deps:)name/\\1${variant}/" "${dockerfile}-tmp" elif is_debian_slim "${variant}"; then sed -Ei -e "s/(debian:)name-slim/\\1${variant}/" "${dockerfile}-tmp" + elif is_ubuntu "${variant}"; then + sed -Ei -e "s/(buildpack-deps:)name/\\1${variant}/" "${dockerfile}-tmp" + elif is_ubuntu_slim "${variant}"; then + # TODO: fix replacement by using only jammy and not jammy-slim + sed -Ei -e "s/(ubuntu:)name/\\1${variant}/" "${dockerfile}-tmp" fi if diff -q "${dockerfile}-tmp" "${dockerfile}" > /dev/null; then @@ -221,6 +226,10 @@ for version in "${versions[@]}"; do template_file="${parentpath}/Dockerfile-debian.template" elif is_debian_slim "${variant}"; then template_file="${parentpath}/Dockerfile-slim.template" + elif is_ubuntu "${variant}"; then + template_file="${parentpath}/Dockerfile-ubuntu.template" + elif is_ubuntu_slim "${variant}"; then + template_file="${parentpath}/Dockerfile-ubuntu-slim.template" elif is_alpine "${variant}"; then template_file="${parentpath}/Dockerfile-alpine.template" fi diff --git a/versions.json b/versions.json index deaeb8795..20d97d294 100644 --- a/versions.json +++ b/versions.json @@ -7,6 +7,7 @@ "codename": "", "alpine-default": "alpine3.20", "debian-default": "bookworm", + "ubuntu-default": "jammy", "variants": { "alpine3.19": [ "amd64", @@ -51,6 +52,9 @@ "arm64v8", "ppc64le", "s390x" + ], + "jammy": [ + "riscv64" ] } }, @@ -62,6 +66,7 @@ "codename": "iron", "alpine-default": "alpine3.20", "debian-default": "bookworm", + "ubuntu-default": "jammy", "variants": { "alpine3.19": [ "amd64", @@ -106,6 +111,9 @@ "arm64v8", "ppc64le", "s390x" + ], + "jammy": [ + "riscv64" ] } }, @@ -117,6 +125,7 @@ "codename": "hydrogen", "alpine-default": "alpine3.20", "debian-default": "bookworm", + "ubuntu-default": "jammy", "variants": { "alpine3.19": [ "amd64", @@ -161,6 +170,9 @@ "arm64v8", "ppc64le", "s390x" + ], + "jammy": [ + "riscv64" ] } }