diff --git a/docs/custom-registries.md b/docs/custom-registries.md index 482737c080..438093b64a 100644 --- a/docs/custom-registries.md +++ b/docs/custom-registries.md @@ -440,10 +440,9 @@ https://github.com/containerbase/php-prebuild/releases/8.3.2/php-8.3.2-jammy-x86 Composer releases are downloaded from: - `https://github.com/containerbase/composer-prebuild/releases` -- `https://getcomposer.org/download` - `https://getcomposer.org/versions` -The first url is preferred and the second is used as fallback for older versions. +The first url is used for downloads. The last url is only used when `latest` or nothing is passed as version. Then we try to find the latest version from getcomposer.org. @@ -452,8 +451,6 @@ Samples: ```txt https://github.com/containerbase/composer-prebuild/releases/2.7.7/composer-2.7.7.tar.xz.sha512 https://github.com/containerbase/composer-prebuild/releases/2.7.7/composer-2.7.7.tar.xz -https://getcomposer.org/download/2.6.6/composer.phar.sha256sum -https://getcomposer.org/download/2.6.6/composer.phar https://getcomposer.org/versions ``` diff --git a/src/cli/tools/php/composer.ts b/src/cli/tools/php/composer.ts index 838ff98583..4bc483e99f 100644 --- a/src/cli/tools/php/composer.ts +++ b/src/cli/tools/php/composer.ts @@ -12,8 +12,7 @@ import { HttpService, PathService, } from '../../services'; -import type { HttpChecksumType } from '../../services/http.service'; -import { logger, semverSort } from '../../utils'; +import { semverSort } from '../../utils'; @injectable() export class ComposerInstallService extends BaseInstallService { @@ -30,63 +29,19 @@ export class ComposerInstallService extends BaseInstallService { override async install(version: string): Promise { const name = this.name; - let filename = `${name}-${version}.tar.xz`; - let url = `https://github.com/containerbase/${name}-prebuild/releases/download/${version}/${filename}`; - let checksumFileUrl = `${url}.sha512`; - const isOnGithub = await this.http.exists(checksumFileUrl); - let file: string; + const filename = `${name}-${version}.tar.xz`; + const url = `https://github.com/containerbase/${name}-prebuild/releases/download/${version}/${filename}`; - if (isOnGithub) { - logger.info(`using github`); - const checksumFile = await this.http.download({ url: checksumFileUrl }); - const expectedChecksum = ( - await fs.readFile(checksumFile, 'utf-8') - ).trim(); - file = await this.http.download({ - url, - checksumType: 'sha512', - expectedChecksum, - }); - } else { - logger.info(`using getcomposer.org`); - // fallback to getcomposer.org - filename = `composer.phar`; - url = `https://getcomposer.org/download/${version}/composer.phar`; - checksumFileUrl = `${url}.sha256sum`; - let expectedChecksum: string | undefined; - let checksumType: HttpChecksumType | undefined; - if (await this.http.exists(checksumFileUrl)) { - logger.debug(`using sha256sum checksum for ${filename}`); - expectedChecksum = await this.readChecksum(`${url}.sha256sum`); - checksumType = 'sha256'; - } else { - throw new Error(`checksum file not found for ${filename}`); - } - - if (!checksumType || !expectedChecksum) { - throw new Error(`checksum not found for ${filename}`); - } - - file = await this.http.download({ - url, - checksumType, - expectedChecksum, - }); - } - - let path = await this.pathSvc.ensureToolPath(this.name); + const checksumFile = await this.http.download({ url: `${url}.sha512` }); + const expectedChecksum = (await fs.readFile(checksumFile, 'utf-8')).trim(); + const file = await this.http.download({ + url, + checksumType: 'sha512', + expectedChecksum, + }); - if (isOnGithub) { - await this.compress.extract({ file, cwd: path }); - } else { - // from getcomposer.org - path = await this.pathSvc.createVersionedToolPath(this.name, version); - path = join(path, 'bin'); - await fs.mkdir(path); - path = join(path, 'composer'); - await fs.cp(file, path); - await fs.chmod(path, this.envSvc.umask); - } + const path = await this.pathSvc.ensureToolPath(this.name); + await this.compress.extract({ file, cwd: path }); } override async link(version: string): Promise { @@ -99,11 +54,6 @@ export class ComposerInstallService extends BaseInstallService { stdio: ['inherit', 'inherit', 1], }); } - - private async readChecksum(url: string): Promise { - const checksumFile = await this.http.download({ url }); - return (await fs.readFile(checksumFile, 'utf-8')).split(' ')[0]?.trim(); - } } @injectable()