Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

582 602 expected docker compose err #794

Merged
merged 8 commits into from Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/commands/dev/index.ts
Expand Up @@ -503,7 +503,20 @@ export default class Dev extends BaseCommand {
build_args.push('--build-arg', arg);
}

await DockerComposeUtils.dockerCompose(['-f', compose_file, '-p', project_name, 'build', ...build_args], { stdio: 'inherit' });
const cmd = DockerComposeUtils.dockerCompose(['-f', compose_file, '-p', project_name, 'build', ...build_args], { stdin: 'inherit', stdout: 'inherit', stderr: 'pipe' });

let stderr_message = '';
try {
cmd.stderr?.on('data', (bytes) => {
stderr_message = (bytes.toString() || '').trim();
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this information is in the exception object returned by execa - I believe e.stderris available so we don't need to set the string this way. You can run console.log(e) to quickly see the various keys available - but I think that would be the same information that's being captured here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed on-data function

await cmd;
} catch (e: any) {
if (e.exitCode !== 0) {
this.logToStderr(chalk.red('Docker compose has encounted an error building the specified image:'));
throw new ArchitectError(stderr_message);
}
}
return [project_name, compose_file];
}

Expand Down
4 changes: 4 additions & 0 deletions src/dependency-manager/utils/files.ts
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs';
import yaml from 'js-yaml';
import path from 'path';
import untildify from 'untildify';
import { ArchitectError } from './errors';
import { ParsedYaml } from './types';

// https://stackoverflow.com/questions/4253367/how-to-escape-a-json-string-containing-newline-characters-using-javascript
Expand Down Expand Up @@ -38,6 +39,9 @@ export const insertFileDataFromRefs = (file_contents: string, config_path: strin
};

export const replaceFileReference = (parsed_yml: ParsedYaml, config_path: string): string => {
if ((parsed_yml || '').toString().trim().length === 0) {
throw new ArchitectError(`The file at ${config_path} is empty. For help getting started take a look at our documentation here: https://docs.architect.io/reference/architect-yml`);
}
const source_as_json = JSON.stringify(parsed_yml, null, 2);
const replaced_source = insertFileDataFromRefs(source_as_json, config_path);
const replaced_object = JSON.parse(replaced_source);
Expand Down
17 changes: 17 additions & 0 deletions test/commands/dev/index.test.ts
Expand Up @@ -1330,4 +1330,21 @@ describe('local dev environment', function () {
const runCompose = Dev.prototype.runCompose as sinon.SinonStub;
expect(runCompose.calledOnce).to.be.false;
});

test
.timeout(20000)
.stub(ComponentBuilder, 'loadFile', () => {
return '';
})
.stub(Dev.prototype, 'failIfEnvironmentExists', sinon.stub().returns(undefined))
.stub(Dev.prototype, 'runCompose', sinon.stub().returns(undefined))
.stub(Dev.prototype, 'downloadSSLCerts', sinon.stub().returns(undefined))
.stub(Dev.prototype, 'readSSLCert', sinon.stub().returns('fake-cert'))
.stdout({ print })
.stderr({ print })
.command(['dev', './examples/hello-world/architect.yml'])
.catch(err => {
expect(err.message).to.include('For help getting started take a look at our documentation here: https://docs.architect.io/reference/architect-yml');
})
.it('Provide error if architect.yml is empty');
});