Swift Registry

JFrog Artifactory Documentation

ft:sourceType
Paligo

Overview

From JFrog Artifactory version 7.41.4, Artifactory provides full support for managing Swift packages. Aggregating multiple Swift registries under a virtual repository Artifactory provides access to all your Swift packages through a single URL for both upload and download.

Swift Version Support

Artifactory supports Swift version 5.7 and above.

Did you know?

Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns.

The Swift Package Manager: A tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

Swift repository (Catalog): https://swiftpackageregistry.com/ is a catalog of Git repositories, each containing a Swift package. The Swift package manager is an open-source project for managing the distribution of source code, aimed at making it easy to share code and reuse others’ code. The tool compiles and links Swift packages, managing dependencies, versioning, and supporting flexible distribution and collaboration models. For more information, see Swift Package Manager.

As a fully-fledged Swift registry on top of its capabilities for advanced artifact management, Artifactory's support for Swift provides:

  • Calculation of Metadata for Swift packages hosted in Artifactory's local repositories.

  • Access to remote registries through Remote Repositories which provide the usual proxy and caching functionality.

  • The ability to access multiple Swift registries from a single URL by aggregating them under a Virtual Repository. This overcomes the limitation of the Swift client which can only access a single registry at a time.

  • Compatibility with the Swift command line tool to deploy and remove packages and more.

  • Support for validating remote Swift repository metadata.

Swift Repository Structure

The Swift package structure is as follows.

├── Package.swift ├── README.md ├── Sources

│ └─ Hello │ └── hello.swift └── Tests └─ HelloTests └── helloTests.swift └─ LinuxMain.swift

Deployment Structure

All deployment of Swift packages into Artifactory can be deployed under the following structures:

  • <SCOPE>/<NAME>/<NAME>-<VERSION>.zip structure.

  • <scope>/<name>/<version>: Based on the following Swift Publish API.

Note that the packages have to be deployed according to this structure, otherwise they will not be included in the index file.

Setting up a Swift Registry

You can set up the following repository types:

Follow the steps according to each repository type below.

You can download packages from a local, remote, or virtual Swift registry.

Setting up a Local Repository

Local repositories enable you to deploy Swift (.swift) packages. Artifactory calculates the metadata for all packages and indexes them to allow users to download these packages through the Swift client.

Prerequisite

Artifactory allows you to define any layout for your Swift registries. In order to upload packages according to your custom layout, you need to package your Swift files using the Swift source archive. This creates the .zip file for your package which you can then upload to any path within your local Swift repository.

To create a Swift local repository:

  1. Navigate to the Administration module, and go to Repositories | Repositories | Local | New Local Repository.

  2. Select Swift as the Package Type.

    swift_repositories in Package types.png
Setting up a Remote Repository

Note

Swift Remote repositories are currently only supported as Smart Remote repositories. Artifactory is the only Swift registry available today, so you would not be able to proxy other remote resources.

Please note that Swift remote repositories can only connect to registries that utilize the swift protocol. URLs such as swiftpackageregistry.com are considered HTML catalogs, since they do not host any actual packages and simply point to a third-party Git repository.

A Remote Repository defined in Artifactory serves as a caching proxy for a registry managed at a remote URL. Artifacts (such as .zip files) requested from a remote repository are cached on demand. You can remove downloaded artifacts from the remote repository cache, however, you can not manually deploy artifacts to a remote swift registry.

Remote Repositories enable you to proxy and cache Swift packages.

To define a remote repository to proxy a remote swift registry:

  1. In the Administration module, under Repositories | Repositories | Remote, click New Remote Repository.

  2. On the New Remote Repository page:

    1. Set the Package Type to Swift and the Repository Key value.

    2. Specify the URL to the remote registry in the URL field.

    3. Click Save & Finish.

Setting up a Virtual Repository

A Virtual Repository defined in Artifactory aggregates packages from both local and remote repositories.

This allows you to access both locally hosted Swift packages and remote proxied Swift repositories from a single URL defined for the Virtual Repository.

To define a virtual Swift repository, do the following:

  1. In the Administration module, under Repositories | Repositories | Virtual, click New Virtual Repository.

  2. In the New Virtual Repository dialog, set the Package Type to Swift.

  3. Select the underlying local and remote Swift registries to include in the Basic settings tab.

  4. Click Save & Finish to create the repository.

Configuring the Swift Client to work Opposite Artifactory

To use Artifactory with your Swift CLI, you will need to generate an access token. Then you can proceed to resolve and deploy the relevant Swift package.

  1. Navigate to Application Module | Artifactory | Artifacts.

  2. Select the desired repository.

  3. Select Set Me Up and follow the instructions. You can log in to your client using one of these methods:

    • Log in with your username and password.

    • Log in using an authentication token in your Swift login command.

      Note

      From Artifactory version 7.55.1, Swift 5.8 is supported with authentication support. For more information, see the Swift Documentation.

      To log in using an authentication token:

      1. To set your Swift registry, run the following command:

        swift package-registry set --global https://example.com/artifactory/api/swift/swift-local
      2. To login to the registry using Swift, run the following command:

        swift package-registry login https://example-registry.com \
            --username jappleseed \
            --password alpine \

        This will create the .swiftpm/configuration/registries.json file as:

        {
          "registries": {
            "[default]": {
              "url": "https://example-registry.com"
            }
          },
          "authentication": {
            "example-registry.com": {
              "type": "basic"
              "loginAPIPath": "artifactory/api/swift/swift-local"
            }
          },
          "version": 1
        }

Starting from Swift version 5.8, you can use the new Swift login command. For more information, see the Swift Documentation.

To use the new Swift login:

  1. To set your Swift registry, run the following command:

    swift package-registry set --global https://example.com/artifactory/api/swift/swift-local
  2. To login to the registry using Swift, run the following command:

    swift package-registry login https://example-registry.com \
        --username jappleseed \
        --password alpine \
  3. This will create the .swiftpm/configuration/registries.json file as:

    {
      "registries": {
        "[default]": {
          "url": "https://example-registry.com"
        }
      },
      "authentication": {
        "example-registry.com": {
          "type": "basic"
          "loginAPIPath": "artifactory/api/swift/swift-local"
        }
      },
      "version": 1
    }

Configuring the Swift Client to Work With HTTP

By default, the Swift Client only works with HTTPS protocol. If you attempt to configure the client with an HTTP URL, you will get the following error:

Error: invalid URL:<URL>

To modify the Swift client to work with the HTTP protocol, do the following:

  1. To set Artifactory as a Swift repository, run the following command using an HTTPS URL:

    swift package-registry set <url>

    This creates the .swiftpm/configuration/registries.json file, which contains the following information:

    {
      "registries" : {
        "[default]" : {
          "url" : "<url to RT>/artifactory/api/swift/swift-local"
        }
      },
      "version" : 1
    }
  2. Modify the URL in the <url to RT> field in the .swiftpm/configuration/registries.json file to HTTP instead of HTTPS.

Searching for Swift Packages

You can search for Swift Packages, using the Artifact Package Search.

search swift packages.png

Re-Indexing a Swift Repository

You can trigger an asynchronous re-indexing of a local Swift repository either through the UI or using the REST API.

This will also reindex the git index and, as a result, will also index the remote repositories.

In the Artifact Tree Browser, select your Swift repository, right-click and select Recalculate Index from the list. Requires Admin privileges.

To reindex a Swift repository through the REST API refer to the following REST API.

Calculate a Swift Index

Description: Calculates a Swift index for the specified repository.

Notes: Requires Artifactory Pro.

Security: Requires a valid admin user.

Usage: POST /api/swift/{repoKey}/reindex

Produces: application/text

Since: 7.39.4

Sample Output:

POST /api/swift/swift-local/reindex

Reindexing of Swift repository swift-local was scheduled to run.