Skip to content

Commit 0743066

Browse files
authored
Create many tiny artifacts for faster download (#2951)
* Create many tiny artifacts for faster download And not escaping the constraints many systems have on /tmp size. If someone installs multiple php versions at once, we still download the full package. The full package also remains available for offline installations of multiple targets for now. Signed-off-by: Bob Weinand <[email protected]> * Fix potential inf loop --------- Signed-off-by: Bob Weinand <[email protected]>
1 parent b3c078a commit 0743066

File tree

4 files changed

+154
-35
lines changed

4 files changed

+154
-35
lines changed

.circleci/continue_config.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -3620,16 +3620,16 @@ jobs:
36203620
name: Setup docker container
36213621
shell: powershell.exe
36223622
command: |
3623-
mkdir extensions_windows_x86_64
3624-
mkdir extensions_windows_x86_64_debugsymbols
3623+
mkdir extensions_x86_64
3624+
mkdir extensions_x86_64_debugsymbols
36253625
# No DNS for you by default in circleci docker containers
36263626
docker network create -d "nat" -o com.docker.network.windowsshim.dnsservers="1.1.1.1" net
36273627
docker run -v ${pwd}:C:\Users\ContainerAdministrator\app -d --network net --name php << parameters.docker_image >> ping -t localhost
36283628
- run:
36293629
name: Build nts
36303630
shell: powershell.exe
36313631
command: |
3632-
docker exec php powershell.exe "cd app; switch-php nts; C:\php\SDK\phpize.bat; .\configure.bat --enable-debug-pack; nmake; move x64\Release\php_ddtrace.dll extensions_windows_x86_64\php_ddtrace-<< parameters.so_suffix >>.dll; move x64\Release\php_ddtrace.pdb extensions_windows_x86_64_debugsymbols\php_ddtrace-<< parameters.so_suffix >>.pdb"
3632+
docker exec php powershell.exe "cd app; switch-php nts; C:\php\SDK\phpize.bat; .\configure.bat --enable-debug-pack; nmake; move x64\Release\php_ddtrace.dll extensions_x86_64\php_ddtrace-<< parameters.so_suffix >>.dll; move x64\Release\php_ddtrace.pdb extensions_x86_64_debugsymbols\php_ddtrace-<< parameters.so_suffix >>.pdb"
36333633
- run:
36343634
name: Reuse libdatadog build
36353635
shell: powershell.exe
@@ -3639,10 +3639,10 @@ jobs:
36393639
name: Build zts
36403640
shell: powershell.exe
36413641
command: |
3642-
docker exec php powershell.exe "cd app; switch-php zts; C:\php\SDK\phpize.bat; .\configure.bat --enable-debug-pack; nmake; move x64\Release_TS\php_ddtrace.dll extensions_windows_x86_64\php_ddtrace-<< parameters.so_suffix >>-zts.dll; move x64\Release_TS\php_ddtrace.pdb extensions_windows_x86_64_debugsymbols\php_ddtrace-<< parameters.so_suffix >>-zts.pdb"
3642+
docker exec php powershell.exe "cd app; switch-php zts; C:\php\SDK\phpize.bat; .\configure.bat --enable-debug-pack; nmake; move x64\Release_TS\php_ddtrace.dll extensions_x86_64\php_ddtrace-<< parameters.so_suffix >>-zts.dll; move x64\Release_TS\php_ddtrace.pdb extensions_x86_64_debugsymbols\php_ddtrace-<< parameters.so_suffix >>-zts.pdb"
36433643
- persist_to_workspace:
36443644
root: '.'
3645-
paths: [ './extensions_windows_x86_64', './extensions_windows_x86_64_debugsymbols' ]
3645+
paths: [ './extensions_x86_64', './extensions_x86_64_debugsymbols' ]
36463646

36473647
compile_appsec_extension_centos:
36483648
working_directory: ~/datadog

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ build_pecl_package:
492492
tooling/bin/pecl-build $${FILES//$${BUILD_DIR}/}
493493

494494
dbgsym.tar.gz:
495-
$(if $(DDTRACE_MAKE_PACKAGES_ASAN), , tar -zcf $(PACKAGES_BUILD_DIR)/dd-library-php-$(VERSION)_windows_debugsymbols.tar.gz ./extensions_windows_x86_64_debugsymbols --owner=0 --group=0)
495+
$(if $(DDTRACE_MAKE_PACKAGES_ASAN), , tar -zcf $(PACKAGES_BUILD_DIR)/dd-library-php-$(VERSION)_windows_debugsymbols.tar.gz ./extensions_x86_64_debugsymbols --owner=0 --group=0)
496496

497497
installer_packages: .apk.x86_64 .apk.aarch64 .rpm.x86_64 .rpm.aarch64 .deb.x86_64 .deb.arm64 .tar.gz.x86_64 .tar.gz.aarch64 bundle.tar.gz dbgsym.tar.gz
498498
tar --use-compress-program=pigz --exclude='dd-library-php-ssi-*' -cf packages.tar.gz $(PACKAGES_BUILD_DIR) --owner=0 --group=0

datadog-setup.php

+82-20
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ function print_help()
9595
option can be provided multiple times.
9696
--install-dir <path> Install to a specific directory. Default: '$installdir'
9797
--uninstall Uninstall the library from the specified binaries.
98+
--file <path to .tar.gz> Path to a dd-library-php-*.tar.gz file. Can be used for offline installation.
9899
--extension-dir <path> Specify the extension directory. Default: PHP's extension directory.
99100
--ini <path> Specify the INI file to use. Default: <ini-dir>/98-ddtrace.ini
100101
--enable-appsec Enable the application security monitoring module.
101-
--enable-profiling Enable the profiling module.
102+
--enable-profiling Enable the profiling module.
102103
-d setting[=value] Used in conjunction with `config <set|get>`
103104
command to specify the INI setting to get or set.
104105
@@ -462,9 +463,58 @@ function install($options)
462463
$selectedBinaries = require_binaries_or_exit($options);
463464
$interactive = empty($options[OPT_PHP_BIN]);
464465

466+
$commandExtensionSuffixes = [];
467+
$downloadVersions = [];
468+
foreach ($selectedBinaries as $command => $fullPath) {
469+
$binaryForLog = ($command === $fullPath) ? $fullPath : "$command ($fullPath)";
470+
echo "Checking for binary: $binaryForLog\n";
471+
472+
check_php_ext_prerequisite_or_exit($fullPath, 'json');
473+
474+
$phpProperties = ini_values($fullPath);
475+
if (!isset($phpProperties[INI_SCANDIR])) {
476+
if (!isset($phpProperties[INI_MAIN])) {
477+
if (IS_WINDOWS) {
478+
$phpProperties[INI_MAIN] = dirname($fullPath) . "/php.ini";
479+
} else {
480+
print_error_and_exit(
481+
"It is not possible to perform installation on this "
482+
. "system because there is no scan directory and no "
483+
. "configuration file loaded."
484+
);
485+
}
486+
}
487+
488+
print_warning(
489+
"Performing an installation without a scan directory may "
490+
. "result in fragile installations that are broken by normal "
491+
. "system upgrades. It is advisable to use the configure "
492+
. "switch --with-config-file-scan-dir when building PHP."
493+
);
494+
}
495+
496+
// Suffix (zts/debug)
497+
$extensionSuffix = '';
498+
if (is_truthy($phpProperties[IS_DEBUG])) {
499+
$extensionSuffix .= '-debug';
500+
}
501+
if (is_truthy($phpProperties[THREAD_SAFETY])) {
502+
$extensionSuffix .= '-zts';
503+
}
504+
505+
$commandExtensionSuffixes[$command] = $extensionSuffix;
506+
507+
$extensionVersion = $phpProperties[PHP_API];
508+
$downloadVersions["$extensionVersion$extensionSuffix"] = true;
509+
}
510+
511+
$tar_gz_suffix = "";
512+
if (count($downloadVersions) === 1) {
513+
$tar_gz_suffix = "-" . key($downloadVersions);
514+
}
515+
465516
// Preparing clean tmp folder to extract files
466517
$tmpDir = sys_get_temp_dir() . '/dd-install';
467-
$tmpDirTarGz = $tmpDir . "/dd-library-php-{$platform}.tar.gz";
468518
$tmpArchiveRoot = $tmpDir . '/dd-library-php';
469519
$tmpArchiveTraceRoot = $tmpDir . '/dd-library-php/trace';
470520
$tmpArchiveAppsecRoot = $tmpDir . '/dd-library-php/appsec';
@@ -490,8 +540,14 @@ function install($options)
490540
print_warning('--' . OPT_FILE . ' option is intended for internal usage and can be removed without notice');
491541
$tmpDirTarGz = $options[OPT_FILE];
492542
} else {
493-
$url = RELEASE_URL_PREFIX . "dd-library-php-" . RELEASE_VERSION . "-{$platform}.tar.gz";
494-
download($url, $tmpDirTarGz);
543+
for (;;) {
544+
$url = RELEASE_URL_PREFIX . "dd-library-php-" . RELEASE_VERSION . "-{$platform}{$tar_gz_suffix}.tar.gz";
545+
$tmpDirTarGz = $tmpDir . "/dd-library-php-{$platform}{$tar_gz_suffix}.tar.gz";
546+
if (download($url, $tmpDirTarGz, $tar_gz_suffix != "")) {
547+
break;
548+
}
549+
$tar_gz_suffix = ""; // retry with the full archive if the original download failed
550+
}
495551
}
496552
if (!IS_WINDOWS || `where tar 2> nul` !== null) {
497553
execute_or_exit(
@@ -574,15 +630,7 @@ function install($options)
574630

575631
// Copying the extension
576632
$extensionVersion = $phpProperties[PHP_API];
577-
578-
// Suffix (zts/debug/alpine)
579-
$extensionSuffix = '';
580-
if (is_truthy($phpProperties[IS_DEBUG])) {
581-
$extensionSuffix .= '-debug';
582-
}
583-
if (is_truthy($phpProperties[THREAD_SAFETY])) {
584-
$extensionSuffix .= '-zts';
585-
}
633+
$extensionSuffix = $commandExtensionSuffixes[$command];
586634

587635
$extDir = isset($options[OPT_EXTENSION_DIR]) ? $options[OPT_EXTENSION_DIR] : $phpProperties[EXTENSION_DIR];
588636
echo "Installing extension to $extDir\n";
@@ -1416,7 +1464,7 @@ function execute_or_exit($exitMessage, $command)
14161464
* @param string $url
14171465
* @param string $destination
14181466
*/
1419-
function download($url, $destination)
1467+
function download($url, $destination, $retry = false)
14201468
{
14211469
echo "Downloading installable archive from $url.\n";
14221470
echo "This operation might take a while.\n";
@@ -1444,12 +1492,20 @@ function download($url, $destination)
14441492
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
14451493
$progress_counter = 0;
14461494
$return = curl_exec($ch);
1495+
1496+
if ($retry) {
1497+
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
1498+
if ($httpCode == 404) {
1499+
return false;
1500+
}
1501+
}
1502+
14471503
curl_close($ch);
14481504
fclose($fp);
14491505

14501506
if (false !== $return) {
14511507
echo $okMessage;
1452-
return;
1508+
return true;
14531509
}
14541510
// Otherwise we attempt other methods
14551511
}
@@ -1461,20 +1517,20 @@ function download($url, $destination)
14611517
if (!IS_WINDOWS && false !== exec('curl --version', $output, $statusCode) && $statusCode === 0) {
14621518
$curlInvocationStatusCode = 0;
14631519
system(
1464-
'curl -L --output ' . escapeshellarg($destination) . ' ' . escapeshellarg($url),
1520+
'curl -f -L --output ' . escapeshellarg($destination) . ' ' . escapeshellarg($url),
14651521
$curlInvocationStatusCode
14661522
);
14671523

14681524
if ($curlInvocationStatusCode === 0) {
14691525
echo $okMessage;
1470-
return;
1526+
return true;
14711527
}
14721528
// Otherwise we attempt other methods
14731529
}
14741530

14751531
// file_get_contents
14761532
if (is_truthy(ini_get('allow_url_fopen')) && extension_loaded('openssl')) {
1477-
ini_set("memory_limit", "1G"); // increase memory limit otherwise we may run OOM here.
1533+
ini_set("memory_limit", "2G"); // increase memory limit otherwise we may run OOM here.
14781534
$data = @file_get_contents($url);
14791535
// PHP doesn't like too long location headers, and on PHP 7.3 and older they weren't read at all.
14801536
// But this only really matters for CircleCI artifacts, so not too bad.
@@ -1491,11 +1547,14 @@ function download($url, $destination)
14911547
}
14921548
got_data: ;
14931549
if ($data == "" || false === file_put_contents($destination, $data)) {
1550+
if ($retry) {
1551+
return false;
1552+
}
14941553
print_error_and_exit("Error while downloading the installable archive from $url\n");
14951554
}
14961555

14971556
echo $okMessage;
1498-
return;
1557+
return true;
14991558

15001559
next_method:
15011560
}
@@ -1508,11 +1567,14 @@ function download($url, $destination)
15081567
);
15091568
if ($webRequestInvocationStatusCode === 0) {
15101569
echo $okMessage;
1511-
return;
1570+
return true;
15121571
}
15131572
// Otherwise we attempt other methods
15141573
}
15151574

1575+
if ($retry) {
1576+
return false;
1577+
}
15161578

15171579
echo "Error: Cannot download the installable archive.\n";
15181580
echo " One of the following prerequisites must be satisfied:\n";

tooling/bin/generate-final-artifact.sh

+66-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,69 @@ tmp_folder_final=$tmp_folder/final
1111

1212
architectures=(x86_64 aarch64)
1313

14+
php_apis=(20190902 20200930 20210902 20220829 20230831 20240924)
15+
if [[ -z ${DDTRACE_MAKE_PACKAGES_ASAN:-} ]]; then
16+
php_apis+=(20151012 20160303 20170718 20180731)
17+
fi
18+
19+
targets=(unknown-linux-gnu alpine-linux-musl)
20+
if [[ -z ${DDTRACE_MAKE_PACKAGES_ASAN:-} ]]; then
21+
targets+=(windows)
22+
fi
23+
24+
configs=("" -zts -debug -debug-zts)
25+
26+
ln_with_dir() {
27+
mkdir -p $(dirname $2)
28+
ln $1 $2
29+
}
30+
31+
for architecture in "${architectures[@]}"; do
32+
for php_api in "${php_apis[@]}"; do
33+
for full_target in "${targets[@]}"; do
34+
target=${full_target#*-}
35+
alpine=$(if [[ $target == "linux-musl" ]]; then echo -alpine; fi)
36+
ext=$([[ $target == "windows" ]] && echo dll || echo so)
37+
for config in "${configs[@]}"; do
38+
ddtrace_ext_path=./extensions_${architecture}/$(if [[ $target == "windows" ]]; then echo php_; fi)ddtrace-${php_api}${alpine}${config}.${ext}
39+
if [[ -f ${ddtrace_ext_path} ]]; then
40+
rm -rf $tmp_folder
41+
mkdir -p $tmp_folder_final
42+
43+
trace_base_dir=${tmp_folder_final}/dd-library-php/trace
44+
ln_with_dir ${ddtrace_ext_path} ${trace_base_dir}/ext/${php_api}/$(if [[ $target == "windows" ]]; then echo php_; fi)ddtrace${config}.${ext}
45+
cp -r ./src ${trace_base_dir}
46+
47+
profiling_ext_path=./datadog-profiling/${architecture}-${full_target}/lib/php/${php_api}/datadog-profiling${config}.${ext}
48+
if [[ -f ${profiling_ext_path} ]]; then
49+
profiling_base_dir=${tmp_folder_final}/dd-library-php/profiling
50+
ln_with_dir ${profiling_ext_path} ${profiling_base_dir}/ext/${php_api}/datadog-profiling${config}.${ext}
51+
52+
# Licenses
53+
ln \
54+
./profiling/LICENSE* \
55+
./profiling/NOTICE \
56+
${profiling_base_dir}/
57+
fi
58+
59+
appsec_ext_path=./appsec_${architecture}/ddappsec-${php_api}${alpine}${config}.${ext}
60+
if [[ -f ${appsec_ext_path} ]]; then
61+
appsec_base_dir=${tmp_folder_final}/dd-library-php/appsec
62+
ln_with_dir ${appsec_ext_path} ${appsec_base_dir}/ext/$php_api/ddappsec${config}.${ext}
63+
ln_with_dir ./appsec_${architecture}/libddappsec-helper.so ${appsec_base_dir}/lib/libddappsec-helper.so
64+
ln_with_dir ./appsec_${architecture}/recommended.json ${appsec_base_dir}/etc/recommended.json
65+
fi
66+
67+
echo "$release_version" > ${tmp_folder_final}/dd-library-php/VERSION
68+
tar -czv \
69+
-f ${packages_build_dir}/dd-library-php-${release_version}-$architecture-$target-${php_api}${config}.tar.gz \
70+
-C ${tmp_folder_final} . --owner=0 --group=0
71+
fi
72+
done
73+
done
74+
done
75+
done
76+
1477
for architecture in "${architectures[@]}"; do
1578
tmp_folder_final_gnu=$tmp_folder_final/$architecture-linux-gnu
1679
tmp_folder_final_musl=$tmp_folder_final/$architecture-linux-musl
@@ -33,24 +96,18 @@ for architecture in "${architectures[@]}"; do
3396
tmp_folder_final_musl_trace=$tmp_folder_final_musl/dd-library-php/trace
3497
tmp_folder_final_windows_trace=$tmp_folder_final_windows/dd-library-php/trace
3598

36-
php_apis=(20190902 20200930 20210902 20220829 20230831 20240924)
37-
if [[ -z ${DDTRACE_MAKE_PACKAGES_ASAN:-} ]]; then
38-
php_apis+=(20151012 20160303 20170718 20180731)
39-
fi
4099
for php_api in "${php_apis[@]}"; do
41100
mkdir -p ${tmp_folder_final_gnu_trace}/ext/$php_api ${tmp_folder_final_musl_trace}/ext/$php_api;
42101
if [[ -z ${DDTRACE_MAKE_PACKAGES_ASAN:-} ]]; then
43102
ln ./extensions_${architecture}/ddtrace-$php_api.so ${tmp_folder_final_gnu_trace}/ext/$php_api/ddtrace.so;
44103
ln ./extensions_${architecture}/ddtrace-$php_api-zts.so ${tmp_folder_final_gnu_trace}/ext/$php_api/ddtrace-zts.so;
45104
ln ./extensions_${architecture}/ddtrace-$php_api-debug.so ${tmp_folder_final_gnu_trace}/ext/$php_api/ddtrace-debug.so;
46105
ln ./extensions_${architecture}/ddtrace-$php_api-alpine.so ${tmp_folder_final_musl_trace}/ext/$php_api/ddtrace.so;
47-
if [[ ${php_api} -ge 20151012 ]]; then # zts on alpine starting 7.0
48-
ln ./extensions_${architecture}/ddtrace-$php_api-alpine-zts.so ${tmp_folder_final_musl_trace}/ext/$php_api/ddtrace-zts.so;
49-
fi
106+
ln ./extensions_${architecture}/ddtrace-$php_api-alpine-zts.so ${tmp_folder_final_musl_trace}/ext/$php_api/ddtrace-zts.so;
50107
if [[ ${php_api} -ge 20170718 && $architecture == "x86_64" ]]; then # Windows support starts on 7.2
51108
mkdir -p ${tmp_folder_final_windows_trace}/ext/$php_api;
52-
ln ./extensions_windows_${architecture}/php_ddtrace-$php_api.dll ${tmp_folder_final_windows_trace}/ext/$php_api/php_ddtrace.dll;
53-
ln ./extensions_windows_${architecture}/php_ddtrace-$php_api-zts.dll ${tmp_folder_final_windows_trace}/ext/$php_api/php_ddtrace-zts.dll;
109+
ln ./extensions_${architecture}/php_ddtrace-$php_api.dll ${tmp_folder_final_windows_trace}/ext/$php_api/php_ddtrace.dll;
110+
ln ./extensions_${architecture}/php_ddtrace-$php_api-zts.dll ${tmp_folder_final_windows_trace}/ext/$php_api/php_ddtrace-zts.dll;
54111
fi
55112
else
56113
ln ./extensions_${architecture}/ddtrace-$php_api-debug-zts.so ${tmp_folder_final_gnu_trace}/ext/$php_api/ddtrace-debug-zts.so;

0 commit comments

Comments
 (0)