Azure / draft-classic

A tool for developers to create cloud-native applications on Kubernetes.
https://draft.sh
MIT License
3.92k stars 397 forks source link

draft up error when app is referencing a library from the parent directory #814

Closed IvanFarkas closed 6 years ago

IvanFarkas commented 6 years ago

Draft Up Referencing Source in Parent Directory

The goal is to use draft up to deploy this application to a Kubernetes cluster. The challange is that the app is referencing a library from the parent directory. I created the DraftReferencingSourceInParentDir app to demonstrate the issue. draft up cannot execute in the example-dotnet project directory since the docker build will return a no such file or directory error for the library project.

cd [App Root]\src\example-dotnet
draft up

Result

Draft Up Started: 'example-dotnet': 01CFAVZ5N7GF78FPD6MRSP197H
example-dotnet: Building Docker Image: FAIL ❌  (1.0010s)
Inspect the logs with `draft logs 01CFAVZ5N7GF78FPD6MRSP197H`

Log draft logs 01CFAVZ5N7GF78FPD6MRSP197H

...
Step 6/19 : COPY src/Lib/Lib.csproj src/Lib/
2018/06/06 11:38:14 error while building: COPY failed: stat /var/lib/docker/tmp/docker-builder786413135/src/Lib/Lib.csproj: no such file or directory

Build Docker Container & Run Docker Image

docker build have to be called from the solution root directory to build a docker image and run it. This is demonstrated below. The app is working on docker following these steps.

cd [Solution Root]
docker build -t ivanfarkas/example-dotnet -f src/example-dotnet/Dockerfile .
docker run -p 8080:80 ivanfarkas/example-dotnet

Open a new console

curl localhost:8080

Result

Hello World! 2

Question

How do I use draft up when the app is referencing a library from the parent directory?

christiansparre commented 6 years ago

I'm having this exact issue as well, got about 2 minutes into using draft when I hit this :(

What is the workflow for using draft with ASP.NET Core when you have multiple projects?

IvanFarkas commented 6 years ago

I think they expect you to package your libraries as a NuGet package and upload them to your private NuGet server. This way the Dockerfile refers only current context or subdirectories.

bacongobbler commented 6 years ago

bingo. The application directory should contain (ha!) everything to containerize your application. If your application relies on external dependencies outside of the docker context, then you'll need to either

a) ship it as a NuGet package as @IvanFarkas mentions, OR b) run draft create from the parent directory, so Docker has the necessary context required to build and package your application.

The container should live in a directory where it'll have the context required to build your application entirely from source. If your external dependencies can be packaged, that's even better :)

bacongobbler commented 6 years ago

For an example, have a look at the example-python app, which contains source code (app.py) and compiles external dependencies (requirements.txt).

IvanFarkas commented 6 years ago

Fantastic! We figured it out @bacongobbler. I can close this now.

timjroberts commented 5 years ago

How did you figure it out? I'm having a similar issue where I have a solution with one project referencing the others. I'd like to simply set the docker context in the draft.toml file don't think that I can.