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

chore(build) Docker fixes #1542

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

joeytwiddle
Copy link
Contributor

@joeytwiddle joeytwiddle commented Jan 7, 2023

I have managed to build with Docker but it took a few fixes. I'm on Linux.

I'll share them with you. If you run into problems with Docker builds, these may help you!

May be of interest to @fortuna or @daniellacosse who have been working around this area.

@joeytwiddle joeytwiddle requested review from a team as code owners January 7, 2023 22:28
}
console.error(chalk.red(String(error)));
Copy link
Contributor Author

@joeytwiddle joeytwiddle Jan 7, 2023

Choose a reason for hiding this comment

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

I was getting back a ChildProcess object in the error variable, which is not really desirable, but that's what happened. So I reported it by looking for the exitCode property. Now fixed in spawn_stream.mjs

Instead of logging error.message I log String(error) which should produce almost identical output for errors (it tends to have an extra "Error: " on the front). But in the undesirable case where a non-error is caught, this will at least print something.

I needed this extra error handling because, for some reason cordova/setup action was throwing a ChildProcess with exit code 1.

After debugging it here, I fixed spawnStream() which was throwing an object instead of an error, and also added a process.exit(0) to stop the failure itself.

@@ -80,3 +80,6 @@ export async function main(...parameters) {
if (import.meta.url === url.pathToFileURL(process.argv[1]).href) {
await main(...process.argv.slice(2));
}

// Without this, the script exits with code 1, causing the caller to fail
process.exit(0);
Copy link
Contributor Author

@joeytwiddle joeytwiddle Jan 7, 2023

Choose a reason for hiding this comment

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

I have no idea why this was needed, but it was!

This (silent) failure was why I added the extra error handling run run_action.mjs.

const uid = os.userInfo().uid;
if (uid !== 0) {
console.error(`It might be non-writable because you are running as ${uid} instead of running as root.`);
console.error(`A workaround is to run 'node ./src/cordova/build.action.mjs' instead of 'npm run action cordova/build'`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason ./tools/build.sh npm run action cordova/build drop to a user account inside the container,

while ./tools/build.sh node ./src/cordova/build.action.mjs runs as root.

If we can make the first one run as root, then this commit could probably be removed/reverted.

@@ -33,4 +33,9 @@ ENV CI=true

COPY ./setup_linux_android.sh ./setup_linux_android.sh

# We define the variable here, so it can be seen by both the setup script, and the running container
ENV ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT:-"/opt/android-sdk"}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this, when we finally run the build, it doesn't know where to find the SDK.

Copy link
Contributor Author

@joeytwiddle joeytwiddle left a comment

Choose a reason for hiding this comment

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

These are some problems I had, and how I resolved them.

Up to you whether you want to merge this, or address the issues elsewhere in code or docs.

I'm hoping this will save you some time, rather than cost more.

Feel free to close if you are planning on other solutions. I will still have my branch when I need it!

@@ -37,7 +37,7 @@ export const spawnStream = (command, parameters) =>
if (code === 0) {
resolve(childProcess);
} else {
reject(childProcess);
reject(new Error(`Process '${command}' failed with error code ${code}`));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As with throw, we should always reject with an Error object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant