Skip to content

Creating a Repository Mirror: A Step‐by‐Step Guide

Jefferson edited this page Feb 19, 2024 · 13 revisions

Introduction

While our former webserver supported direct browsing and file downloading, transitioning to an object storage system removed our folder listing feature. If you're interested in mirroring our packages, this guide is tailor-made for you! Though we encourage using our repositories over direct file downloads, knowing how to decipher the path format for various Node.js versions is essential for those preferring the latter. Dive into Deciphering the NodeSource Distribution Server Path Format for insights.

Setting Up an RPM Mirror 🛠️

For Node.js Version >=16x

  1. Install Dependencies and Setup Repo:

    • Modify NODE_MAJOR to reflect your chosen Node.js version.
      # Set the desired Node.js version
      NODE_MAJOR=18
      
      # Install essential tools and set up the repository
      yum install yum-utils createrepo curl -y
      yum install https://rpm.nodesource.com/pub_${NODE_MAJOR}.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y
      
      # Import the signing key for NodeSource packages
      rpm --import /etc/pki/rpm-gpg/NODESOURCE-NSOLID-GPG-SIGNING-KEY-EL
  2. Download Artifacts:

    # Sync and download all packages from the NodeSource Node.js repository
    reposync -g --repoid=nodesource-nodejs -p /var/rpm/
  3. Prepare the Repository: Move to the directory and initialize the repository.

    # Navigate to the downloaded repository's directory
    cd /var/rpm/nodesource-nodejs
    
    # Create metadata for the repository
    createrepo_c --database .
  4. Publish: Make the files available through your HTTP server.

For Node.js Version 14x

  1. Install Dependencies and Key:

    # Get essential tools and NodeSource's signing key
    yum install yum-utils createrepo curl -y
    curl -LSs -o '/etc/pki/rpm-gpg/NODESOURCE-NODEJS-GPG-SIGNING-KEY-EL' https://rpm.nodesource.com/gpgkey/NODESOURCE-NODEJS-GPG-SIGNING-KEY-EL
    
    # Add the key to RPM
    rpm --import /etc/pki/rpm-gpg/NODESOURCE-NODEJS-GPG-SIGNING-KEY-EL
  2. Manual Repo Configuration:

    # Create a repository configuration for NodeSource Node.js packages
    cat << 'EOF' > /etc/yum.repos.d/nodesource-nodejs.repo
    [nodesource-nodejs]
    name=Node.js Packages for Linux RPM based distros - $basearch
    baseurl=https://rpm.nodesource.com/pub_14.x/fc/36/$basearch
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/NODESOURCE-NODEJS-GPG-SIGNING-KEY-EL
    EOF
  3. Download Artifacts:

    # Sync and grab all packages from the NodeSource Node.js repository
    reposync -g --repoid=nodesource-nodejs -p /var/rpm/
  4. Prepare the Repository: Head to the directory and initialize the repository.

    # Navigate to the repository's directory
    cd /var/rpm/nodesource-nodejs
    
    # Generate metadata for the repository
    createrepo_c --database .
  5. Publish: Host the files on your HTTP server.

Setting Up a DEB Mirror 📦

Using Aptly

1. Install aptly

Kick off by ensuring aptly is on your system:

# Get the key for aptly from the keyserver
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A0546A43624A8331

# Refresh the system's package list
apt-get update

# Install aptly tool
apt-get install aptly

📖 Reference: For a comprehensive guide, head to the official aptly download page.

2. Creating the Mirror

Configure the needed keys and generate a mirror from NodeSource:

# Retrieve and save the NodeSource GPG key
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

# Add the key to the list of trusted keys
gpg --no-default-keyring --keyring /etc/apt/keyrings/nodesource.gpg --export | gpg --no-default-keyring --keyring trustedkeys.gpg --import

# Establish a mirror titled "nodesource-distributions" for Node.js 20.x (or modify for your desired version)
aptly -keyring=/etc/apt/keyrings/nodesource.gpg mirror create nodesource-distributions https://deb.nodesource.com/node_20.x nodistro main

3. Updating the Mirror

Ensure your mirror aligns with the main repository:

# Refresh the "nodesource-distributions" mirror
aptly mirror update nodesource-distributions

4. Publishing the Mirror

Prior to providing access to your mirrored packages, generate a snapshot and publish it:

  1. Snapshot Creation

    # Create a snapshot from the "nodesource-distributions" mirror
    aptly snapshot create monday-updates from mirror nodesource-distributions

    🔐 Note: Ensure a GPG key is set up. If missing, either import an existing one or check this guide to establish a new one.

  2. Publish the Snapshot

    # Make the snapshot publicly available, setting up the directory structure
    aptly publish snapshot monday-updates
  3. Serve the Repository

    # Activate the aptly server, granting access to the repository
    aptly serve

📚 Further Reading: For more details and advanced configurations, consult the official aptly documentation.

Using jFrog Artifactory

1. Create a new Remote Repository

  1. Create a Remote repository and select debian as package type
  2. Define the repository name Nodesource
  3. Specify the remote URL https://deb.nodesource.com/node_20.x/
  4. Define Include Patterns **

2. Important Settings

  1. Define repository layout as simple-default
  2. Disable List Remote folder items

image

3.Configure advanced settings, and disable any related feature to listing directories, because currently our repo does not support folder listing.

image

3. Repo configuration example

# Import Nodesource gpg key
mkdir -p /usr/share/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /usr/share/keyrings/nodesource.gpg

# Configure jFrog repo on `sources.list`
deb [trusted=yes signed-by=/usr/share/keyrings/nodesource.gpg] https://MyjfrogRepo.io/artifactory/Nodesource nodistro main

# Install nsolid or nodejs
apt-get update && apt-get install nodejs

📚 Further Reading: For more details and advanced configurations, consult the official jFrog documentation.


Deciphering the NodeSource Distribution Server Path Format

Node.js Version 16 and Later:

  • Example URL: 🔗 Node.js v16 RPM Package

    • 🌐 rpm.nodesource.com: This is the domain for Node.js RPM packages.

    • 🔢 pub_16.x: Denotes the Node.js 16 major version. This covers all minor and patch versions.

    • 📦 nodistro: A universal package fit for any RPM-based distribution.

    • 🔖 nodejs: Refers to the package or category name.

    • 💻 x86_64: Specifies the architecture, typically x86_64 for 64-bit systems.

    • 📄 nodejs-16.20.2-1nodesource.x86_64.rpm: In this case, 16.20.2 highlights the specific Node.js version.

Node.js Version 14:

  • Example URL: 🔗 Node.js v14 RPM Package

    • 🌐 rpm.nodesource.com: Domain for Node.js RPM packages.

    • 🔢 pub_14.x: Marks the Node.js 14 major version.

    • 📜 fc/36: Indicates Fedora 36 distribution version. Yet, even if left out, it's still compatible with most RPM-based distributions.

    • 💻 x86_64: Represents the architecture.

    • 📄 nodejs-14.21.3-1nodesource.x86_64.rpm: Here, 14.21.3 points out the Node.js version.

📝 Friendly Reminder: Even though 'fc/36' is present, it doesn't restrict the package only to Fedora 36. It's versatile and aligns with nearly all RPM-based distributions.