Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions docs/custom-registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
```

Expand Down
74 changes: 12 additions & 62 deletions src/cli/tools/php/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
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 {
Expand All @@ -30,63 +29,19 @@

override async install(version: string): Promise<void> {
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}`;

Check warning on line 33 in src/cli/tools/php/composer.ts

View check run for this annotation

Codecov / codecov/patch

src/cli/tools/php/composer.ts#L32-L33

Added lines #L32 - L33 were not covered by tests

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,
});

Check warning on line 41 in src/cli/tools/php/composer.ts

View check run for this annotation

Codecov / codecov/patch

src/cli/tools/php/composer.ts#L35-L41

Added lines #L35 - L41 were not covered by tests

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 });

Check warning on line 44 in src/cli/tools/php/composer.ts

View check run for this annotation

Codecov / codecov/patch

src/cli/tools/php/composer.ts#L43-L44

Added lines #L43 - L44 were not covered by tests
}

override async link(version: string): Promise<void> {
Expand All @@ -99,11 +54,6 @@
stdio: ['inherit', 'inherit', 1],
});
}

private async readChecksum(url: string): Promise<string | undefined> {
const checksumFile = await this.http.download({ url });
return (await fs.readFile(checksumFile, 'utf-8')).split(' ')[0]?.trim();
}
}

@injectable()
Expand Down