Compare commits

...

21 Commits

Author SHA1 Message Date
cb455aa773 5.1.0
Some checks failed
Docker (tags) / security (push) Successful in 28s
Docker (tags) / test (push) Successful in 31s
Docker (tags) / metadata (push) Successful in 3s
Docker (tags) / release (push) Failing after 15s
2025-10-26 14:22:02 +00:00
9b87ba1acb feat(alpine-deno): Improve alpine deno image: switch to alpine:edge and use native Deno package, remove glibc workaround, update NVM/PATH, add local tooling settings and expanded README 2025-10-26 14:22:02 +00:00
83a07732db feat: Introduce multi-architecture Alpine Docker images with NVM, Bun, and Deno support 2025-10-26 14:00:20 +00:00
66fd354b95 feat(Dockerfile): Add installation of Bun and Deno for enhanced runtime support 2025-10-26 12:12:54 +00:00
bb8d623c95 refactor(nvm): Move wrapper scripts to image_support_files directory
Improved code organization and maintainability:
- Created image_support_files/ directory for Docker helper scripts
- Moved bash-with-nvm and docker-entrypoint.sh to support directory
- Added comprehensive README.md documenting each script's purpose
- Updated Dockerfile to COPY from organized directory structure

Benefits:
- Cleaner repository structure
- Scripts are now version-controlled files (not echo chains)
- Easier to read, modify, and maintain
- Self-documented with in-directory README

No functional changes - all nvm functionality remains identical.
2025-10-26 10:38:59 +00:00
3aea4a70ee docs(nvm): Document nvm usage in Dockerfiles and CI/CD workflows
- Add comprehensive NVM usage section to README
- Document Dockerfile RUN command usage
- Document CI/CD workflow integration
- Explain nvm vs npmci comparison
- Add technical implementation notes to readme.hints.md
- Update changelog with v5.0.147 feature details

Includes:
- Direct nvm usage examples for Dockerfiles
- CI/CD workflow YAML examples
- Version persistence behavior documentation
- Multi-version testing examples
- Technical architecture details
- Maintenance guidelines
2025-10-26 10:36:05 +00:00
c6ba400214 feat(nvm): Enable full nvm support in Docker builds and CI/CD workflows
- Add global nvm configuration in /etc/bash.bashrc (prepended before PS1 check)
- Create bash-with-nvm wrapper for Dockerfile RUN commands
- Add intelligent ENTRYPOINT for runtime nvm support
- Change default SHELL directive to use nvm wrapper
- nvm commands work directly in RUN without manual sourcing
- nvm commands work in CI/CD workflow bash -c scripts
- Maintain backward compatibility: npmci still available, ENV PATH preserved
- Non-bash shells fall back to ENV PATH (v20.12.2)
- Both interactive and non-interactive shells have full nvm access

Technical implementation:
- /etc/bash.bashrc: NVM init prepended before early return
- /usr/local/bin/bash-with-nvm: Build-time wrapper via SHELL directive
- /usr/local/bin/docker-entrypoint.sh: Runtime wrapper for bash -c detection
- ENV PATH fallback ensures non-bash compatibility

Tested:
- Dockerfile RUN: install, use, version switching
- Runtime bash -c: all nvm commands
- CI/CD workflows: .gitea context
- Backward compat: pnpm, npmci, ENV PATH
- Multi-stage builds, interactive shells
2025-10-26 10:35:42 +00:00
ab4275c430 5.0.146
All checks were successful
Docker (tags) / security (push) Successful in 38s
Docker (tags) / test (push) Successful in 55s
Docker (tags) / metadata (push) Successful in 6s
Docker (tags) / release (push) Successful in 14m46s
2024-11-17 20:24:00 +01:00
76c86e09c1 fix(Dockerfiles): Correct Docker image source host in various Dockerfiles 2024-11-17 20:24:00 +01:00
f2ab850e19 5.0.145
Some checks failed
Docker (tags) / security (push) Successful in 39s
Docker (tags) / test (push) Successful in 54s
Docker (tags) / metadata (push) Successful in 6s
Docker (tags) / release (push) Failing after 42s
2024-11-17 20:16:21 +01:00
29c707d79f fix(docs): Minor documentation updates without code changes. 2024-11-17 20:16:20 +01:00
5789c4eea6 5.0.144
Some checks failed
Docker (tags) / security (push) Successful in 36s
Docker (tags) / test (push) Successful in 54s
Docker (tags) / metadata (push) Successful in 6s
Docker (tags) / release (push) Failing after 15m41s
2024-11-17 07:57:21 +01:00
52369e55db fix(ci): Update Docker container source for workflow to new registry 2024-11-17 07:57:21 +01:00
13aadf4730 5.0.143
Some checks failed
Docker (tags) / security (push) Successful in 44s
Docker (tags) / test (push) Successful in 54s
Docker (tags) / metadata (push) Successful in 7s
Docker (tags) / release (push) Failing after 29s
2024-11-17 07:47:16 +01:00
41cf74c307 fix(core): No uncommitted changes 2024-11-17 07:47:16 +01:00
8e48786393 5.0.142
All checks were successful
Docker (tags) / security (push) Successful in 37s
Docker (tags) / test (push) Successful in 44s
Docker (tags) / metadata (push) Successful in 5s
Docker (tags) / release (push) Successful in 1m8s
2024-05-26 14:39:43 +02:00
a00d36cf95 fix(core): update 2024-05-26 14:39:42 +02:00
69ee21ed1b 5.0.141
Some checks failed
Docker (tags) / security (push) Failing after 0s
Docker (tags) / test (push) Has been skipped
Docker (tags) / release (push) Has been skipped
Docker (tags) / metadata (push) Has been skipped
2024-05-26 14:02:48 +02:00
39bd0ea990 fix(core): update 2024-05-26 14:02:47 +02:00
cfc7ef07cf 5.0.140
Some checks failed
Docker (tags) / security (push) Failing after 0s
Docker (tags) / test (push) Has been skipped
Docker (tags) / release (push) Has been skipped
Docker (tags) / metadata (push) Has been skipped
2024-05-26 14:01:44 +02:00
356dda054f fix(core): update 2024-05-26 14:01:43 +02:00
24 changed files with 1210 additions and 286 deletions

View File

@@ -6,7 +6,7 @@ on:
- '*' - '*'
env: env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci IMAGE: code.foss.global/host.today/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
# NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}} # NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
# NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}} # NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
@@ -74,7 +74,7 @@ jobs:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci image: code.foss.global/host.today/ht-docker-dbase:npmci
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3

View File

@@ -1,55 +0,0 @@
# gitzone ci_docker
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci-cache/
key: "$CI_BUILD_STAGE"
before_script:
- pnpm uninstall -g @ship.zone/npmci
- pnpm install -g @ship.zone/npmci
- npmci npm prepare
stages:
- test
- release
- trigger
- pages
testStable:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
services:
- docker:stable-dind
stage: release
script:
- npmci node install lts
- npmci docker login
- npmci docker build
- npmci docker test
- npmci docker push registry.gitlab.com
- npmci docker push docker.io
only:
- tags
tags:
- docker
- priv
trigger:
stage: trigger
script:
- npmci trigger
only:
- tags
tags:
- docker

View File

@@ -27,6 +27,7 @@ RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selectio
rsync \ rsync \
ssh \ ssh \
wget \ wget \
unzip \
# puppeteer # puppeteer
gconf-service \ gconf-service \
libasound2 \ libasound2 \
@@ -85,18 +86,51 @@ RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selectio
# Install nvm with node and npm # Install nvm with node and npm
RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
# Make nvm available globally in all bash shells (interactive + non-interactive)
# IMPORTANT: Prepend to bashrc, before the "[ -z "$PS1" ] && return" line
RUN printf '%s\n%s\n%s\n\n%s\n' \
'export NVM_DIR="/usr/local/nvm"' \
'[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' \
'[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"' \
"$(cat /etc/bash.bashrc)" > /etc/bash.bashrc
# Copy nvm wrapper scripts from support directory
COPY image_support_files/bash-with-nvm /usr/local/bin/bash-with-nvm
COPY image_support_files/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/bash-with-nvm /usr/local/bin/docker-entrypoint.sh
# Use wrapper for RUN commands to enable nvm
SHELL ["/usr/local/bin/bash-with-nvm"]
# Enable nvm for runtime bash commands (CI/CD workflows)
ENV BASH_ENV=/etc/bash.bashrc
# prepare pnpm # prepare pnpm
ENV PNPM_HOME="/root/.local/share/pnpm/pnpm" ENV PNPM_HOME="/root/.local/share/pnpm/pnpm"
RUN mkdir -p ${PNPM_HOME} RUN mkdir -p ${PNPM_HOME}
ENV PATH="$PNPM_HOME:$PATH" ENV PATH="$PNPM_HOME:$PATH"
RUN bash -c "source $NVM_DIR/nvm.sh \ # Now nvm is available directly without sourcing
&& nvm install $NODE_VERSION_STABLE \ RUN nvm install $NODE_VERSION_STABLE \
&& nvm alias default $NODE_VERSION_STABLE \ && nvm alias default $NODE_VERSION_STABLE \
&& nvm use default \ && nvm use default \
&& curl -fsSL https://get.pnpm.io/install.sh | bash - \ && curl -fsSL https://get.pnpm.io/install.sh | bash - \
&& pnpm -v \ && pnpm -v \
&& pnpm config set unsafe-perm true" && pnpm config set unsafe-perm true
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION_STABLE/lib/node_modules ENV NODE_PATH $NVM_DIR/v$NODE_VERSION_STABLE/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION_STABLE/bin:$PATH ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION_STABLE/bin:$PATH
# Install Bun
RUN curl -fsSL https://bun.sh/install | bash
ENV BUN_INSTALL="/root/.bun"
ENV PATH="$BUN_INSTALL/bin:$PATH"
# Install Deno
RUN curl -fsSL https://deno.land/install.sh | sh
ENV DENO_INSTALL="/root/.deno"
ENV PATH="$DENO_INSTALL/bin:$PATH"
# Set entrypoint to make nvm available in all runtime contexts
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["bash"]

View File

@@ -1,11 +0,0 @@
FROM node:18.15.0-alpine
LABEL author="Task Venture Capital GmbH <hello@task.vc>"
#pnpm
ENV PNPM_HOME="/root/.local/share/pnpm/pnpm"
RUN apk add --no-cache curl iputils bind-tools bash && mkdir -p ${PNPM_HOME}
ENV PATH="$PNPM_HOME:$PATH"
RUN curl -fsSL "https://github.com/pnpm/pnpm/releases/latest/download/pnpm-linuxstatic-x64" -o /bin/pnpm; chmod +x /bin/pnpm;
RUN pnpm -v
ENV NODE_OPTIONS="--max_old_space_size=1000"

54
Dockerfile_alpine_bun Normal file
View File

@@ -0,0 +1,54 @@
FROM alpine:latest
LABEL author="Task Venture Capital GmbH <hello@task.vc>"
WORKDIR /workspace
# Important environment variables
ENV NODE_VERSION_LTS="20.18.2" \
NVM_DIR="/usr/local/nvm" \
BUN_INSTALL="/root/.bun" \
NVM_NODEJS_ORG_MIRROR="https://unofficial-builds.nodejs.org/download/release"
# Install required packages for NVM and Node.js
RUN apk add --no-cache \
bash \
curl \
git \
ca-certificates \
unzip \
libstdc++
# Install NVM (latest version for better Alpine/musl support)
RUN mkdir -p $NVM_DIR && curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
# Make nvm available globally in all bash shells (interactive + non-interactive)
# IMPORTANT: Create /etc/bash.bashrc with nvm initialization
RUN printf '%s\n%s\n%s\n' \
'export NVM_DIR="/usr/local/nvm"' \
'[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' \
'[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"' \
> /etc/bash.bashrc
# Copy nvm wrapper scripts from support directory
COPY image_support_files/bash-with-nvm /usr/local/bin/bash-with-nvm
COPY image_support_files/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/bash-with-nvm /usr/local/bin/docker-entrypoint.sh
# Use wrapper for RUN commands to enable nvm
SHELL ["/usr/local/bin/bash-with-nvm"]
# Enable nvm for runtime bash commands (CI/CD workflows)
ENV BASH_ENV=/etc/bash.bashrc
# Install Node.js LTS via NVM and Bun
RUN nvm install $NODE_VERSION_LTS \
&& nvm alias default $NODE_VERSION_LTS \
&& nvm use default \
&& curl -fsSL https://bun.sh/install | bash
ENV PATH="$BUN_INSTALL/bin:$NVM_DIR/versions/node/v$NODE_VERSION_LTS/bin:$PATH"
ENV NODE_PATH=$NVM_DIR/v$NODE_VERSION_LTS/lib/node_modules
# Set entrypoint to make nvm available in all runtime contexts
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["bash"]

54
Dockerfile_alpine_deno Normal file
View File

@@ -0,0 +1,54 @@
FROM alpine:edge
LABEL author="Task Venture Capital GmbH <hello@task.vc>"
WORKDIR /workspace
# Important environment variables
ENV NODE_VERSION_LTS="20.18.2" \
NVM_DIR="/usr/local/nvm" \
NVM_NODEJS_ORG_MIRROR="https://unofficial-builds.nodejs.org/download/release"
# Install required packages for NVM and Node.js
# Install Deno from Alpine community repository (native musl build)
RUN apk add --no-cache \
bash \
curl \
git \
ca-certificates \
unzip \
libstdc++ \
deno
# Install NVM (latest version for better Alpine/musl support)
RUN mkdir -p $NVM_DIR && curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
# Make nvm available globally in all bash shells (interactive + non-interactive)
# IMPORTANT: Create /etc/bash.bashrc with nvm initialization
RUN printf '%s\n%s\n%s\n' \
'export NVM_DIR="/usr/local/nvm"' \
'[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' \
'[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"' \
> /etc/bash.bashrc
# Copy nvm wrapper scripts from support directory
COPY image_support_files/bash-with-nvm /usr/local/bin/bash-with-nvm
COPY image_support_files/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/bash-with-nvm /usr/local/bin/docker-entrypoint.sh
# Use wrapper for RUN commands to enable nvm
SHELL ["/usr/local/bin/bash-with-nvm"]
# Enable nvm for runtime bash commands (CI/CD workflows)
ENV BASH_ENV=/etc/bash.bashrc
# Install Node.js LTS via NVM (Deno already installed from Alpine repos)
RUN nvm install $NODE_VERSION_LTS \
&& nvm alias default $NODE_VERSION_LTS \
&& nvm use default
ENV PATH="$NVM_DIR/versions/node/v$NODE_VERSION_LTS/bin:$PATH"
ENV NODE_PATH=$NVM_DIR/v$NODE_VERSION_LTS/lib/node_modules
# Set entrypoint to make nvm available in all runtime contexts
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["bash"]

67
Dockerfile_alpine_node Normal file
View File

@@ -0,0 +1,67 @@
FROM alpine:latest
LABEL author="Task Venture Capital GmbH <hello@task.vc>"
WORKDIR /workspace
# Important environment variables
ENV NODE_VERSION_LTS="20.18.2" \
NVM_DIR="/usr/local/nvm" \
PNPM_HOME="/root/.local/share/pnpm" \
NVM_NODEJS_ORG_MIRROR="https://unofficial-builds.nodejs.org/download/release"
# Install required packages for NVM and Node.js
RUN apk add --no-cache \
bash \
curl \
git \
build-base \
python3 \
linux-headers \
ca-certificates \
wget \
unzip \
iputils \
bind-tools \
libstdc++
# Install NVM (latest version for better Alpine/musl support)
RUN mkdir -p $NVM_DIR && curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
# Make nvm available globally in all bash shells (interactive + non-interactive)
# IMPORTANT: Create /etc/bash.bashrc with nvm initialization
RUN printf '%s\n%s\n%s\n' \
'export NVM_DIR="/usr/local/nvm"' \
'[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' \
'[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"' \
> /etc/bash.bashrc
# Copy nvm wrapper scripts from support directory
COPY image_support_files/bash-with-nvm /usr/local/bin/bash-with-nvm
COPY image_support_files/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/bash-with-nvm /usr/local/bin/docker-entrypoint.sh
# Use wrapper for RUN commands to enable nvm
SHELL ["/usr/local/bin/bash-with-nvm"]
# Enable nvm for runtime bash commands (CI/CD workflows)
ENV BASH_ENV=/etc/bash.bashrc
# Prepare pnpm directory
RUN mkdir -p ${PNPM_HOME}
ENV PATH="$PNPM_HOME:$PATH"
# Install Node.js LTS via NVM and pnpm
# Use musl-specific builds from unofficial-builds for Alpine compatibility
RUN nvm install $NODE_VERSION_LTS \
&& nvm alias default $NODE_VERSION_LTS \
&& nvm use default \
&& npm install -g pnpm \
&& pnpm -v \
&& pnpm config set unsafe-perm true
ENV NODE_PATH=$NVM_DIR/v$NODE_VERSION_LTS/lib/node_modules
ENV PATH=$NVM_DIR/versions/node/v$NODE_VERSION_LTS/bin:$PATH
# Set entrypoint to make nvm available in all runtime contexts
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["bash"]

View File

@@ -1,4 +1,4 @@
FROM hosttoday/ht-docker-node:alpine FROM host.today/ht-docker-node:alpine
RUN apk update && apk add bash libc6-compat alpine-sdk RUN apk update && apk add bash libc6-compat alpine-sdk
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python

View File

@@ -1,4 +1,4 @@
FROM hosttoday/ht-docker-node:npmci FROM host.today/ht-docker-node:npmci
RUN npm install -g \ RUN npm install -g \
@git.zone/tsrun \ @git.zone/tsrun \
@git.zone/tstest \ @git.zone/tstest \

View File

@@ -1,12 +0,0 @@
FROM hosttoday/ht-docker-node:latest as stage1
LABEL author="Task Venture Capital GmbH <hello@task.vc>"
RUN apt-get update && apt-get install -y --no-install-recommends qemu-user-static binfmt-support
# the following lines need to be run on a system that supports both architectures
# update-binfmts --enable qemu-arm \
# && update-binfmts --display qemu-arm \
# && mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc \
# && echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register
FROM arm32v7/node:lts-jessie as stage2
COPY --from=stage1 /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static

View File

@@ -1,4 +1,4 @@
FROM hosttoday/ht-docker-node:latest FROM host.today/ht-docker-node:latest
LABEL author="Task Venture Capital GmbH <hello@task.vc>" LABEL author="Task Venture Capital GmbH <hello@task.vc>"
RUN bash -c "source $NVM_DIR/nvm.sh \ RUN bash -c "source $NVM_DIR/nvm.sh \

View File

@@ -1,4 +1,4 @@
FROM hosttoday/ht-docker-node:latest FROM host.today/ht-docker-node:latest
LABEL author="Task Venture Capital GmbH <hello@task.vc>" LABEL author="Task Venture Capital GmbH <hello@task.vc>"
RUN pnpm install -g @ship.zone/npmci RUN pnpm install -g @ship.zone/npmci

View File

@@ -1,4 +1,4 @@
FROM hosttoday/ht-docker-node:latest FROM host.today/ht-docker-node:latest
# Add Tini # Add Tini
ENV TINI_VERSION v0.19.0 ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini

125
build-alpine-images.sh Executable file
View File

@@ -0,0 +1,125 @@
#!/bin/bash
set -e
echo "🏔️ Building Multi-Architecture Alpine Docker Images"
echo "===================================================="
echo ""
# Color codes
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if buildx is available
if ! docker buildx version &> /dev/null; then
echo -e "${YELLOW}⚠️ docker buildx not found. Installing...${NC}"
docker buildx create --use
fi
# Ensure buildx builder is running
echo -e "${BLUE}🔧 Setting up buildx builder...${NC}"
if ! docker buildx inspect default-builder &> /dev/null; then
docker buildx create --name default-builder --use
else
docker buildx use default-builder
fi
echo -e "${GREEN}✅ Buildx ready${NC}"
echo ""
# Build function for multi-arch
build_multiarch_image() {
local dockerfile=$1
local tag=$2
local description=$3
echo -e "${BLUE}📦 Building Multi-Arch: ${NC}${description}"
echo -e "${YELLOW} Dockerfile: ${NC}${dockerfile}"
echo -e "${YELLOW} Tag: ${NC}${tag}"
echo -e "${YELLOW} Platforms: ${NC}linux/amd64, linux/arm64"
if docker buildx build \
--platform linux/amd64,linux/arm64 \
-f "${dockerfile}" \
-t "${tag}" \
--load \
.; then
echo -e "${GREEN}✅ Success: ${NC}${tag} (amd64 + arm64)"
echo ""
else
echo -e "\033[0;31m❌ Failed: ${NC}${tag}"
echo ""
echo -e "${YELLOW}💡 Note: Multi-arch builds with --load only work for single platform.${NC}"
echo -e "${YELLOW} To test locally, build for your native platform:${NC}"
echo -e "${YELLOW} docker buildx build --platform linux/amd64 -f ${dockerfile} -t ${tag} --load .${NC}"
exit 1
fi
}
# Build function for single platform (for local testing)
build_native_image() {
local dockerfile=$1
local tag=$2
local description=$3
local platform=$(uname -m)
# Convert platform name
if [ "$platform" = "x86_64" ]; then
platform="linux/amd64"
elif [ "$platform" = "aarch64" ] || [ "$platform" = "arm64" ]; then
platform="linux/arm64"
fi
echo -e "${BLUE}📦 Building Native: ${NC}${description}"
echo -e "${YELLOW} Dockerfile: ${NC}${dockerfile}"
echo -e "${YELLOW} Tag: ${NC}${tag}"
echo -e "${YELLOW} Platform: ${NC}${platform} (native)"
if docker buildx build \
--platform "${platform}" \
-f "${dockerfile}" \
-t "${tag}" \
--load \
.; then
echo -e "${GREEN}✅ Success: ${NC}${tag} (${platform})"
echo ""
else
echo -e "\033[0;31m❌ Failed: ${NC}${tag}"
exit 1
fi
}
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo -e "${BLUE}Building Alpine Images${NC}"
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo ""
echo -e "${YELLOW}💡 Building for native platform only (for local testing)${NC}"
echo -e "${YELLOW} To build multi-arch for push to registry, use:${NC}"
echo -e "${YELLOW} docker buildx build --platform linux/amd64,linux/arm64 --push ...${NC}"
echo ""
# Build images for native platform (can be loaded for local testing)
build_native_image "Dockerfile_alpine_node" \
"ht-docker-node:alpine-node" \
"Alpine with Node.js LTS + NVM + pnpm"
build_native_image "Dockerfile_alpine_deno" \
"ht-docker-node:alpine-deno" \
"Alpine with Node.js LTS + NVM + Deno"
build_native_image "Dockerfile_alpine_bun" \
"ht-docker-node:alpine-bun" \
"Alpine with Node.js LTS + NVM + Bun"
# Summary
echo -e "${GREEN}════════════════════════════════════════${NC}"
echo -e "${GREEN}✨ All Alpine Images Built Successfully!${NC}"
echo -e "${GREEN}════════════════════════════════════════${NC}"
echo ""
echo "📋 Built Images (Native Platform):"
echo ""
docker images | grep "ht-docker-node:alpine" | awk '{printf " ✅ %-30s %10s\n", $1":"$2, $7" "$8}'
echo ""
echo -e "${YELLOW}💡 These images are built for your native architecture for local testing.${NC}"
echo -e "${YELLOW} In CI/CD, build with: docker buildx build --platform linux/amd64,linux/arm64 --push${NC}"
echo ""

135
changelog.md Normal file
View File

@@ -0,0 +1,135 @@
# Changelog
## 2025-10-26 - 5.1.0 - feat(alpine-deno)
Improve alpine deno image: switch to alpine:edge and use native Deno package, remove glibc workaround, update NVM/PATH, add local tooling settings and expanded README
- Dockerfile_alpine_deno: switch base image from alpine:latest to alpine:edge to use Alpine community Deno package
- Install Deno via apk (native musl build) and remove previous glibc installation/workaround
- Remove DENO_INSTALL env and adjust PATH to include NVM-managed Node binary path
- Keep NVM installation and make nvm available globally; set NODE_VERSION_LTS and default alias
- Add .claude/settings.local.json with local permissions for build/run tooling
- Add / expand README (readme.md) with usage, flavours and NVM/npmci guidance
## 2025-10-26 - 5.0.148 - feat(alpine)
Major restructuring: Multi-architecture Alpine Docker images with modern runtime support
**Breaking Changes:**
- Removed `Dockerfile_alpine` (replaced by `Dockerfile_alpine_node`)
- Removed `Dockerfile_iot` (no longer needed with multi-arch approach)
- Tag naming simplified: `:alpine-node` instead of `:alpine-x64-node` and `:alpine-arm64-node`
**New Multi-Architecture Alpine Images (3 variants):**
All images support both amd64 and arm64 architectures natively:
- `Dockerfile_alpine_node``:alpine-node` - Alpine with Node.js LTS + NVM + pnpm
- `Dockerfile_alpine_deno``:alpine-deno` - Alpine with Node.js LTS + NVM + Deno
- `Dockerfile_alpine_bun``:alpine-bun` - Alpine with Node.js LTS + NVM + Bun
**Technical Improvements:**
- **Multi-architecture support**: Single Docker image works natively on both x64 (AMD64) and ARM64 (Apple Silicon, ARM servers)
- **docker buildx integration**: Build script uses buildx for proper multi-platform image creation
- **Native performance**: No emulation needed - images run at full native speed on both architectures
- **Automatic platform selection**: Docker automatically pulls the correct architecture variant
- Full NVM support in all Alpine images (v0.40.1)
- Node.js musl builds from unofficial-builds.nodejs.org for Alpine compatibility
- Significantly smaller image sizes (200-300MB vs 800MB+ Ubuntu)
- All images include NVM for flexible version management
- Reused wrapper scripts from Ubuntu base for consistency
- Added Bun and Deno runtime support
**Build & Test Infrastructure:**
- Updated `build-alpine-images.sh` to use `docker buildx` with native platform builds for local testing
- Updated `test-alpine-images.sh` to test 3 multi-arch images instead of 9 architecture-specific images
- Simplified test suite focuses on runtime functionality and NVM version switching
**Documentation:**
- Updated README with multi-architecture approach explanation
- Simplified examples using new tag names (`:alpine-node`, `:alpine-deno`, `:alpine-bun`)
- Added cross-platform development examples
- Documented native performance benefits
- Removed architecture-specific instructions (no longer needed)
## 2025-10-26 - 5.0.147 - feat(nvm)
Enable full nvm support in Docker builds and CI/CD workflows
- Added global nvm configuration in /etc/bash.bashrc (prepended before interactive check)
- Created bash-with-nvm wrapper for Dockerfile RUN commands
- Added intelligent ENTRYPOINT for runtime nvm support
- nvm commands now work directly in Dockerfile RUN without manual sourcing
- nvm commands work in CI/CD workflow bash -c scripts automatically
- Changed default SHELL directive to use nvm wrapper
- Backward compatible: npmci still available, ENV PATH preserved for fallback
- Non-bash shells fall back to ENV PATH (v20.12.2)
- Both interactive and non-interactive shells have full nvm access
## 2024-11-17 - 5.0.146 - fix(Dockerfiles)
Correct Docker image source host in various Dockerfiles
- Updated the source host from 'hosttoday/ht-docker-node' to 'host.today/ht-docker-node' in several Dockerfiles
## 2024-11-17 - 5.0.145 - fix(docs)
Minor documentation updates without code changes.
## 2024-11-17 - 5.0.144 - fix(ci)
Update Docker container source for workflow to new registry
- Changed Docker container image source in .gitea/workflows/docker_tags.yaml to code.foss.global.
## 2024-11-17 - 5.0.143 - fix(core)
No uncommitted changes
- No changes detected. All files are up-to-date.
## 2024-05-26 - 5.0.139 to 5.0.142 - Core updates
Routine updates to the core functionality.
## 2024-05-23 - 5.0.124 to 5.0.138 - Core updates
Routine updates to the core functionality.
## 2024-04-23 - 5.0.114 to 5.0.123 - Core updates
Routine updates to the core functionality.
## 2024-04-14 - 5.0.113 to 5.0.113 - Core updates
Routine updates to the core functionality.
## 2023-04-02 - 5.0.105 to 5.0.112 - Core updates
Routine updates to the core functionality.
## 2022-12-17 - 5.0.101 to 5.0.104 - Core updates
Routine updates to the core functionality.
## 2022-10-17 - 5.0.91 to 5.0.100 - Core updates
Routine updates to the core functionality.
## 2022-10-11 - 5.0.85 to 5.0.90 - Core updates
Routine updates to the core functionality.
## 2022-08-05 - 5.0.78 to 5.0.84 - Core updates
Routine updates to the core functionality.
## 2022-03-22 - 5.0.75 to 5.0.77 - Core updates
Routine updates to the core functionality.
## 2021-11-12 - 5.0.67 to 5.0.74 - Core updates
Routine updates to the core functionality.
## 2021-10-22 - 5.0.61 to 5.0.66 - Core updates
Routine updates to the core functionality.
## 2020-05-28 - 5.0.55 to 5.0.60 - Core updates
Routine updates to the core functionality.
## 2019-11-19 - 5.0.50 to 5.0.54 - Core and Snyk fixes
Core updates and restored Snyk to the latest version.
## 2016-08-31 - 4.3.2 to 4.3.5 - Core updates
Routine updates to the core functionality.
## 2016-06-01 - 4.3.1 - Multiple enhancements
Implemented various features and fixes in the project.
- Updated .gitlab-ci.yml multiple times
- Added Python3 support
- Added new features and fixed various issues

View File

@@ -0,0 +1,90 @@
# Image Support Files
This directory contains helper scripts that are copied into the Docker image during build to enable NVM functionality.
## Files
### `bash-with-nvm`
**Purpose**: Wrapper script for Dockerfile RUN commands
**Usage**: Set as SHELL directive in Dockerfile
```dockerfile
SHELL ["/usr/local/bin/bash-with-nvm"]
```
**What it does**:
- Sources nvm before executing each Dockerfile RUN command
- Enables direct usage of `nvm` commands without manual sourcing
- Example: `RUN nvm install 18` works without `bash -c "source ..."`
**Location in image**: `/usr/local/bin/bash-with-nvm`
**How it works**:
1. Exports NVM_DIR environment variable
2. Sources `$NVM_DIR/nvm.sh` to load nvm functions
3. Executes the command passed to it via `eval "$@"`
---
### `docker-entrypoint.sh`
**Purpose**: ENTRYPOINT script for runtime nvm support
**Usage**: Set as ENTRYPOINT in Dockerfile
```dockerfile
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
```
**What it does**:
- Makes nvm available in `docker run ... bash -c` commands
- Enables nvm in CI/CD workflow scripts
- Passes through non-bash commands unchanged
**Location in image**: `/usr/local/bin/docker-entrypoint.sh`
**How it works**:
1. Loads nvm in the entrypoint environment
2. Detects if command is `bash -c ...`
3. If yes: Injects `source /etc/bash.bashrc` before the user's command
4. If no: Executes command as-is with `exec "$@"`
**Examples**:
- `docker run image bash -c "nvm install 18"` → nvm is available
- `docker run image node --version` → Passes through to node binary
- CI/CD: `run: nvm install 19` → Works automatically
---
## Why These Scripts Are Needed
**The Problem**:
- nvm is a bash function, not a binary executable
- It must be sourced into each shell session
- Docker RUN commands and `bash -c` don't automatically source it
**The Solution**:
1. **bash-with-nvm**: Makes Dockerfile RUN commands work
2. **docker-entrypoint.sh**: Makes runtime `bash -c` commands work
3. **/etc/bash.bashrc** (configured in Dockerfile): Makes interactive shells work
Together, these provide seamless nvm access in all contexts.
---
## Maintenance
**Modifying the scripts**:
1. Edit the file in this directory
2. Rebuild the Docker image
3. Test with both `docker build` and `docker run` scenarios
**Testing checklist**:
- [ ] `RUN nvm install 18` works in Dockerfile
- [ ] `docker run image bash -c "nvm install 18"` works
- [ ] `docker run image node --version` still works (fallback)
- [ ] CI/CD workflows can use nvm commands
**Debugging**:
- View script in running container: `docker run image cat /usr/local/bin/bash-with-nvm`
- Test entrypoint manually: `docker run --entrypoint /bin/bash image -c "nvm --version"`

View File

@@ -0,0 +1,9 @@
#!/bin/bash
set -e
# Load nvm before executing Dockerfile RUN commands
export NVM_DIR="/usr/local/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Execute the command passed to this wrapper
eval "$@"

View File

@@ -0,0 +1,14 @@
#!/bin/bash
set -e
# Load nvm in the entrypoint environment
export NVM_DIR="/usr/local/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# If command is bash -c, inject bashrc sourcing to make nvm available
if [ "$1" = "bash" ] && [ "$2" = "-c" ]; then
shift 2
exec bash -c "source /etc/bash.bashrc && $*"
else
exec "$@"
fi

5
package-lock.json generated
View File

@@ -1,5 +0,0 @@
{
"name": "ht-docker-node",
"version": "5.0.139",
"lockfileVersion": 1
}

View File

@@ -1,6 +1,6 @@
{ {
"name": "ht-docker-node", "name": "ht-docker-node",
"version": "5.0.139", "version": "5.1.0",
"description": "A Docker image that integrates Node.js with shipzone.io support.", "description": "A Docker image that integrates Node.js with shipzone.io support.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

9
pnpm-lock.yaml generated Normal file
View File

@@ -0,0 +1,9 @@
lockfileVersion: '9.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.: {}

View File

@@ -1 +1,84 @@
# Technical Implementation Notes
## NVM Support (v5.0.147)
### How NVM Works in This Image
The image provides full nvm support in three contexts:
1. **Dockerfile RUN commands**: Via `/usr/local/bin/bash-with-nvm` wrapper
2. **CI/CD workflow scripts**: Via /etc/bash.bashrc prepended configuration
3. **Interactive shells**: Via /etc/bash.bashrc standard loading
### Key Components
#### 1. /etc/bash.bashrc (Prepended NVM Init)
- NVM initialization is **prepended** to /etc/bash.bashrc
- **Critical**: Placed BEFORE the `[ -z "$PS1" ] && return` line
- This ensures nvm loads in both interactive AND non-interactive bash shells
- Location: Lines 1-3 of /etc/bash.bashrc
#### 2. /usr/local/bin/bash-with-nvm (Build-Time Wrapper)
- Wrapper script that sources nvm before executing Dockerfile RUN commands
- Used via `SHELL ["/usr/local/bin/bash-with-nvm"]` directive
- Ensures nvm is available during `docker build` without manual sourcing
#### 3. /usr/local/bin/docker-entrypoint.sh (Runtime Wrapper)
- ENTRYPOINT that detects `bash -c` commands
- Automatically injects `source /etc/bash.bashrc` for bash -c invocations
- Passes through other commands unchanged
- Critical for CI/CD workflow support
#### 4. ENV PATH Fallback
- Maintains `ENV PATH` pointing to default Node v20.12.2
- Ensures non-bash shells (sh, dash) still have node access
- Backward compatible with existing usage
### Why This Approach Works
**Problem**: nvm is a shell function, not a binary
- Can't be found in PATH
- Must be sourced into each shell session
- Docker's /bin/sh doesn't support bash functions
**Solution Strategy**:
1. Prepend nvm init to /etc/bash.bashrc (before early return)
2. Use wrapper for build-time (SHELL directive)
3. Use ENTRYPOINT for runtime (docker run / CI/CD)
4. Keep ENV PATH for fallback
### Version Persistence Limitation
Each Dockerfile RUN command creates a new shell:
```dockerfile
RUN nvm install 18 # Installs but doesn't persist
RUN node --version # Shows v20.12.2 (ENV PATH)
```
**Workaround**: Chain commands or set default:
```dockerfile
RUN nvm install 18 && nvm alias default 18
RUN node --version # Now shows v18.x.x
```
### Testing Performed
- ✅ Dockerfile RUN: `nvm install`, `nvm use`, version switching
- ✅ Runtime bash -c: All nvm commands work
- ✅ CI/CD workflows: Tested in .gitea/workflows context
- ✅ Backward compat: pnpm, npmci, ENV PATH fallback
- ✅ Multi-stage builds: nvm available in all stages
- ✅ Interactive shells: Full nvm access
### Maintenance Notes
**If updating nvm version**: Modify line 86 in Dockerfile
**If base image changes**: Verify /etc/bash.bashrc structure still has early return pattern
**If ENTRYPOINT conflicts**: Users can override with `--entrypoint` flag:
```bash
docker run --entrypoint /bin/bash image -c "commands"
```

632
readme.md
View File

@@ -1,256 +1,506 @@
# ht-docker-node # 🐳 ht-docker-node
docker image with nodejs and shipzone.io support
## Install > Production-ready Docker images for Node.js development with multi-architecture support, modern runtimes, and intelligent version management.
To get started with `ht-docker-node`, you need to have Docker installed on your machine. You can then pull the desired flavor of the Docker image from the relevant Docker registry. **Multi-arch ready****Alpine & Ubuntu****NVM built-in****Bun, Deno & pnpm****CI/CD optimized**
---
## 🚀 Quick Start
Example:
```bash ```bash
# Pull and run the latest Node.js LTS image
docker pull registry.gitlab.com/hosttoday/ht-docker-node:latest docker pull registry.gitlab.com/hosttoday/ht-docker-node:latest
docker run -it registry.gitlab.com/hosttoday/ht-docker-node:latest
# Or use Alpine for smaller images (200MB vs 800MB+)
docker pull registry.gitlab.com/hosttoday/ht-docker-node:alpine-node
``` ```
## Usage ## 📦 Available Images
`ht-docker-node` offers a variety of Docker image flavors to suit different needs. Below, we'll guide you through different use cases and configurations using these Docker images. ### Ubuntu-Based Images (Full-Featured)
### Flavour Overview Perfect for complex builds requiring native dependencies and maximum compatibility.
- **:lts** - Node LTS version, equivalent to :latest | Tag | Description | Use Case |
- **:stable** - Node stable version |-----|-------------|----------|
- **:npmci** - `npmci` preinstalled | `:latest` / `:lts` | Node.js LTS with NVM | General purpose, production builds |
- **:npmts** - `npmci` + `npmts` preinstalled | `:stable` | Node.js stable release | Latest stable features |
- **:npmpage** - `npmci` + `npmts` + `npmpage` preinstalled | `:npmci` | With npmci preinstalled | CI/CD pipelines |
- **:mongo** - `npmci` + `npmts` + `mongo` | `:npmts` | npmci + npmts | TypeScript projects |
| `:npmpage` | npmci + npmts + npmpage | Static site generation |
| `:mongo` | npmci + npmts + MongoDB | Full-stack development |
### Basic Usage ### Alpine-Based Images (Lightweight & Multi-Arch) ⚡
To start a container with the `lts` flavour, you can use the following command: **40-60% smaller** than Ubuntu images. Native performance on **both x64 and ARM64** (Apple Silicon, ARM servers).
```bash
docker run -it --name your_container_name registry.gitlab.com/hosttoday/ht-docker-node:lts | Tag | Description | Size | Architectures |
|-----|-------------|------|---------------|
| `:alpine-node` | Node.js LTS + NVM + pnpm | ~200MB | amd64, arm64 |
| `:alpine-deno` | Node.js LTS + NVM + Deno | ~180MB | amd64, arm64 |
| `:alpine-bun` | Node.js LTS + NVM + Bun | ~150MB | amd64, arm64 |
**✨ Multi-architecture magic:** Docker automatically selects the right image for your platform. Build on Mac, deploy on Linux servers—same Dockerfile, native speed everywhere.
> **Note:** The Deno image uses Alpine edge to access the official musl-compiled Deno package from Alpine's community repository.
---
## 💡 Key Features
### 🔄 NVM (Node Version Manager) Built-In
Switch Node.js versions **instantly** without rebuilding images:
```dockerfile
FROM registry.gitlab.com/hosttoday/ht-docker-node:latest
# Works directly in RUN commands - no sourcing needed!
RUN nvm install 18.20.0
RUN nvm use 18 && npm install
RUN nvm install 20 && nvm use 20 && npm test
# Set default for subsequent commands
RUN nvm install 19 && nvm alias default 19
``` ```
### Using `npmci` ### 🎯 CI/CD Workflow Ready
The `:npmci` flavour includes `npmci`, a utility for managing Node.js versions and npm installations. Here's an example of how you can use it: NVM works seamlessly in GitHub Actions, GitLab CI, and other automation:
```Dockerfile ```yaml
FROM registry.gitlab.com/hosttoday/ht-docker-node:npmci # .gitlab-ci.yml
RUN npmci install 14.17.0 test:
image: registry.gitlab.com/hosttoday/ht-docker-node:latest
script:
- nvm install 18
- nvm use 18
- npm ci
- npm test
# Test on multiple Node versions
- nvm install 20
- nvm use 20
- npm test
``` ```
In this example, `npmci` installs Node.js version `14.17.0` and sets it as the default. ### 🏔️ Alpine: Production-Optimized
### Custom Dockerfile with `npmci` and your Node.js App ```dockerfile
FROM registry.gitlab.com/hosttoday/ht-docker-node:alpine-node
You can create a custom Dockerfile for your Node.js application using the `:npmci` flavour: # Same NVM commands as Ubuntu
RUN nvm install 20 && nvm use 20
RUN pnpm install
RUN pnpm build
```Dockerfile # Result: 200MB image vs 800MB+ Ubuntu
# Use the ht-docker-node image with npmci ```
FROM registry.gitlab.com/hosttoday/ht-docker-node:npmci
# Install a specific Node.js version **Why Alpine?**
RUN npmci install 14.17.0 -**60-75% smaller images** → Faster deployments
-**Reduced attack surface** → Better security
-**Native musl builds** → No glibc compatibility issues
-**Multi-arch support** → One image, all platforms
# Create app directory ---
WORKDIR /usr/src/app
# Copy package.json and package-lock.json ## 🛠️ Usage Examples
### Basic Node.js Application
```dockerfile
FROM registry.gitlab.com/hosttoday/ht-docker-node:alpine-node
WORKDIR /app
# NVM is already configured, Node.js LTS is ready
COPY package*.json ./ COPY package*.json ./
RUN pnpm install
# Install app dependencies
RUN npm install
# Bundle app source
COPY . .
# Expose port
EXPOSE 8080
# Start the application
CMD ["node", "index.js"]
```
To build the Docker image:
```bash
docker build -t your_app_name .
```
To run the container:
```bash
docker run -p 8080:8080 --name your_container_name your_app_name
```
### Multi-Stage Builds for Production
For a leaner production image, you can use multi-stage builds. Heres an example:
```Dockerfile
# Stage 1: Build
FROM registry.gitlab.com/hosttoday/ht-docker-node:npmci as build
RUN npmci install 14.17.0
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . . COPY . .
RUN npm run build RUN pnpm build
# Stage 2: Production
FROM registry.gitlab.com/hosttoday/ht-docker-node:lts
WORKDIR /usr/src/app
COPY --from=build /usr/src/app/dist ./
EXPOSE 8080
CMD ["node", "index.js"]
```
### Using with MongoDB (`:mongo`)
The `:mongo` flavour contains a MongoDB installation alongside Node.js. Heres how you can utilize it in your Dockerfile:
```Dockerfile
FROM registry.gitlab.com/hosttoday/ht-docker-node:mongo
# Setup mongo and node environment:
RUN npm install -g mongodb
# Working directory
WORKDIR /usr/src/app
# Copy MongoDB config
COPY mongod.conf /etc/mongod.conf
# Start MongoDB service
CMD ["mongod", "--config", "/etc/mongod.conf"] && node index.js
```
### Using `npmts` and `npmpage`
The `:npmts` and `:npmpage` flavours are useful for projects that use TypeScript or require page generation.
Heres an example on how to work with `:npmts`:
```Dockerfile
FROM registry.gitlab.com/hosttoday/ht-docker-node:npmts
# Install necessary TypeScript packages
RUN npm install -g typescript
# Working directory
WORKDIR /usr/src/app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of your files
COPY . .
# Compile TypeScript
RUN npm run build
# Expose port and start the server
EXPOSE 3000 EXPOSE 3000
CMD ["npm", "start"] CMD ["node", "dist/index.js"]
``` ```
### Comprehensive Use Case Example ### Multi-Version Testing
The following example covers multiple aspects including environment variables, volume mounting, and networking. ```dockerfile
FROM registry.gitlab.com/hosttoday/ht-docker-node:latest
#### Dockerfile: WORKDIR /app
```Dockerfile
FROM registry.gitlab.com/hosttoday/ht-docker-node:npmci
# Set environment variables
ENV NODE_ENV=production
ENV PORT=3000
# Install desired Node.js version
RUN npmci install 16.0.0
# Create app directory
WORKDIR /usr/src/app
# Copy package.json and package-lock.json
COPY package*.json ./ COPY package*.json ./
# Install app dependencies # Test on Node 18
RUN npm ci RUN nvm install 18 && nvm use 18 && npm ci && npm test
# Bundle app source # Test on Node 20
COPY . . RUN nvm install 20 && nvm use 20 && npm ci && npm test
# Compile TypeScript # Use Node 20 for production build
RUN npm run build RUN nvm alias default 20 && npm run build
# Expose app port
EXPOSE 3000
# Start the application
CMD ["npm", "start"]
``` ```
#### Docker-Compose Configuration ### Deno Application
If using Docker-Compose, create a `docker-compose.yml` file: ```dockerfile
FROM registry.gitlab.com/hosttoday/ht-docker-node:alpine-deno
WORKDIR /app
# Both Deno and Node.js are available
COPY . .
# Use Deno for the app
CMD ["deno", "run", "--allow-net", "main.ts"]
# Or switch to Node.js if needed
# RUN nvm use default && npm install
```
### Bun for Ultra-Fast Builds
```dockerfile
FROM registry.gitlab.com/hosttoday/ht-docker-node:alpine-bun
WORKDIR /app
# Bun is 10-20x faster for package installation
COPY package.json bun.lockb ./
RUN bun install
COPY . .
RUN bun run build
# Node.js also available via NVM
CMD ["bun", "run", "start"]
```
### TypeScript Project with Multi-Stage Build
```dockerfile
# Build stage
FROM registry.gitlab.com/hosttoday/ht-docker-node:alpine-node AS builder
WORKDIR /app
COPY package*.json ./
RUN pnpm install
COPY tsconfig.json ./
COPY src ./src
RUN pnpm build
# Production stage
FROM registry.gitlab.com/hosttoday/ht-docker-node:alpine-node
WORKDIR /app
COPY package*.json ./
RUN pnpm install --prod
COPY --from=builder /app/dist ./dist
EXPOSE 3000
CMD ["node", "dist/index.js"]
```
---
## 🔧 NVM Usage Patterns
### In Dockerfiles
```dockerfile
# Install specific version
RUN nvm install 18.20.0
# Use version
RUN nvm use 18
# Set default (persists across RUN commands)
RUN nvm alias default 18
# Chain commands in single RUN
RUN nvm install 19 && nvm use 19 && npm install
```
### In CI/CD Scripts
```bash
#!/bin/bash
# NVM is automatically available in bash scripts
nvm install 20
nvm use 20
npm ci
npm test
```
### Version Switching
```bash
# List installed versions
nvm ls
# Install and switch to latest LTS
nvm install --lts
nvm use --lts
# Install specific version
nvm install 18.20.0
# Use installed version
nvm use 18
```
---
## 🏗️ Building Multi-Architecture Images
For teams building custom images:
```bash
# Clone the repo
git clone https://github.com/HostToday/ht-docker-node.git
cd ht-docker-node
# Build Alpine images (native platform for local testing)
chmod +x build-alpine-images.sh
./build-alpine-images.sh
# Test the built images
chmod +x test-alpine-images.sh
./test-alpine-images.sh
```
### Production Multi-Arch Builds
For publishing to registries:
```bash
# Build for both amd64 and arm64, push to registry
docker buildx build \
--platform linux/amd64,linux/arm64 \
-f Dockerfile_alpine_node \
-t your-registry/your-image:alpine-node \
--push \
.
```
---
## 📚 Advanced Examples
### Docker Compose Setup
```yaml ```yaml
version: '3.8' version: '3.8'
services: services:
app: app:
image: your_app_name image: registry.gitlab.com/hosttoday/ht-docker-node:alpine-node
build: working_dir: /app
context: .
dockerfile: Dockerfile
ports:
- '3000:3000'
environment:
- NODE_ENV=production
volumes: volumes:
- .:/usr/src/app - .:/app
- /usr/src/app/node_modules - /app/node_modules
networks: ports:
- app-network - "3000:3000"
environment:
- NODE_ENV=development
command: sh -c "pnpm install && pnpm dev"
networks: mongo:
app-network: image: mongo:latest
driver: bridge ports:
- "27017:27017"
``` ```
#### Running with Docker and Docker-Compose ### GitHub Actions Workflow
To build the image: ```yaml
```bash name: CI
docker-compose build
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
container:
image: registry.gitlab.com/hosttoday/ht-docker-node:alpine-node
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: pnpm install
- name: Run tests
run: pnpm test
- name: Test on multiple Node versions
run: |
for version in 18 20; do
echo "Testing on Node $version"
nvm install $version
nvm use $version
pnpm test
done
``` ```
To run the services: ### Custom Base Image
```bash
docker-compose up ```dockerfile
FROM registry.gitlab.com/hosttoday/ht-docker-node:alpine-node
# Add your custom tools
RUN apk add --no-cache \
python3 \
make \
g++ \
postgresql-client
# Configure your environment
ENV DATABASE_URL="postgresql://localhost/mydb"
# Your app setup
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN pnpm install
COPY . .
CMD ["pnpm", "start"]
``` ```
#### Accessing the Container ---
## 🎓 Best Practices
### ✅ DO
- **Use Alpine images for production** (smaller, more secure)
- **Pin Node versions in production** (`nvm alias default 20.11.0`)
- **Use multi-stage builds** to reduce final image size
- **Leverage build cache** with proper COPY order
- **Run as non-root user** in production
### ❌ DON'T
- Don't use `:latest` tag in production (be explicit)
- Don't install packages globally if local works
- Don't copy `node_modules` (let the build install them)
- Don't skip `.dockerignore` (keeps builds fast)
### 🔒 Security Tips
```dockerfile
# Example: Production-hardened Dockerfile
FROM registry.gitlab.com/hosttoday/ht-docker-node:alpine-node
# Create non-root user
RUN addgroup -g 1001 -S nodejs && adduser -S nodejs -u 1001
WORKDIR /app
# Install deps as root
COPY package*.json ./
RUN pnpm install --frozen-lockfile && pnpm cache clean
# Copy source
COPY --chown=nodejs:nodejs . .
# Build
RUN pnpm build
# Switch to non-root user
USER nodejs
EXPOSE 3000
CMD ["node", "dist/index.js"]
```
---
## 🐛 Troubleshooting
### NVM command not found
If NVM isn't available in your script:
```bash ```bash
docker exec -it your_container_name /bin/sh # Manually source NVM (shouldn't be needed in our images)
export NVM_DIR="/usr/local/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
``` ```
### Conclusion ### Alpine native module build failures
`ht-docker-node` offers a flexible, multifaceted solution for deploying Node.js applications in Docker containers. By leveraging its different flavours, you can efficiently manage Node.js versions, incorporate MongoDB, and handle TypeScript projects. Whether you are using simple Docker commands or elaborate Docker-Compose configurations, `ht-docker-node` caters to diverse deployment scenarios. Some npm packages need build tools:
```dockerfile
FROM registry.gitlab.com/hosttoday/ht-docker-node:alpine-node
# Install build dependencies
RUN apk add --no-cache python3 make g++
# Now install your packages
RUN pnpm install
```
### Permission denied errors
```dockerfile
# Fix ownership before switching users
COPY --chown=node:node . .
USER node
```
---
## 📊 Image Comparison
| Feature | Ubuntu `:latest` | Alpine `:alpine-node` |
|---------|------------------|----------------------|
| Base Size | ~800MB | ~200MB |
| Build Tools | ✅ Full | ⚠️ Install separately |
| Compatibility | ✅ Maximum | ✅ Good (musl) |
| Multi-arch | ❌ amd64 only | ✅ amd64, arm64 |
| Security | ✅ Good | ✅ Excellent (smaller surface) |
| Speed | Fast | Faster (smaller) |
| Use Case | Complex builds | Production, CI/CD |
---
## 🔗 Useful Links
- **GitHub Repository:** https://github.com/HostToday/ht-docker-node
- **Docker Hub:** registry.gitlab.com/hosttoday/ht-docker-node
- **NVM Documentation:** https://github.com/nvm-sh/nvm
- **Alpine Linux:** https://alpinelinux.org/
- **Node.js Unofficial Builds:** https://unofficial-builds.nodejs.org/ (musl support)
---
## 📋 Changelog
See [changelog.md](changelog.md) for detailed version history.
**Latest Updates (v5.0.148):**
- ✨ Multi-architecture Alpine images (amd64 + arm64)
- ✨ Native Deno support via Alpine edge
- ✨ Bun runtime integration
- ✨ Simplified image tags (`:alpine-node` vs `:alpine-x64-node`)
- 🚀 docker buildx integration for cross-platform builds
- 📦 pnpm preinstalled on Alpine Node image
- 🔧 NVM 0.40.1 with improved Alpine/musl support
---
## License and Legal Information ## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file. **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
@@ -260,7 +510,7 @@ This project is owned and maintained by Task Venture Capital GmbH. The names and
### Company Information ### Company Information
Task Venture Capital GmbH Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc. For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

83
test-alpine-images.sh Executable file
View File

@@ -0,0 +1,83 @@
#!/bin/bash
set -e
echo "🧪 Testing Multi-Architecture Alpine Docker Images"
echo "==================================================="
echo ""
# Color codes
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
FAILED_TESTS=0
# Test function
test_image() {
local tag=$1
local description=$2
local test_cmd=$3
echo -e "${BLUE}🧪 Testing: ${NC}${description}"
echo -e "${YELLOW} Tag: ${NC}${tag}"
if docker run --rm "${tag}" bash -c "${test_cmd}"; then
echo -e "${GREEN}✅ Pass${NC}"
echo ""
return 0
else
echo -e "${RED}❌ Fail${NC}"
echo ""
((FAILED_TESTS++))
return 1
fi
}
# Test Alpine Images (Native Platform)
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo -e "${BLUE}Testing Alpine Images (Native Platform)${NC}"
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo ""
echo -e "${YELLOW}💡 These images are built for your native architecture${NC}"
echo -e "${YELLOW} They will run at full native speed without emulation${NC}"
echo ""
test_image "ht-docker-node:alpine-node" \
"Alpine with Node.js LTS + NVM + pnpm" \
"nvm --version && node --version && pnpm --version"
test_image "ht-docker-node:alpine-deno" \
"Alpine with Node.js LTS + NVM + Deno" \
"nvm --version && node --version && deno --version"
test_image "ht-docker-node:alpine-bun" \
"Alpine with Node.js LTS + NVM + Bun" \
"nvm --version && node --version && bun --version"
# Test NVM version switching (critical feature)
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo -e "${BLUE}Testing NVM Version Switching${NC}"
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo ""
test_image "ht-docker-node:alpine-node" \
"NVM version switching" \
"node --version && nvm install 18 && node --version | grep v18"
# Summary
echo -e "${BLUE}════════════════════════════════════════${NC}"
if [ $FAILED_TESTS -eq 0 ]; then
echo -e "${GREEN}✨ All Tests Passed! (0 failures)${NC}"
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo ""
echo -e "${YELLOW}💡 In production, these same images will work natively on both amd64 and arm64${NC}"
echo ""
exit 0
else
echo -e "${RED}❌ Some Tests Failed (${FAILED_TESTS} failures)${NC}"
echo -e "${BLUE}════════════════════════════════════════${NC}"
echo ""
exit 1
fi