How to enable cache for Satis composer registry in Artifactory - composer-php

I have a problem setting up internal composer registry in artifactory. For a long time we are using satis as a registry for php packages, but currently we slowly moving to artifactory for other languages and want same for php.
I've configured composer remote registry for packagist.org and it works well (expect I don't understand why I need to set github.com as git provider and what will be if it gitlab or something).
Btw I configured one more registry for internal packages, in Registry URL I set our satis url (https://packagist.internal). Now i can install packages from it, but it does not cache files in artifactory and serve it directly from our private repository.
Looks like this:
$ composer i -vvv
...
Downloading https://artifacts.plesk.tech/artifactory/api/composer/composer-internal/packages.json
...
Installs: os/pear:1.0.4
- Downloading os/pear (1.0.4)
Downloading https://packagist.internal/dist/os/pear/os-pear-1.0.4-8d8196.zip
As you can see, it download metadata from artifactory, but artifacts directly from satis, besides I enabled caching in advanced > other > Store Artifacts Locally. In Satis access log I only see requests to json files from artifactory, but not to zip. Also it for some reason trying to request these urls:
GET /api/system/version/service HTTP/1.1" 404 821 "-" "Artifactory/7.39.4 73904900
GET /api/system/version HTTP/1.1" 404 821 "-" "Artifactory/7.39.4 73904900
For packagist.org work as expected:
Installs: psr/log:3.0.0
- Downloading psr/log (3.0.0)
Downloading https://artifacts.plesk.tech/artifactory/api/composer/composer-general-remote/vcs-dists/zip/php-fig/log/fe5ea303b0887d5caefd3d431c3e61ad47037001
[200] https://artifacts.plesk.tech/artifactory/api/composer/composer-general-remote/vcs-dists/zip/php-fig/log/fe5ea303b0887d5caefd3d431c3e61ad47037001

Related

Composer cannot download and install packages in Iran

I live in Iran, in last days because of internet limitations, I couldn't push into GitHub or GitLab, and also I couldn't use composer.
for GitHub and GitLab, I try SSH connection and SSH access key and I have no problems yet!
but I can't use composer.
when I try this
composer create-project laravel/laravel starter-app
I get this
Creating a "laravel/laravel" project at "./starter-app"
Info from https://repo.packagist.org: #StandWithUkraine
Cannot use laravel/laravel's latest version v9.3.8 as it requires PHP ^8.0.2 which is not satisfied by your platform.
Installing laravel/laravel (v8.6.12)
- Downloading laravel/laravel (v8.6.12)
- Downloading laravel/laravel (v8.6.12)
- Downloading laravel/laravel (v8.6.12)
- Downloading laravel/laravel (v8.6.12)
Failed to download laravel/laravel from dist: curl error 28 while downloading https://codeload.github.com/laravel/laravel/legacy.zip/843a4f81eb25b88b225a89d75a2d3c274e81be6b: Operation timed out after 10000 milliseconds with 0 out of 0 bytes received
Now trying to download from source
- Syncing laravel/laravel (v8.6.12) into cache
Cloning failed using an SSH key for authentication, enter your GitHub credentials to access private repos
When working with _public_ GitHub repositories only, head to https://github.com/settings/tokens/new?scopes=&description=Composer+on+DESKTOP-RRHGV12+2022-10-11+1350 to retrieve a token.
This token will have read-only permission for public information only.
When you need to access _private_ GitHub repositories as well, go to https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+DESKTOP-RRHGV12+2022-10-11+1350
Note that such tokens have broad read/write permissions on your behalf, even if not needed by Composer.
Tokens will be stored in plain text in "C:/Users/VIRA-PC03/AppData/Roaming/Composer/auth.json" for future use by Composer.
For additional information, check https://getcomposer.org/doc/articles/authentication-for-private-packages.md#github-oauth
Token (hidden):
I go to this link "https://getcomposer.org/doc/articles/authentication-for-private-packages.md#github-oauth" and generate new token and paste it, but nothing happen and also I can't use composer
also I try this command
composer diagnose
and get this
Checking platform settings: OK
Checking git settings: OK git version 2.29.2
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com oauth access: FAIL
[Composer\Downloader\TransportException] curl error 28 while downloading https://api.github.com/: Operation timed out after 10000 milliseconds with 0 out of 0 bytes received
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: some number with spaces
Dev Public Key Fingerprint: some number with spaces
OK
Checking composer version: FAIL
[Composer\Downloader\TransportException] curl error 28 while downloading https://getcomposer.org/versions: Operation timed out after 10008 milliseconds with 0 out of 0 bytes received
Composer version: 2.4.2
PHP version: 7.4.12
PHP binary path: C:\xampp\php\php.exe
OpenSSL version: OpenSSL 1.1.1h 22 Sep 2020
cURL version: 7.70.0 libz 1.2.11 ssl OpenSSL/1.1.1h
zip: extension present, unzip not available, 7-Zip not available
and I go to C:\users<my-user>\AppData\Roaming\composer and create file "auth.json" and put this into it
{
"github-oauth": {
"github.com": "my token"
}
}
but I can't get or install Laravel or any other package like phpspeadsheet using composer.
you can use this website https://www.vpngate.net/ to get the vpn. and use vpn to update composer.
or you can copy vendor folder form other project and copy it to your project.

Why does go module ssh custom private repo (non-github) config still request https fetch?

I am using Go modules.
In order to use module version, I cannot use local module. For example:
replace locakpkg => ../localpkg v0.1.0
The above will fail because replacement local path cannot have version so far (go 1.15).
Thus, to make the module version work, I decided to use a private ssh repo.
I did search how to make private ssh repo work for two days.
By following many online articles, I did
git config --global url.user#private.com:.insteadOf https://private.com/
go env -w GOPRIVATE=private.com
I found out go get will always do https fetch to check ssl credential. So I configured a https server properly too.
But in the end, I still get an error message:
unrecognized import path "private.com/foo": reading https://private.com/foo?go-get=1: 404 Not Found
I did google this error and found out this spec https://golang.org/ref/mod#vcs-find which says I have to let the server reply with <meta name="go-import" content="root-path vcs repo-url"> for https fetch request.
If there is a way to use git tag versioning in local module packages, I am OK to use local replace in go.mod instead of configuring a private ssh repo.
If the above point is not possible, how to avoid https fetch when I configure a private ssh repo? I think ssh repo has nothing to do with https protocol.
(I am using go 1.15 at linux. The latest stable version while posting this answer)
I solved the problem and posting here, hopefully, this will help other people one day. I don't find any correct answer by my search online.
In short, the answer is to use .git suffix in all places. Without .git suffix, go mod tidy and go get will use https instead of ssh (git).
At Client:
The file ~/.gitconfig (at linux) if you use /repopath/foo.git path at server:
[url "ssh://user#private.com"]
insteadOf = https://private.com
The file ~/.gitconfig (at linux) if you use ~/repopath/foo.git path at server:
[url "user#private.com:"]
insteadOf = https://private.com/
Execute the following to update ~/.config/go/env at linux:
go env -w GOPRIVATE=private.com
In go.mod, it should use
require private.com/repopath/foo.git v0.1.0
In file.go, it should be
import private.com/repopath/foo.git
At SSH Server
in foo.git/go.mod at private server should have:
module private.com/repopath/foo.git
And make sure the git repo at server has tag version v0.1.0. Don't forget to use git push --tags at client to update the tag version to the server. Without --tags, tag version will not be pushed.
After adding .git suffix to all the required places, go mod tidy and go get will no longer send https request.

How to use artifactory as proxy to get a package?

I've really tried to understand artifactory and to use artifactory as a proxy to get packages and files from public registries and github but haven't got it to work yet.
Github repository key in artifactory:
github.com
File I want:
https://github.com/nvm-sh/nvm/archive/v0.37.2.tar.gz
I have tried to reach it through a machine with command:
wget https://artifactoryenterprise.corp.com/github.com/nvm-sh/nvm/archive/v0.37.2.tar.gz
But it just timed out.
I'm not sure if it is relevant now, but I assume the issue is with the repo key "github.com" which is causing the DNS resolution difficult. Can you test out by creating a generic remote repository with repo key as "githubcom" and wget the file as below
wget https://artifactoryenterprise.corp.com/artifactory/githubcom/nvm-sh/nvm/archive/v0.37.2.tar.gz

Artifactory bundle install '/versions' file not found

We are running a local Artifactory Pro installation and have rubygems.org configured as a Remote Repository.
When running bundle install in a CI Job, the local Artifactory Instance does return a 404 File not found when querying for the /versions file. When doing a manual lookup in the Remote (&Cache) Repo, the file >is present<.
The path we pass to bundle install is provided by the Set me up Wizard and looks like this:
https://$rtf-instance.com/artifactory/api/gems/gems-remote/versions
This was mentioned in an issue here: https://www.jfrog.com/jira/browse/RTFACT-16005
and should have been fixed, but it is still not working in our installation.
Can't find any mention of RTFACT-16005 or the related RTFACT-19012 in the Release Notes.
Repo is setup with default values, no additional config done.
Are we missing something?
Environment:
debian 10 (buster)
nginx 1.14.2
artifactory-pro 7.15.4 / 7.15.3
To enable the gems compact index support you need to add the following system property (under $JFROG_HOME/var/etc/artifactory/artifactory.system.properties):
artifactory.gems.compact.index.enabled=true
You will need to restart Artifactory afterward.
This can be found in JFrog Wiki, here: https://www.jfrog.com/confluence/display/JFROG/RubyGems+Repositories#RubyGemsRepositories-RetrievingLatestRubyGemsPackageCompatiblewithYourRubyVersions

Laravel Spark - Cannot connect to repo

So, I recently made two big changes ... moved my code from bitbucket to github, and set up a pipeline on heroku with a new staging app (original app is now production).
I got a new github token and placed it into the auth.json file as was done with the previous bitbucket repo (it's a private repo). However, when I push to heroku to build the code with composer there, I cannot connect with the laravel spark repo.
Error:
Installing laravel/spark (v3.0.5): Downloading (failed) Failed to download laravel/spark
from dist: The "https://api.github.com/repos/laravel/spark/zipball/512af184c15d793c33328ff03313553ea6feacba"
file could not be downloaded (HTTP/1.1 404 Not Found)
Now trying to download from source
Installing laravel/spark (v3.0.5): Cloning 512af184c1
[RuntimeException]
Failed to execute git clone --no-checkout 'https://***:***#github.com/laravel/spark.git' '/tmp/build_9916d292e7eb72e0fbe34f47e3d9854c/vendor/laravel/spark' && cd '/tmp/build_9916d292e7eb72e0fbe34f47e3d9854c/vendor/laravel/spark' && git remote add composer 'https://***:***#github.com/laravel/spark.git' && git fetch composer
remote: Repository not found.
fatal: repository 'https://***:***#github.com/laravel/spark.git/' not found
What I have tried ...
Setting the github api token on heroku with
heroku config:set GITHUB_API_TOKEN=<token>
Setting the composer github token
composer config -g github-oauth.github.com <token>
I am connected to the Laravel Spark repo on github and when I run composer on my local machine I am not prompted for a spark token. Every other dependency that I have runs fine - I can change the auth.json and that is not the case, so I don't think this is a problem with lack of access to my github.
Does anyone know how Laravel - Spark checks to grant access and how we can check to see where we are going wrong? There should be a checklist of things that can be looked at if access is denied.
Any help is appreciated. Been stuck for almost a week. I really need some way to figure out how to connect to the Spark repo.
(Edit) Spark is a composer satis repo. I can't really find any info on how to prompt this type of repo to tell me why I can't clone it or how best to communicate with it.
(Edit 2) Also tried changing the git config to ensure that it had the right token. This should be overwritten by the files, but I tried it anyway.
git config github.accesstoken <token>
The response from the software providers is to use an alternative method and place the code under my source control so that composer is not trying to load it. I do not wish to do this for a number of reasons. Again, I need a way to clone the satis repo in composer.
Edit 3: I have also tried going to the URL of the repo and attempting to access one of the versions. This displays the same error as when you go to the URL in the error directly (it's the same URL).
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/contents/#get-archive-link"
}
This seems to back up the belief that this is not a composer issue, but something to do with a github setting or spark setting.
Edit 4: It occurred to me that my problems started after upgrading to V6 and I am getting denied access to the spark repo containing versions 1-5 and version 6 is separate. I upgraded my spark version to 6 and had access to that repo. I then tried uploaded the code base to heroku that had version 6 but was denied access to the repo there.
I also tried ...
heroku config:set github_oauth=<token>
Edit 5: I noticed that the output from pushing to heroku included the phrase
NOTICE: Using $COMPOSER_GITHUB_OAUTH_TOKEN for GitHub OAuth.
In response, I found an article asserting that the oauth token should be set in the config portion of composer.json as ...
"config": {
"github-oauth": {
"github.com": "<token>"
}
}
I tried it, but it didn't work
So, it turns out there were several issues. The final big one was that for some reason, I had to delete my api personal token used for github access and create a new one with full privileges for everything. Once that was set up, I had access and was able to reduce the privileges to repo only.
https://github.com/ladybirdweb/agorainvoicing Use open source Agora Invoicing software. It has all the tools you need to start software selling business. It is build on Laravel framework and is very similar to Laravel Spark

Resources