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

Test balena push with docker-compose using symlinks #2408

Closed
wants to merge 1 commit into from

Conversation

thgreasi
Copy link
Member

Change-type: patch
See: https://www.flowdock.com/app/rulemotion/i-cli/threads/Yo53CeVqtfSoo4Dw_qO8B0ZD2Nu
Signed-off-by: Thodoris Greasidis [email protected]

Resolves: #
Change-type: major|minor|patch
Depends-on:
See:


Please check the CONTRIBUTING.md file for relevant information and some
guidance. Keep in mind that the CLI is a cross-platform application that runs
on Windows, macOS and Linux. Tests will be automatically run by balena CI on
all three operating systems, but this will only help if you have added test
code that exercises the modified or added feature code.

Note that each commit message (currently only the first line) will be
automatically copied to the CHANGELOG.md file, so try writing it in a way
that describes the feature or fix for CLI users.

If there isn't a linked issue or if the linked issue doesn't quite match the
PR, please add a PR description to explain its purpose or the features that it
implements. Adding PR comments to blocks of code that aren't self explanatory
usually helps with the review process.

If the PR introduces security considerations or affects the development, build
or release process, please be sure to highlight this in the PR description.

Thank you very much for your contribution!

@thgreasi thgreasi marked this pull request as draft December 13, 2021 18:54
@thgreasi thgreasi force-pushed the docker-compose-symbolic-links branch 3 times, most recently from 2bb979f to 2b1f9a0 Compare December 13, 2021 21:21
@thgreasi thgreasi marked this pull request as ready for review December 13, 2021 22:31
@thgreasi thgreasi self-assigned this Dec 13, 2021
const isDirectory =
entry.isDirectory() ||
(entry.isSymbolicLink() &&
(await fs.stat(await fs.realpath(fpath))).isDirectory());
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the realpath() call necessary? I understand that fs.stat() will (recursively) follow symlinks if fpath is a symlink (as opposed to fs.lstat()), so it would not be necessary to explicitly resolve the symlink with realpath().

Suggested change
(await fs.stat(await fs.realpath(fpath))).isDirectory());
(await fs.stat(fpath)).isDirectory());

Copy link
Member Author

Choose a reason for hiding this comment

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

TIL that fs.stat() does follow symbolic links. Nice catch 👍

@@ -0,0 +1 @@
../symlink-fixtures/service1/
Copy link
Contributor

@pdcastro pdcastro Dec 13, 2021

Choose a reason for hiding this comment

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

Build is failing on Windows with:

glob error [Error: EPERM: operation not permitted, scandir 'C:\var\lib\concourse\worker\volumes\live\a9a3a529-20a6-4d2c-748a-bf5059dd242b\volume\tests\test-data\projects\docker-compose\symbolic-links\service1'] {
  errno: -4048,
  code: 'EPERM',
  syscall: 'scandir',
  path: 'C:\\var\\lib\\concourse\\worker\\volumes\\live\\a9a3a529-20a6-4d2c-748a-bf5059dd242b\\volume\\tests\\test-data\\projects\\docker-compose\\symbolic-links\\service1'
}

It rings a bell that Windows doesn't play nicely with soft links, however out of the 5 existing tests that touch the dockerignore2 test project that uses soft links, I think only one is currently being skipped on Windows:

So maybe some investigation on how come that 4 other tests don't need to be skipped on Windows (maybe they don't really exercise the soft link aspect?) before skipping this test on Windows as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

how come that 4 other tests don't need to be skipped on Windows

This is the one that is completely skipped on Windows:

const itSkipWindows = process.platform === 'win32' ? it.skip : it;
itSkipWindows('should produce a compatible tar stream (symbolic links)'

This test is not skipped but it cheats :-) with:

			...(isWindows
				? {
						'lib/src-a.txt': { fileSize: 5, type: 'file' },
						'src/src-a.txt': { fileSize: 5, type: 'file' },
				  }
				: {}),

I think these 3 tests pass on Windows because git clone on Windows makes a real copy of the file that is pointed to by the symlink.

So, I think it would be fair to skip this test-data/projects/docker-compose/symbolic-links/service1 test case on Windows, for example with the itSkipWindows trick.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like it's related to symlinks to folders on windows 🤔
I will skip it for now since I don't have the bandwith to further investigate this, and it already adds value as is.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh wait, this might actually be a balena-lint bug :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think so, the balena-lint issue was caused by the commit that added the itNoWin call.

Copy link
Member Author

Choose a reason for hiding this comment

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

This might work, based on the comments in that issue of glob:
See: balena-io-modules/node-balena-lint#82

Copy link
Member Author

Choose a reason for hiding this comment

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

Agrrrrr. I now fails is the test:source step.
Should I just drop the tests to get this fixed sooner than later?

Copy link
Member Author

Choose a reason for hiding this comment

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

See: #2410

And I will leave this PR having only the test case, just in case someone has the patience to fix them for Windows...

Copy link
Contributor

@pdcastro pdcastro Dec 14, 2021

Choose a reason for hiding this comment

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

Before dropping the tests, how about:

  • Do not commit the service1 soft link to the git repo.
  • Have the new test case (added by this PR) dynamically create (and clean up) the soft link with fs.symlink that you had suggested in Flowdock.
  • Re-add itNoWin to the test case so that the soft link is never created on Windows.

Copy link
Member Author

@thgreasi thgreasi Dec 14, 2021

Choose a reason for hiding this comment

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

During my research I saw ppl facing such issues when creating symlinks as well, but at this point it sounds more promising than the committed one. I will add a reminder for later this week.

Note for self:
See: balanced-mt/serverless-plugin-typescript@0f57f0c

@thgreasi thgreasi force-pushed the docker-compose-symbolic-links branch 3 times, most recently from 6957e74 to a67aaf4 Compare December 13, 2021 23:21
@pdcastro
Copy link
Contributor

Build failed quickly for all platforms because of missing npm run build that calls npm run lint that modifies the source code and causes uncommitted code changes:

** Uncommitted changes found (^^^ diff above ^^^) - FAIL **
Error: "catch-uncommitted": npx failed with exit code 1:

@thgreasi thgreasi force-pushed the docker-compose-symbolic-links branch from a67aaf4 to 1d2abb7 Compare December 13, 2021 23:35
@thgreasi thgreasi marked this pull request as draft December 14, 2021 00:08
@thgreasi thgreasi force-pushed the docker-compose-symbolic-links branch 2 times, most recently from 7e219c7 to 2ff0141 Compare December 14, 2021 00:14
@thgreasi thgreasi force-pushed the docker-compose-symbolic-links branch 2 times, most recently from 27a9c8b to 989a2e3 Compare December 14, 2021 11:47
@ab77 ab77 closed this Nov 8, 2022
@otaviojacobi otaviojacobi deleted the docker-compose-symbolic-links branch March 14, 2024 17:21
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.

3 participants