Andy
Andy

Reputation: 2140

How can I use Artifactory as a caching proxy for my PHP composer dependencies from packagist?

I want to use Artifactory as a caching proxy for my PHP composer dependencies.

I have been able to manually create a remote repository and configure composer to use Artifactory instead of packagist.

The problem is that my project has a lot of dependencies (because dependencies have dependencies).

It's going to be impossible to use Artifactory if I have to do this manually.

How can I create a mirror of all my dependencies (including indirect dependencies) starting from my composer.json?

Upvotes: 2

Views: 1672

Answers (2)

Eyal Ben Moshe
Eyal Ben Moshe

Reputation: 2425

JFrog CLI can help in setting up automation for managing your Artifactory repositories. You can create, update and delete local, remote and virtual Artifactory repositories. Here's what you need to do:

1. Install JFrog CLI

Install JFrog CLI from https://jfrog.com/getcli/

2. Configure your JFrog instance

Configure the connection details of your JFrog instance by running the following command:

jfrog c add my-instance

3. Create a repository template

Run the following command:

jfrog rt rpt repo-conf-template.yml

This command will create a template file named repo-conf-template.yml in the current directory, with your repository configuration. This is an interactive command, which prompts you with a series of questions. You have the option of using variables as values for the questions. For example, when prompted to provide the Repository Key, you can provide ${my-repo-key} as the value. This allows replacing the variable my-repo-key with any repository key value, when the template is used. This way, you can use the exact same configuration, to create a new repository, and only set a new repository key every time.

4. Creating, updating or deleting a repository

Now that you have the template ready, you can use it to create and update repositories as part of your automation scripts. Let's say that you'd like to create a repository using the repo-conf-template.yml template you created, which includes the ${my-repo-key} variable for the repository key. You should then use the jfrog rt rc command as follows.

jfrog rt rc repo-conf-template.yml --vars "my-repo-key=my-actual-repo-name"

Note that you can set values for multiple variables, by using the following format for --vars using the following format:

--vars "key1=value1;key2=value2;..."

You can use the similarly the jfrog rt ru to update a repository using a template. To delete this repository, run the jfrog rt rdel as follows.

jfrog rt rdel my-actual-repo-name

Read more about managing repositories with JFrog CLI here

Upvotes: 1

yinon
yinon

Reputation: 1554

A remote repository in Artifactory is usually used to mirror another repository / registry, serving multiple packages. There shouldn't be a need to setup a new remote repository for each dependency (i.e. package).

Since the majority of the packages in packagist.org are served from github.com, configuring a single remote repository that resolves the registry index files from packagist and the binaries from github should be enough.

If you depend on packages which are not hosted in github, you can simply add an additional remote repository that mirrors that other git provider. In this case you should also define a virtual repository that aggregates all the relevant repositories and use that one to resolve your dependencies.

For more details - see the documentation for PHP Composer Remote Repositories.

Upvotes: 2

Related Questions