Skip to content

Commit 5f90f6e

Browse files
committed
Fixed resources for linux (ubuntu)
1 parent 5ffe083 commit 5f90f6e

22 files changed

Lines changed: 472 additions & 219 deletions

File tree

.cirrus.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ integration_individual_test_macos_task:
5252
- zsh -i -c "npm run test -- $FILE_NAME --disable-console-intercept $DEBUG --no-file-parallelism"
5353

5454
integration_individual_test_linux_task:
55-
arm_container:
56-
image: kevinwang5658/codify-test-linux:latest
55+
# trick cirrus CI to use tart here to run a linux instance
56+
macos_instance:
57+
image: codify-test-vm-linux
5758
# node_modules_cache:
5859
# folder: node_modules
5960
# fingerprint_script: cat package-lock.json
6061
# populate_script: npm ci
6162
test_script:
62-
- chown -R node /tmp/cirrus-ci/working-dir
63-
- su node -c "npm install"
63+
# - chown -R node /tmp/cirrus-ci/working-dir
64+
# - su node -c "npm install"
6465
- echo $FILE_NAME
65-
- su node -c "npm run test -- $FILE_NAME --disable-console-intercept $DEBUG --no-file-parallelism"
66+
- npm ci
67+
- npm run test -- $FILE_NAME --disable-console-intercept $DEBUG --no-file-parallelism

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"ajv": "^8.12.0",
2727
"ajv-formats": "^2.1.1",
2828
"chalk": "^5.3.0",
29-
"codify-plugin-lib": "1.0.182-beta57",
29+
"codify-plugin-lib": "1.0.182-beta64",
3030
"codify-schemas": "1.0.86-beta7",
3131
"debug": "^4.3.4",
3232
"lodash.isequal": "^4.5.0",
@@ -55,7 +55,7 @@
5555
"@types/node": "^18",
5656
"@types/plist": "^3.0.5",
5757
"@types/semver": "^7.5.4",
58-
"codify-plugin-test": "0.0.53-beta23",
58+
"codify-plugin-test": "0.0.53-beta24",
5959
"commander": "^12.1.0",
6060
"eslint": "^8.51.0",
6161
"eslint-config-oclif": "^5",

scripts/run-tests.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ program
2020
.action(main)
2121
.parse()
2222

23-
async function main(argument: string, args: { operatingSystem: string; persistent: boolean; launchPersistent: boolean }): Promise<void> {
23+
async function main(argument: string, args: {
24+
operatingSystem: string;
25+
persistent: boolean;
26+
launchPersistent: boolean
27+
}): Promise<void> {
2428
const debug = isInDebugMode();
2529
if (debug) {
2630
console.log('Running in debug mode!')
@@ -72,31 +76,29 @@ async function launchPersistentTest(test: string, debug: boolean, operatingSyste
7276
const shell = operatingSystem === 'darwin' ? 'zsh' : 'bash';
7377

7478
// if (operatingSystem === 'darwin') {
75-
const { data: vmList } = await codifySpawn('tart list --format json');
76-
console.log(vmList);
79+
const { data: vmList } = await codifySpawn('tart list --format json');
80+
console.log(vmList);
7781

78-
const parsedVmList = JSON.parse(vmList);
79-
const runningVm = parsedVmList.find(vm => vm.Name.startsWith('codify-test-vm') && vm.Running === true);
80-
if (!runningVm) {
81-
throw new Error('No persistent VM found');
82-
}
82+
const parsedVmList = JSON.parse(vmList);
83+
const runningVm = parsedVmList.find(vm => vm.Name.startsWith('codify-test-vm') && vm.Running === true);
84+
if (!runningVm) {
85+
throw new Error('No persistent VM found');
86+
}
8387

84-
const vmName = runningVm.Name;
85-
const dir = '~/codify-homebrew-plugin';
86-
// const dir = '/Volumes/My\\ Shared\\ Files/plugin'
88+
const vmName = runningVm.Name;
89+
const dir = '~/codify-homebrew-plugin';
90+
// const dir = '/Volumes/My\\ Shared\\ Files/plugin'
8791

88-
const debugFlag = debug ? ' -e DEBUG="--inspect-brk=9229"' : ''
92+
const debugFlag = debug ? ' -e DEBUG="--inspect-brk=9229"' : ''
8993

90-
console.log('Refreshing files on VM...');
91-
const { data: ipAddr } = await testSpawn(`tart ip ${vmName}`);
92-
await testSpawn(`tart exec ${vmName} rm -rf ${dir}/src`);
93-
await testSpawn(`tart exec ${vmName} rm -rf ${dir}/test`);
94-
await testSpawn(`sshpass -p "admin" scp -r -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${path.join(process.cwd(), 'test')} admin@${ipAddr}:${dir}/test`);
95-
await testSpawn(`sshpass -p "admin" scp -r -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${path.join(process.cwd(), 'src')} admin@${ipAddr}:${dir}/src`);
94+
console.log('Refreshing files on VM...');
95+
const { data: ipAddr } = await testSpawn(`tart ip ${vmName}`);
96+
await testSpawn(`tart exec ${vmName} rm -rf ${dir}/src ${dir}/test`, { throws: true });
97+
await testSpawn(`sshpass -p "admin" scp -r -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${path.join(process.cwd(), 'test')} ${path.join(process.cwd(), 'src')} ${path.join(process.cwd(), 'package.json')} ${path.join(process.cwd(), 'package-lock.json')} admin@${ipAddr}:${dir}`, { throws: true });
9698

97-
console.log('Done refreshing files on VM. Starting tests...');
98-
VerbosityLevel.set(3);
99-
await codifySpawn(`tart exec ${vmName} ${shell} -c ${operatingSystem === 'darwin' ? '-i' : ''} "cd ${dir} && FORCE_COLOR=true npm run test -- ${test} --disable-console-intercept ${debugFlag} --no-file-parallelism"`, { throws: false });
99+
console.log('Done refreshing files on VM. Starting tests...');
100+
VerbosityLevel.set(3);
101+
await codifySpawn(`tart exec ${vmName} ${shell} -c ${operatingSystem === 'darwin' ? '-i' : ''} "cd ${dir} && FORCE_COLOR=true npm run test -- ${test} --disable-console-intercept ${debugFlag} --no-file-parallelism"`, { throws: false });
100102
// }
101103
}
102104

@@ -125,6 +127,7 @@ async function launchPersistentVm(operatingSystem: string) {
125127
console.log('Finished installing dependencies. Start tests in a new terminal window.');
126128

127129
await sleep(1_000_000_000);
130+
128131
// This is effective the end just without a return
129132

130133
async function cleanupVm() {

src/resources/apt/apt.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class AptResource extends Resource<AptConfig> {
1616
id: 'apt',
1717
operatingSystems: [OS.Linux],
1818
schema,
19+
removeStatefulParametersBeforeDestroy: true,
1920
parameterSettings: {
2021
install: { type: 'stateful', definition: new AptInstallParameter() },
2122
update: { type: 'boolean', default: true, setting: true }
@@ -45,6 +46,6 @@ export class AptResource extends Resource<AptConfig> {
4546

4647
override async destroy(): Promise<void> {
4748
// apt is a core system component and should not be removed
48-
throw new Error('apt cannot be destroyed as it is a core system package manager');
49+
console.warn('apt cannot be destroyed as it is a core system package manager');
4950
}
5051
}

src/resources/apt/install-parameter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class AptInstallParameter extends StatefulParameter<AptConfig, Array<AptP
104104
return p.name;
105105
}).join(' ');
106106

107-
await $.spawn(`apt-get install -y ${toInstall}`, { requiresRoot: true, interactive: true });
107+
await $.spawn(`apt-get install -y ${toInstall}`, { requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' }});
108108
}
109109

110110
private async uninstall(packages: Array<AptPackage | string>): Promise<void> {
@@ -121,7 +121,7 @@ export class AptInstallParameter extends StatefulParameter<AptConfig, Array<AptP
121121
return p.name;
122122
}).join(' ');
123123

124-
await $.spawn(`apt-get remove -y ${toUninstall}`, { requiresRoot: true, interactive: true });
124+
await $.spawn(`apt-get auto-remove -y ${toUninstall}`, { requiresRoot: true, env: { DEBIAN_FRONTEND: 'noninteractive' }});
125125
}
126126

127127
isSamePackage(a: AptPackage | string, b: AptPackage | string): boolean {

src/resources/asdf/asdf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class AsdfResource extends Resource<AsdfConfig> {
5555
const asdfDir = path.join(os.homedir(), '.local', 'bin');
5656
await fs.mkdir(asdfDir, { recursive: true });
5757
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'codify-asdf'));
58-
const arch = Utils.isLinux() ? 'amd64' : 'arm64';
58+
const arch = (await Utils.isArmArch()) ? 'arm64' : 'amd64';
5959

6060
// Download and extract asdf
6161
await $.spawn(`curl -Lo ${tmpDir}/asdf.tar.gz "https://github.com/asdf-vm/asdf/releases/download/${latestVersion}/asdf-${latestVersion}-linux-${arch}.tar.gz"`, { cwd: tmpDir });

src/resources/aws-cli/cli/aws-cli.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Resource, ResourceSettings, getPty, SpawnStatus, Utils } from 'codify-plugin-lib';
1+
import { Resource, ResourceSettings, SpawnStatus, Utils, getPty, FileUtils } from 'codify-plugin-lib';
22
import { OS, StringIndexedObject } from 'codify-schemas';
33
import fs from 'node:fs/promises';
44
import os from 'node:os';
@@ -75,7 +75,13 @@ softwareupdate --install-rosetta
7575
} else if (Utils.isLinux()) {
7676
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'codify-aws-cli'));
7777

78-
await $.spawn('curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"', { cwd: tmpDir });
78+
// Detect architecture and use appropriate download link
79+
const downloadUrl = isArmArch
80+
? 'https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip'
81+
: 'https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip';
82+
83+
console.log(`Installing AWS CLI for Linux (${isArmArch ? 'ARM64' : 'x86_64'})...`);
84+
await FileUtils.downloadFile(downloadUrl, path.join(tmpDir, 'awscliv2.zip'));
7985
await $.spawn('unzip -q awscliv2.zip', { cwd: tmpDir });
8086
await $.spawn('./aws/install', { cwd: tmpDir, requiresRoot: true });
8187
await fs.rm(tmpDir, { recursive: true, force: true });
@@ -95,9 +101,9 @@ softwareupdate --install-rosetta
95101
return;
96102
}
97103

98-
await $.spawn(`rm ${installLocation}`, { requiresRoot: true });
99-
await $.spawn(`rm ${installLocation}_completer`, { requiresRoot: true });
100-
await $.spawn('rm -rf $HOME/.aws/');
104+
await $.spawnSafe(`rm ${installLocation}`, { requiresRoot: true });
105+
await $.spawnSafe(`rm ${installLocation}_completer`, { requiresRoot: true });
106+
await $.spawnSafe('rm -rf $HOME/.aws/');
101107
}
102108

103109
private async findInstallLocation(): Promise<null | string> {

0 commit comments

Comments
 (0)