keystonejs / keystone-5

https://v5.keystonejs.com
MIT License
64 stars 33 forks source link

Docker volume path can't be served as static app #113

Open zdllucky opened 3 years ago

zdllucky commented 3 years ago

Bug report

Docker volume path can't be served as static app.

Firstly thanks to maintainer folks for such a cool headless (Best one i ve used so on). Here is what I got

Describe the bug

I am trying to conteierize my app within docker and also do serve some uploads, so in order to prevent upload file loss ive decided to store those in separate docker volume. The error says it cant find the volume path A clear and concise description of the bug.

Like this My Static app configuration

new StaticApp(
    {
        path: '/uploads/',
        src: process.env.NODE_ENV === 'production' ? `/media/uploads/` : `uploads/`,
        fallback: '/'
    }
)

When I run docker I also specify my volume (-v /a:/b) and it works fine. But i get this error during docker build:

- Initialising Keystone CLI
ℹ Command: keystone build
-  
✔ Validated project entry file ./index.js
- Initialising Keystone instance
✔ Initialised Keystone instance
- Exporting Keystone build to ./dist
✖ Exporting Keystone build to ./dist
[Error: ENOENT: no such file or directory, stat '/media/uploads'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: '/media/uploads'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error response from daemon: The command '/bin/sh -c yarn install && yarn migrate && export COOKIE_SECRET=$(openssl rand -hex 32) && yarn build && yarn cache clean' returned a non-zero code: 1
Failed to deploy 'daiana_dev Dockerfile: ./docker/Dockerfile':

To Reproduce

I hope the reproduce process is qiute clean from above. Just try to add volume path as static app path

Expected behaviour

I understand that it might occur during build time when volume is still not inited but asking this kind requirement during buildtime (not launch time) seems quite irrational I actually hoped it will host static app from any runtime real location specified.

System information

zdllucky commented 3 years ago

Btw, the native express serve static works fine^ that is why I proposed bad behaviour of StaticApp

configureExpress: app => {
  app.set('trust proxy', 1);
  app.use('/uploads',
    static(process.env.NODE_ENV === 'production'
      ? `/media/uploads/`
      : `static/uploads/`, options));
}