doc/user/packages/package_registry/enterprise_structure_tutorial.md
As your organization grows, package management can become increasingly complex. The GitLab package registry model offers a powerful solution for enterprise package management. Understanding how to leverage the package registry is important to working with packages securely, simply, and at scale.
In this tutorial, you'll learn how to incorporate the GitLab package registry model into an enterprise group structure. Although the examples provided here are specific to Maven and npm packages, you can extend the concepts of this tutorial to any package supported by the GitLab package registry.
When you finish this tutorial, you'll know how to:
You'll need the following to complete this tutorial:
Traditional package managers like JFrog Artifactory and Sonatype Nexus use a single, centralized repository to store and update your packages. With GitLab, you manage packages directly in your group or project. This means:
Because your packages are stored and managed like code, you can add package management to your existing projects or groups. This model offers several advantages:
Consider organizing your code under a single top-level group. For example:
company/ (top-level group)
├── retail-division/
│ ├── shared-libraries/ # Division-specific shared code
│ └── teams/
│ ├── checkout/ # Team publishes packages here
│ └── inventory/ # Team publishes packages here
├── banking-division/
│ ├── shared-libraries/ # Division-specific shared code
│ └── teams/
│ ├── payments/ # Team publishes packages here
│ └── fraud/ # Team publishes packages here
└── shared-platform/ # Enterprise-wide shared code
├── java-commons/ # Shared Java libraries
└── ui-components/ # Shared UI components
In this structure, all the teams in a company publish code and packages to their own projects,
while inheriting the configurations of the top-level company/ group.
You can use an existing top-level group if you have one, and you have the Owner role.
If you don't have a group, create one:
This group will store the other groups and projects in your organization. If you have other projects and groups, you can transfer them to the new top-level group for management.
Before you move on, make sure you have at least:
To maintain clear ownership, teams should publish packages to their own package registries. This keeps packages with their source code and ensures version history is tied to project activity.
{{< tabs >}}
{{< tab title="Maven projects" >}}
To publish Maven packages:
Configure your pom.xml file to publish to the project's package registry:
<!-- checkout/pom.xml -->
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
</repository>
</distributionManagement>
{{< /tab >}}
{{< tab title="npm projects" >}}
To publish npm packages:
Configure your package.json file:
// ui-components/package.json
{
"name": "@company/ui-components",
"publishConfig": {
"registry": "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/"
}
}
{{< /tab >}}
{{< /tabs >}}
Because your projects are organized under a single top-level group, your packages are still accessible to the organization. Let's configure a single API endpoint for your teams to consume packages from.
{{< tabs >}}
{{< tab title="Maven projects" >}}
Configure your pom.xml to access packages from the top-level group:
<!-- Any project's pom.xml -->
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.example.com/api/v4/groups/company/-/packages/maven</url>
</repository>
</repositories>
{{< /tab >}}
{{< tab title="npm projects" >}}
Configure your .npmrc file:
# Any project's .npmrc
@company:registry=https://gitlab.example.com/api/v4/groups/company/-/packages/npm/
{{< /tab >}}
{{< /tabs >}}
This configuration automatically provides access to all packages across your organization while maintaining the benefits of project-based publishing.
Next, add a read-only deploy token. This token provides access to the packages stored in the subgroups and projects of the organization, so your teams can use them for development.
read_repository.You can add as many deploy tokens to your top-level group as you need. Remember to rotate your tokens periodically. If you suspect a token has been exposed, revoke and replace it immediately.
When CI/CD jobs need to access the package registry, they authenticate with the predefined CI/CD variable
CI_JOB_TOKEN. This authentication happens automatically, so you don't need to do any extra configuration:
publish:
script:
- mvn deploy # For Maven packages
# or
- npm publish # For npm packages
# CI_JOB_TOKEN provides automatic authentication
Organizing your GitLab projects under one top-level group confers several benefits:
The GitLab package registry model offers a powerful solution for enterprise package management. By combining project-based publishing with top-level group consumption, you get the best of both worlds: clear ownership and simplified access.
This approach scales naturally with your organization while maintaining security and ease of use. Start by implementing this model with a single team or division, and expand as you see the benefits of this integrated approach. Remember that while this tutorial focused on Maven and npm, the same principles apply to all package types supported by GitLab.