<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andrey Popov</title>
    <description>The latest articles on DEV Community by Andrey Popov (@andpopov).</description>
    <link>https://dev.to/andpopov</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F981874%2F185947ca-717f-46ea-b59f-45fc28ea7b7c.png</url>
      <title>DEV Community: Andrey Popov</title>
      <link>https://dev.to/andpopov</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/andpopov"/>
    <language>en</language>
    <item>
      <title>Deployment of NPM Repositories with Artipie</title>
      <dc:creator>Andrey Popov</dc:creator>
      <pubDate>Wed, 21 Dec 2022 12:44:17 +0000</pubDate>
      <link>https://dev.to/andpopov/deployment-of-npm-repositories-with-artipie-30co</link>
      <guid>https://dev.to/andpopov/deployment-of-npm-repositories-with-artipie-30co</guid>
      <description>&lt;p&gt;In this article I, am going to demonstrate how to deploy your own NPM-repository server by using Artipie.&lt;/p&gt;

&lt;p&gt;I will show how to configure and start a new NPM repository, how to use the standard NPM tool for publishing an NPM package to the Artipie NPM repository, and how to install an NPM package after obtaining it from the Artipie NPM repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction of Artipie
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/artipie"&gt;Artipie&lt;/a&gt; is a free open-source binary artifact management tool project under an MIT license.&lt;/p&gt;

&lt;p&gt;Artipie is a rapidly growing project that was born in 2020. It currently supports a large number of repository types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NPM - for storing and sharing Node JS packages.&lt;/li&gt;
&lt;li&gt;Docker - Docker registry for images.&lt;/li&gt;
&lt;li&gt;RPM – a repository of .rpm files for RHEL, CentOs, Fedora, PCLinuxOS, AlmaLinux, openSUSE, OpenMandriva, Oracle Linux, etc.&lt;/li&gt;
&lt;li&gt;Debian - repository packages for Debian-based Linux distros (Debian, Mint, Ubuntu, MX Linux, Raspberry Pi OS, Parrot OS, etc).&lt;/li&gt;
&lt;li&gt;Go – for storing Go packages.&lt;/li&gt;
&lt;li&gt;Maven - Java, Kotlin, Groovy, Scala, Clojure artifacts of types such as .jar, .war, .klib, etc.&lt;/li&gt;
&lt;li&gt;PyPI - Python packages index.&lt;/li&gt;
&lt;li&gt;Anaconda - packages for data science for Python, R, Lua, C, C++, and other languages.&lt;/li&gt;
&lt;li&gt;HexPM - for storing and sharing packages for Elixir and Erlang languages.&lt;/li&gt;
&lt;li&gt;Gem – a hosting service of RubyGem for Ruby language.&lt;/li&gt;
&lt;li&gt;Helm - Helm charts repository.&lt;/li&gt;
&lt;li&gt;NuGet - .NET package hosting service.&lt;/li&gt;
&lt;li&gt;Composer - PHP source packages.&lt;/li&gt;
&lt;li&gt;Binary (files) storage - for hosting any type of file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Artipie is flexible enough to support custom configurations, so you can use it like a “Lego constructor” by organizing your own repository or multiple repositories for storing your artifacts.&lt;/p&gt;

&lt;p&gt;Artipie consists of the following main parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Storage - keeps artifacts in some source of data, for example, it can store artifacts in a file system or in Amazon S3.&lt;/li&gt;
&lt;li&gt;Repository - understands the format of some types of artifacts and organizes work with these types of artifacts. For example, there is an NPM repository type that can work with NPM packages and NPM tools.&lt;/li&gt;
&lt;li&gt;Artipe engine - server of Artipie.&lt;/li&gt;
&lt;li&gt;Artipie frontend - provides a web-based dashboard to control repository configurations.&lt;/li&gt;
&lt;li&gt;Artipie REST API – provides REST services and Swagger UI to control all aspects of Artipie.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Atripie supports the following types of storage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;File system storage&lt;/li&gt;
&lt;li&gt;Amazon S3 storage&lt;/li&gt;
&lt;li&gt;Redis storage&lt;/li&gt;
&lt;li&gt;Custom storage type&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Artipie engine is designed as a binary artifact’s storage management system for high loads. Artipie engine design follows the principles of a reactive approach that supposes the usage of asynchronous files and network operations.&lt;/p&gt;

&lt;p&gt;Artipie provides access control means through users and groups, and permissions can be assigned to users and groups for specific resources and operations.&lt;/p&gt;

&lt;p&gt;Artipie provides two kinds of repository layouts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;flat&lt;/strong&gt;, where all artifacts lay in one repository&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;org&lt;/strong&gt;, where artifacts are organized as a set of separate user repositories.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To get more information about Artipie please visit the &lt;a href="https://github.com/artipie/artipie"&gt;github&lt;/a&gt; and &lt;a href="https://github.com/artipie/artipie/wiki"&gt;wiki&lt;/a&gt; pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preparation of NPM Repository
&lt;/h2&gt;

&lt;p&gt;Artipie is a java application and there are two ways to launch it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As a Java application from a JAR file&lt;/li&gt;
&lt;li&gt;As a container in Docker Engine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, I use Docker Engine as a deployment environment for Artipie NPM-repository.&lt;/p&gt;

&lt;p&gt;Therefore, you should ensure that &lt;a href="https://docs.docker.com/get-docker/"&gt;Docker Engine&lt;/a&gt; has already been installed on your workstation.&lt;/p&gt;

&lt;p&gt;I use the Windows 10 operating system on my workstation, but you can use either Unix/Linux/MacOs operating system that supports Docker Engine.&lt;/p&gt;

&lt;p&gt;I am going to store all the configuration files and NPM packages inside the folder &lt;code&gt;C:\artipie&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, I store two configuration files in the &lt;code&gt;C:\artipie&lt;/code&gt; folder: one for the Artipie engine and the second one for the NPM repository.&lt;/p&gt;

&lt;p&gt;The Artipie engine configuration file is located at the path: &lt;code&gt;C:\artipie\config\artipie.yml&lt;/code&gt; and defines the following parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;type: fs&lt;/strong&gt;
The storage type, where &lt;code&gt;fs&lt;/code&gt; indicates the use of the file storage type for storing artifacts in the file system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;path: /var/artipie/repo&lt;/strong&gt;
Specifies the path to the directory that stores configurations of all repositories, including the NPM repository configuration mentioned in this article.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;layout: flat&lt;/strong&gt;
The artifact’s layout definition, ‘flat’ means to store all artifacts in one directory of storage.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Listing of &lt;code&gt;C:\artipie\config\artipie.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;meta:
  storage:
    type: fs
    path: /var/artipie/repo #path to repository configurations
  layout: flat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The NPM repository configuration file is located at the path: &lt;code&gt;C:\artipie\repo\my-npm.yaml&lt;/code&gt; and it defines the following parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;type: npm&lt;/strong&gt;
The type of repository here is &lt;code&gt;npm&lt;/code&gt; for the deployment of the NPM repository.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;url: &lt;a href="http://localhost:8080/my-npm"&gt;http://localhost:8080/my-npm&lt;/a&gt;&lt;/strong&gt;
The URL of the repository. It indicates the HTTP endpoint to access the NPM repository by using the &lt;code&gt;npm&lt;/code&gt; command tool.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;path: /var/artipie/packages&lt;/strong&gt;
Specifies the path where the published NPM packages should be stored.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;permissions:&lt;/strong&gt;
Configures access permissions on the NPM repository’s artifacts, including “democratic” permissions that allow everyone to download and publish NPM packages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Listing of &lt;code&gt;C:\artipie\repo\my-npm.yaml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;repo:
  type: npm
  url: http://localhost:8080/my-npm
  storage:
    type: fs
    path: /var/artipie/packages
  permissions:
    "*":
      - download
      - publish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Resulting file-tree view of configuration files and directories on my local workstation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\artipie
  config/
      artipie.yml
  repo/
      my-npm.yaml
  packages/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are ready to launch Artipie as a container of the Docker Engine.&lt;/p&gt;

&lt;p&gt;Run following command in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run \
-v C:\artipie\config:/etc/artipie/ \
-v C:\artipie\repo:/var/artipie/repo \
-v C:\artipie\packages:/var/artipie/packages \
-p 8081:8080
artipie/artipie:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command starts the Artipie engine as a container application inside Docker Engine. The command mounts 3 local directories to the Docker container as volumes, and forwards the local port 8081 to the container’s port 8080:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Artipie engine expects to find its main configuration file inside the &lt;code&gt;/etc/artipie/&lt;/code&gt; directory. Therefore we mount the local directory &lt;code&gt;C:\artipie\config&lt;/code&gt; to &lt;code&gt;/etc/artipie/&lt;/code&gt; container’s directory.&lt;/li&gt;
&lt;li&gt;The Artipie engine looks up repository configurations inside the directory &lt;code&gt;/var/artipie/repo&lt;/code&gt; so we mount the local directory &lt;code&gt;C:\artipie\repo&lt;/code&gt; to it.&lt;/li&gt;
&lt;li&gt;Published NPM packages are stored in the directory &lt;code&gt;/var/artipie/packages&lt;/code&gt;. Therefore, we mount the local directory &lt;code&gt;C:\artipie\packages&lt;/code&gt; to it.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Publishing of package
&lt;/h2&gt;

&lt;p&gt;Now we have started the Artipie engine and deployed an NPM repository. Let’s create a new NPM package and publish it to the NPM repository.&lt;/p&gt;

&lt;p&gt;I created a NodeJS package folder: &lt;code&gt;C:\workdir\@hello\simple-npm-project\&lt;/code&gt; and stored two files of the package: &lt;code&gt;index.js&lt;/code&gt; and &lt;code&gt;package.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Listing of the &lt;code&gt;index.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("Hello world");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Listing of &lt;code&gt;package.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "@hello/simple-npm-project",
  "version": "1.0.1",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" &amp;amp;&amp;amp; exit 1"
  },
  "author": "",
  "license": "ISC"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now go to the &lt;code&gt;C:\ workdir&lt;/code&gt; folder and run following command in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm publish @hello\simple-npm-project --registry http://localhost:8081/my-npm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The parameter &lt;code&gt;--registry&lt;/code&gt; is required to specify Artipie’s NPM repository.&lt;/p&gt;

&lt;p&gt;Using the preceding command publishes the ‘&lt;a class="mentioned-user" href="https://dev.to/hello"&gt;@hello&lt;/a&gt;/simple-npm-project’ NPM package to Artipie’s NPM repository.&lt;/p&gt;

&lt;p&gt;The published NodeJS package can be found inside the folder &lt;code&gt;C:\artipie\packages&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing the package
&lt;/h2&gt;

&lt;p&gt;Let’s install the package ‘&lt;a class="mentioned-user" href="https://dev.to/hello"&gt;@hello&lt;/a&gt;\simple-npm-project’ by using the standard command ‘npm install’:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @hello/simple-npm-project --registry http://localhost:8081/my-npm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The parameter &lt;code&gt;--registry&lt;/code&gt; is required for specifying Artipie’s NPM repository.&lt;/p&gt;

&lt;p&gt;The preceding command downloads the NPM package from the Artipie NPM repository and installs a working project.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;The article demonstrates the simplicity and flexibility usage of using Artipie to deploy a custom configuration of the NPM repository and the interaction with the deployed NPM repository by using the standard &lt;code&gt;npm&lt;/code&gt; tool.&lt;/p&gt;

&lt;p&gt;Files used in the article are available &lt;a href="https://github.com/andpopov/artipie_npm_repository_examples"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>node</category>
      <category>repository</category>
      <category>npm</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
