Skip to content
This repository has been archived by the owner on Jan 28, 2025. It is now read-only.

CDK Construct - Wrong s3 paths generated when deploying from windows #1016

Closed
kostenickj opened this issue Apr 22, 2021 · 14 comments
Closed

Comments

@kostenickj
Copy link

kostenickj commented Apr 22, 2021

Describe the bug

A backslash instead of a forward slash is generated on the static folder, as show below
image

Actual behavior

this causes CloudFront (and pretty much everything) to fail on everything in that folder and get 403's

Expected behavior

slash should point the right way, like this:
_next/static/

Steps to reproduce

Deploy with cdk construct on windows.
You can see below im using building from a different directory, although i dont know if that makes a difference.

Screenshots/Code/Logs

my builder:
image
image

Versions

packages:
image

  • OS/Environment: windows 10
  • Next.js version: 10

Additional context

I am going to test on linux and see if it still happens.
By the way, renaming the folder in s3 to the correct structure fixes literally everything.
This error does NOT happen when using the serverless component version, only cdk construct.

Checklist

@kostenickj kostenickj changed the title CDK Construct - Wrong s3 paths generated when deploying on windows CDK Construct - Wrong s3 paths generated when deploying from windows Apr 22, 2021
@dphang
Copy link
Collaborator

dphang commented Apr 23, 2021

Probably this line needs to be changed to path.posix.relative?

destinationKeyPrefix: path.relative(assetsDirectory, assetPath),

Can you try to update this and see if it works?

@kostenickj
Copy link
Author

I made that change and it failed to deploy on creation of the deployment bucket. I changed it back and it deployed fine, but with the same path error as before

@dphang
Copy link
Collaborator

dphang commented Apr 23, 2021

I see, basically I think just some places need to use the posix path which use "/" separator, maybe it is in another line. @kirkness would probably know better since he originally wrote this?

@kirkness
Copy link
Collaborator

Hi @kostenickj, you say it failed to deploy when you made that fix, what was the error you saw in the logs?

@kostenickj
Copy link
Author

kostenickj commented Apr 26, 2021

Here is where the initial failure happens:

image

Also, I was able to confirm my project deploys fine on linux, so definitely a windows thing.

@kirkness
Copy link
Collaborator

It's likely a simple fix, although without access to a windows machine myself it'll be a little tricky! Is the above error occurring after setting destinationKeyPrefix to path.posix.relative(...)? It looks as if its using win32 still as the formed command is copying files from a posix path to win32?

@kostenickj
Copy link
Author

Yes, i changed it to look like this:

image

@kirkness
Copy link
Collaborator

Cheers for clarifying @kostenickj. From what I can tell, it looks as if the trouble comes from the sources value (as well as the destinationKeyPrefix). The readAssetsDirectory returns values/paths according to the OS, however it appears those are carried through when running on distributions custom resource (based on what I can see in the error message). I'm wondering whether this could be resolved by setting each of the paths returned by readAssetsDirectory using path.posix.join()? Are you able to test this?

@kostenickj
Copy link
Author

@kirkness Ill give this a go today, and let you know!

@dphang
Copy link
Collaborator

dphang commented Apr 28, 2021

I made a possible fix, looks like invalidation paths also need to use posix path: #1025. Though I also don't have windows machine I can use to test, hopefully it works.

On a related note, we should probably also add at least an e2e test for windows and/or CDK so it doesn't break in the future

@kostenickj
Copy link
Author

Didn't have a chance to test yesterday, but i will give it a go today.

@kirkness
Copy link
Collaborator

On a related note, we should probably also add at least an e2e test for windows and/or CDK so it doesn't break in the future

Agreed on this - e2e tests would be great. Not sure how the current e2e are set up but it'd be nice to have the same setup across both.

@kostenickj
Copy link
Author

I am unable to get this to build correctly, so i will wait until a new alpha release before i can test further.

@dphang
Copy link
Collaborator

dphang commented Apr 28, 2021

Have published it, let me know if it works.

@kirkness

Right now e2e tests work by just using a deployment script to manually execute serverless command, run cypress tests and then cleanup all build artifacts, you might be able to create a similar script for CDK deployment and run it as well. Maybe to avoid duplication it can be in next-app package and just run under a different app name to avoid conflicts. But that can be done later

@dphang dphang closed this as completed Apr 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants