sst / ion

❍ — a new engine for SST
https://ion.sst.dev
MIT License
1.09k stars 126 forks source link

cluster service does not properly support absolute context paths #446

Closed ravenscar closed 1 month ago

ravenscar commented 1 month ago

Original issue is here: https://github.com/sst/ion/issues/424 this was closed prematurely without fixing the bug I was experiencing.

if you create a cluster like this:

    cluster.addService("MyService", {
      image: {
        context: '/Users/foobar/code/experiments/sst-cluster',
        dockerfile: '/Users/foobar/code/experiments/sst-cluster/infra/test/Dockerfile'
      }
    });

Where the context/dockerfile paths are absolute, and the Dockerfile is in a subpath of the context then sst deploy fails with:

×  Failed
   Error: ENOENT: no such file or directory, open '/Users/foobar/code/experiments/sst-cluster/infra/Users/foobar/code/experiments/sst-cluster/.dockerignore'
       at Object.writeFileSync (node:fs:2352:20)
       at file:///Users/foobar/code/experiments/sst-cluster/infra/.sst/platform/src/components/aws/service.ts:292:14
       at /Users/foobar/code/experiments/sst-cluster/infra/.sst/platform/node_modules/@pulumi/output.ts:404:31
       at Generator.next (<anonymous>)
       at /Users/foobar/code/experiments/sst-cluster/infra/.sst/platform/node_modules/@pulumi/pulumi/output.js:21:71
       at new Promise (<anonymous>)
       at __awaiter (/Users/foobar/code/experiments/sst-cluster/infra/.sst/platform/node_modules/@pulumi/pulumi/output.js:17:12)
       at applyHelperAsync (/Users/foobar/code/experiments/sst-cluster/infra/.sst/platform/node_modules/@pulumi/pulumi/output.js:245:12)
       at /Users/foobar/code/experiments/sst-cluster/infra/.sst/platform/node_modules/@pulumi/output.ts:316:13 {
     errno: -2,
     code: 'ENOENT',
     syscall: 'open',
     path: '/Users/foobar/code/experiments/sst-cluster/infra/Users/foobar/code/experiments/sst-cluster/.dockerignore',
     promise: Promise { <rejected> [Circular *1] }
   }

Docker allows context paths which do not have to be in a sub-directory relative to the dockefile, they can be parent directories or the Dockerfile and context can be separated. A docker context must be absolute if it is not a sub-directory, e.g. ../ is not a valid context.

Currently SST assumes the context will be in a relative position to the $cli.paths.root, this may not be the same root of the project in all cases, e.g. a monorepo where the modules are hoisted to a parent package.json.

Currently it is not possible to deploy a service having a context with an absolute path which is a parent directory of the sst.config.ts.

jayair commented 1 month ago

Does it not work in 0.0.380?

ravenscar commented 1 month ago

nope I tried this in 0.383, I don't think it's an issue with the dockerfile but the .dockerignore

thdxr commented 1 month ago

ah i see - the thing is in SST we try to ensure all paths across all resources are relative to the sst.config.ts for consistency - if you specify it as a relative path eg ../../something does that work?

ravenscar commented 1 month ago

the paths are provided by our CI/CD system so I was just hoping it would work. In the end I just perform the build outside of sst so I am closing the issue.