Set up the Nexus npm hosted repository
Overview¶
This wiki documents the full setup for building and publishing the TellyboardAdmin frontend using GitLab CI/CD, Nexus npm registry, and Docker multi-platform builds.
Architecture¶
1. Nexus Guide — npm Hosted Repository¶
1.1 Create npm-hosted Repository¶
- Go to
https://nexus.castis.io/#admin/repository/repositories - Click Create repository → select npm (hosted)
- Fill in:
- Name:
npm-hosted - Deployment policy:
Allow redeploy - Click Create repository
Repository URL:
1.2 Add npm-hosted Access Role for CI User¶
- Go to
https://nexus.castis.io/#admin/security/roles - Create a new role:
- Role ID:
npm-hosted-access - Role Name:
npm-hosted-access - Privileges:
nx-repository-view-npm-hosted-read,nx-repository-view-npm-hosted-browse - Assign the role to the
gitlab-ciuser
1.3 Publish @playtelly/design-tokens to Nexus¶
cd tellyboard-frontend/design-tokens
# Build the package
npm install
npm run build:tokens
# Add publishConfig to package.json
# "publishConfig": { "registry": "https://nexus.castis.io/repository/npm-hosted/" }
# Add auth to ~/.npmrc
echo "//nexus.castis.io/repository/npm-hosted/:_auth=$(echo -n 'username:password' | base64)" > ~/.npmrc
# Publish
npm publish
2. Project Configuration¶
2.1 .npmrc (tellyboard-frontend/.npmrc)¶
2.2 Dockerfile (tellyboard-frontend/Dockerfile)¶
# ─────────────────────────────────────────
# Stage 1: Build
# ─────────────────────────────────────────
FROM node:20-alpine AS build
WORKDIR /app
# System dependencies
RUN apk update && apk add --no-cache \
libc6-compat \
python3 \
make \
g++
# Package files
COPY package.json package-lock.json* ./
# Registry auth
ARG NPM_AUTH
RUN echo "//nexus.castis.io/repository/npm-hosted/:_auth=${NPM_AUTH}" > .npmrc && \
echo "//nexus.castis.io:9443/repository/npm-hosted/:_auth=${NPM_AUTH}" >> .npmrc && \
echo "@playtelly:registry=https://nexus.castis.io/repository/npm-hosted/" >> .npmrc
# Install dependencies
ENV ELECTRON_SKIP_BINARY_DOWNLOAD=1
RUN rm -f package-lock.json
RUN npm install --legacy-peer-deps
RUN npm install --legacy-peer-deps @rollup/rollup-linux-arm64-musl --ignore-scripts || true
# Build app
COPY . .
ARG VITE_TELLYID_URL
ENV VITE_TELLYID_URL=$VITE_TELLYID_URL
RUN npm run build
# ─────────────────────────────────────────
# Stage 2: Serve
# ─────────────────────────────────────────
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
2.3 .gitlab-ci.yml¶
# ─────────────────────────────────────────
# Templates
# ─────────────────────────────────────────
.build_template:
stage: build
image: docker:24
services:
- docker:24-dind
script:
- PROJECT_NAME=$(echo $CI_PROJECT_NAME | tr '[:upper:]' '[:lower:]')
- docker login -u $NEXUS_USER -p $NEXUS_PASSWORD $REGISTRY_URL
- docker buildx rm multiarch || true
- docker buildx create --use --name multiarch --node multiarch0
- |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--cache-from $IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-latest \
--tag $IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-$CI_COMMIT_SHORT_SHA \
--tag $IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-latest \
--build-arg NPM_AUTH=$(echo -n "$NEXUS_USER:$NEXUS_PASSWORD" | base64) \
--file tellyboard-frontend/Dockerfile \
--push \
tellyboard-frontend/
# ─────────────────────────────────────────
# Jobs
# ─────────────────────────────────────────
build:staging:
extends: .build_template
variables:
ENV_NAME: staging
environment:
name: staging
rules:
- if: $CI_COMMIT_BRANCH == "staging"
build:production:
extends: .build_template
variables:
ENV_NAME: prod
environment:
name: production
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
2.4 docker-compose.yml (local development)¶
services:
tellyboardadmin:
build:
context: ../../../TellyboardAdmin/tellyboard-frontend
dockerfile: Dockerfile
network: host
args:
VITE_TELLYID_URL: "http://localhost:5174"
NPM_AUTH: ${NPM_AUTH}
extra_hosts:
- "host.docker.internal:host-gateway"
container_name: tellyboard-frontend
ports:
- "5175:80"
networks:
- internal
depends_on:
- coreapi
2.5 .env (local development)¶
Note: Generate with
echo -n "username:password" | base64
3. GitLab CI Variables¶
| Variable | Description |
|---|---|
NEXUS_USER |
Nexus username (e.g. gitlab-ci) |
NEXUS_PASSWORD |
Nexus password |
REGISTRY_URL |
Docker registry URL (e.g. registry.nexus.castis.io) |
IMAGE_BASE |
Base image path (e.g. registry.nexus.castis.io/playtelly) |
4. GitLab Runner Setup¶
4.1 Register a Group Runner¶
- Go to
https://mashup.castis.io/groups/playtelly/-/runners/new - Fill in description, leave tags empty, check Run untagged jobs
- Click Create runner
- SSH into the Digital Ocean server and register:
sudo gitlab-runner register \
--url https://mashup.castis.io \
--token <YOUR_TOKEN>
# executor: shell
4.2 Increase Concurrency¶
sudo sed -i 's/concurrent = 1/concurrent = 4/' /etc/gitlab-runner/config.toml
sudo gitlab-runner restart
5. Nexus Port 9443 Fix¶
Nexus generates tarball URLs with port 9443 internally. Since APISIX handles HTTPS on port 443, port 9443 needs to be exposed.
5.1 Add port 9443 to APISIX on k3s cluster¶
# Add port 9443 to local APISIX configmap
kubectl patch configmap apisix-config -n apisix --type merge -p '{"data":{"config.yaml":"apisix:\n node_listen:\n - 9080\n - 9443\n..."}}'
kubectl rollout restart deployment/apisix -n apisix
# Add port 9443 to local APISIX gateway service
kubectl patch svc apisix-gateway -n apisix --type='json' -p='[
{"op":"add","path":"/spec/ports/-","value":{"name":"npm-ssl","port":9443,"protocol":"TCP","targetPort":9443}}
]'
5.2 Add port 9443 to APISIX on Digital Ocean¶
kubectl patch svc apisix-gateway -n ingress-apisix --type='json' -p='[
{"op":"add","path":"/spec/ports/-","value":{"name":"npm-ssl","port":9443,"protocol":"TCP","targetPort":9443}}
]'
5.3 Set Nexus Base URL (permanent fix)¶
kubectl exec -n nexus <nexus-pod> -- /bin/bash -c \
'echo "nexus.baseUrl=https://nexus.castis.io" >> /nexus-data/etc/nexus.properties'
# Then restart Nexus when memory allows
kubectl rollout restart deployment/nexus -n nexus
Note: Nexus requires ~2.6GB RAM to restart. Ensure enough free memory on the node before restarting.
6. Troubleshooting¶
| Error | Cause | Fix |
|---|---|---|
ECONNREFUSED localhost:4873 |
.npmrc points to local Verdaccio |
Update .npmrc to Nexus URL |
connect ECONNREFUSED port 9443 |
Port 9443 not open | Add port 9443 to APISIX gateway |
E401 Unable to authenticate |
Missing or wrong npm auth | Add _auth to .npmrc for both port 443 and 9443 |
Rollup failed to resolve react-is |
Missing peer dependency | Add react-is to package.json or use --legacy-peer-deps |
| Job stuck in pending | Runner has no concurrent capacity | Increase concurrent in config.toml |
granting entitlement network.host not allowed |
buildkitd config missing | Add /etc/buildkitd.toml with [entitlements] network-host = true |