|
4 | 4 |
|
5 | 5 | use EE; |
6 | 6 | use EE\Migration\Base; |
| 7 | +use Symfony\Component\Process\Process; |
7 | 8 |
|
8 | 9 | class InsertDockerImagesVersion extends Base { |
9 | 10 |
|
@@ -37,18 +38,50 @@ public function up() { |
37 | 38 | 'easyengine/php7.2', |
38 | 39 | 'easyengine/php7.3', |
39 | 40 | 'easyengine/php7.4', |
| 41 | + 'easyengine/php', |
40 | 42 | 'easyengine/php8.0', |
41 | 43 | 'easyengine/php8.1', |
| 44 | + 'easyengine/mailhog', |
42 | 45 | 'easyengine/newrelic-daemon', |
43 | 46 | ]; |
| 47 | + |
| 48 | + $pull_queue = []; |
44 | 49 | foreach ( $images as $image => $tag ) { |
45 | 50 | if ( in_array( $image, $skip_download ) ) { |
46 | 51 | continue; |
47 | 52 | } |
48 | | - EE::log( "Checking and Pulling docker image $image:$tag" ); |
49 | | - if ( ! \EE::exec( "docker pull ${image}:${tag}", true, true ) ) { |
50 | | - throw new \Exception( "Unable to pull ${image}:${tag}. Please check logs for more details." ); |
| 53 | + $pull_queue[] = [ $image, $tag ]; |
| 54 | + } |
| 55 | + |
| 56 | + $concurrency = 4; |
| 57 | + $running = []; |
| 58 | + $successful_pulls = []; |
| 59 | + |
| 60 | + while ( ! empty( $pull_queue ) || ! empty( $running ) ) { |
| 61 | + // Start new processes if under concurrency limit |
| 62 | + while ( count( $running ) < $concurrency && ! empty( $pull_queue ) ) { |
| 63 | + list( $image, $tag ) = array_shift( $pull_queue ); |
| 64 | + EE::log( "Checking and Pulling docker image $image:$tag" ); |
| 65 | + $process = new Process( [ 'docker', 'pull', "$image:$tag" ] ); |
| 66 | + $process->start(); |
| 67 | + $running[] = [ $process, $image, $tag ]; |
51 | 68 | } |
| 69 | + |
| 70 | + // Check for finished processes |
| 71 | + foreach ( $running as $key => list( $process, $image, $tag ) ) { |
| 72 | + if ( ! $process->isRunning() ) { |
| 73 | + if ( ! $process->isSuccessful() ) { |
| 74 | + throw new \Exception( "Unable to pull $image:$tag: " . $process->getErrorOutput() ); |
| 75 | + } |
| 76 | + $successful_pulls[] = [ $image, $tag ]; |
| 77 | + unset( $running[ $key ] ); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + usleep( 100000 ); // Sleep 100ms to avoid busy loop |
| 82 | + } |
| 83 | + |
| 84 | + foreach ( $successful_pulls as list( $image, $tag ) ) { |
52 | 85 | $query .= "INSERT INTO options VALUES( '${image}', '${tag}' );"; |
53 | 86 | } |
54 | 87 |
|
|
0 commit comments