|
1 | 1 | import axios from 'axios'; |
2 | | -import { spawn } from 'node:child_process'; |
| 2 | +import { spawn, spawnSync } from 'node:child_process'; |
3 | 3 | import { randomUUID } from 'node:crypto'; |
| 4 | +import { readFileSync, writeFileSync } from 'node:fs'; |
4 | 5 | import { Agent } from 'node:https'; |
5 | 6 | import * as semver from 'semver'; |
6 | 7 |
|
@@ -31,26 +32,40 @@ httpClient.interceptors.request.use( |
31 | 32 |
|
32 | 33 | const setupAPI7 = async () => { |
33 | 34 | return new Promise<void>((resolve, reject) => { |
34 | | - const ls = spawn( |
| 35 | + const download = spawnSync( |
35 | 36 | 'sh', |
36 | 37 | [ |
37 | 38 | '-c', |
38 | | - `curl -O ${process.env.BACKEND_API7_DOWNLOAD_URL} && tar xf api7-ee-*.tar.gz && cd api7-ee && bash run.sh start`, |
| 39 | + `curl -O ${process.env.BACKEND_API7_DOWNLOAD_URL} && tar xf api7-ee-*.tar.gz`, |
39 | 40 | ], |
40 | 41 | { cwd: `/tmp` }, |
41 | 42 | ); |
42 | 43 |
|
| 44 | + console.log('stdout: ' + download.stdout.toString('utf-8')); |
| 45 | + console.log('stderr: ' + download.stderr.toString('utf-8')); |
| 46 | + |
| 47 | + const dockerComposePath = `/tmp/api7-ee/docker-compose.yaml`; |
| 48 | + const dockerCompose = readFileSync(dockerComposePath, 'utf-8').replaceAll( |
| 49 | + ': bitnami/', |
| 50 | + ': bitnamilegacy/', |
| 51 | + ); |
| 52 | + writeFileSync(dockerComposePath, dockerCompose, 'utf-8'); |
| 53 | + |
| 54 | + const setup = spawn('sh', ['-c', `cd api7-ee && bash run.sh start`], { |
| 55 | + cwd: `/tmp`, |
| 56 | + }); |
| 57 | + |
43 | 58 | console.log('\nSetup API7 Instance\n'); |
44 | 59 |
|
45 | | - ls.stdout.on('data', function (data) { |
| 60 | + setup.stdout.on('data', function (data) { |
46 | 61 | console.log('stdout: ' + data.toString()); |
47 | 62 | }); |
48 | 63 |
|
49 | | - ls.stderr.on('data', function (data) { |
| 64 | + setup.stderr.on('data', function (data) { |
50 | 65 | console.log('stderr: ' + data.toString()); |
51 | 66 | }); |
52 | 67 |
|
53 | | - ls.on('exit', function (code) { |
| 68 | + setup.on('exit', function (code) { |
54 | 69 | if (code) |
55 | 70 | reject(`child process exited with non-zero code: ${code?.toString()}`); |
56 | 71 |
|
|
0 commit comments