scaleway / serverless-scaleway-functions

Plugin for Serverless Framework to allow users to deploy their serverless applications on Scaleway Functions
MIT License
78 stars 25 forks source link

Support for Dockerfile that is not in main folder of the build context #100

Closed korridor closed 2 years ago

korridor commented 2 years ago

I currently have an application with the following folder structure:

I think this currently does not work because the Dockerfile in not in the main build context folder. Is there any way to make that work?

thomas-tacquet commented 2 years ago

Hello 👋

In your Dockerfile located in docker/image1 how do you want to import your codefilesX ?

Do you want to use COPY codefile1 ./ or something like that ?

Have you succeed to run a raw docker build (+ your args) command with this directory setup ?

korridor commented 2 years ago

Hi 👋

Yes, I would like to have the build context in the main folder. The Dockerfile could contains something like this:

COPY codefile1 ./

A docker command would look something like that:

docker build -t someimage:tag -f docker/image1/Dockerfile .

I think the ideal solution would be to be able to define the path to the Dockerfile (-f option) and the build context (docker build argument). But fixing the build context to . and only making the -f option configurable would also work for me.

thomas-tacquet commented 2 years ago

The problem we face to allow your use case is that we need to tarball the whole folder (Dockerfile + context) because we use dockerode npm package (doc here :https://github.com/apocas/dockerode#building-an-image) , you can check it here : https://github.com/scaleway/serverless-scaleway-functions/blob/88c9ad663e9fbeb7921c53822db586a55203ec06/deploy/lib/buildAndPushContainers.js#L77

There is a second way to use dockerode but we need to give it all files to src: agrument before building the image, it's not very user friendly.

So if I take your example :

We need to "merge" the context + the Dockerfile in a single archive it can lead to conflicts 🤔

For now I couldn't find a clean and satisfying solution that does not involve eventual breaking changes for users (depending on other users folder structure) 💭

thomas-tacquet commented 2 years ago

Hello 👋

For now I close the issue because I haven't found non-breaking way to implement this use case using dockerode 🤔

I don't lock the discussion if I find a way to implement it I'll let you know 👌