Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple profile for docker compose project #252

Open
mhamri opened this issue May 1, 2020 · 3 comments
Open

Multiple profile for docker compose project #252

mhamri opened this issue May 1, 2020 · 3 comments

Comments

@mhamri
Copy link

mhamri commented May 1, 2020

Hi there,

discussing with @poppastring, he asked me to create an issue in here

@poppastring if you remember, I whined about the docker support in the #VisualStudio awhile back and you guided me to this documenthttps://t.co/4KYpbJ1qkt

— Mohammad Hossein Amri (@AmrimhM) April 23, 2020

I played around with the docker-compose project and I have a couple of problem with it

1- the docker project always is created in the root folder and if you want to add multiple of that, it always overrides each others. it's a disaster for a mono repo.
2- but let's assume that there should be a single docker project in a solution. then we should be able to create multiple profile. depending on the set of applications that we want to run.
for example one profile can be docker-compose for backend+ docker compose for db & caching.
another profile is without caching. another is for running a test. ....

image

3- if I want to mix and match different docker-compose file, there is only a single XML property in the dcproj file. first, the dcproj is not easily editable, if I right-click on the docker-project, I won't get edit project, as it's available for other project types.

image for normal csproj

but as you can see, this isn't the case for a dcproj

image
second, there is no way to tell the docker tools that for example the database is running out of the docker-compose. this way my developer needs to run a set of docker manually outside of the visual studio. I searched if I can find any target in the MSBuild that can make the running of extra composer automated inside the dcproj but I couldn't hook into any available targe.t
4- what I was asking from @poppastring was to have something like launchSetting.Json in the docker project and have all the dcproj properties configurations in a JSON file, instead of the dcproj. this way we can have multiple profiles with multiple settings.
5-also regard to the available properties in the dcproj, there is a lacking of having a property that let me set the docker-compose context folder. dcproj always assume that the context starts from where it is. referring back to #1 it should be configurable if you let more than one dcproj in a solution.
6- I'm loading some extra compose files for Redis or frontend (angular) with AdditionalComposeFilePaths. later I noticed docker tools is creating an obj folder next to those docker files. I'm not sure why docker tools should add those extra files next to the docker file and not docker compose. especially it's not a dotnet project

@NCarlsonMSFT
Copy link
Member

NCarlsonMSFT commented May 2, 2020

  1. Having multiple .dcproj is not supported, but it is not blocked. The easiest way to add a second compose project to a solution is:

    1. Create a new folder in the solution folder
    2. Copy docker-compose.* to the folder
    3. Rename the .dcproj to have a unique name (VS does not allow two projects with the same name)
    4. Open the .dcproj in a text editor and change the value for <ProjectGuid>...</ProjectGuid> to a new GUID (VS also does not allow two projects with the same ID)
      • FYI VS has a UI on Tools->Create GUID for generating a new one if you need:
        Tools->Create GUID
    5. While you're editing the .dcproj, you'll need to change any relative paths to files you did not copy. For instance <None Include=".dockerignore" /> to <None Include="..\.dockerignore" /> (assuming your project is now nested one folder deep)
    6. In VS you can now add the new project to your solution using the solution context menu->Add->Existing Project...
      Add->Existing Project...
    7. The only step left is to go through your compose files and update any relative paths for the new location. (Pro-tip properties like context are relative to the .yml file, but some properties like dockerfile are relative to context)

    If you'd like this to be supported through the UI (or run into an issue with multiple projects), please open a separate issue so we can triage and track it individually.

  2. We don't support launch profiles. But you should be able to achieve what you are asking for using VS Configurations. To create a new configuration with different compose files:

    1. Open the Configuration Manager:
      <Configuration Manager...>

    2. Select the <New...> configuration:
      <New...>

    3. Enter a name for the new configuration, and pick a base configuration to copy, and click OK.
      New Solution Configuration

    4. Unload the .dcproj and add a property group for the new configuration:

    <PropertyGroup Condition="'$(Configuration)' == 'Debug With Redis'">
        <!-- This is the name of your main compose file w/o the .yml-->
        <DockerComposeBaseFilePath>docker-compose.test</DockerComposeBaseFilePath>
        <!-- This is a semicolon-delimited list of additional .yml files to include when launching -->
        <AdditionalComposeFilePaths>$(MSBuildPojectDirectory)docker-compose.redis.yml</AdditionalComposeFilePaths>
        <!-- Because this is a custom configuration you need to opt into Fast mode -->
        <DockerDevelopmentMode>Fast</DockerDevelopmentMode>
        <!-- Best to move these properties here from the Globals section -->
        <DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
        <DockerServiceUrl>{Scheme}://localhost:{ServicePort}</DockerServiceUrl>
        <DockerServiceName>webapplication12</DockerServiceName>
    </PropertyGroup>
    
    1. Edit your service projects and add a property group for the new configuration:
    <PropertyGroup Condition=" '$(Configuration)' == 'Debug With Redis'">
        <DebugSymbols>true</DebugSymbols>
        <Optimize>false</Optimize>
    </PropertyGroup>
    

    If you feel this is insufficient and would like to pursue getting support for launch profiles, please open a separate issue for that so we can triage and track it individually.

  3. a) For the single XML property: see 2 above for being able to use multiple configurations
    b) For "Edit Project File" support: That is something we could investigate adding. Please open an issue for that so we can triage and track it individually.
    c) I'm not sure I understand what you mean by "there is no way to tell the docker tools that for example the database is running out of the docker-compose". Could you please elaborate?

  4. See 2 above.

  5. Which context are you referring to? The build context for each service is configured in the compose file with paths relative to the compose file. If you would like your compose file to be in a folder rather than next to your .dcproj you can set the property DockerComposeBaseFilePath. For example: <DockerComposeBaseFilePath>Folder\docker-compose</DockerComposeBaseFilePath> would use Folder\docker-compose.yml

  6. Please open a separate issue for this so we can triage and track it individually.

@mhamri
Copy link
Author

mhamri commented Jun 12, 2020

Thanks for the detailed explanation, I will play with it and come back to you,

in meanwhile, what is the DebugSymbols and why do you need to make the Optimize false in here?

<PropertyGroup Condition=" '$(Configuration)' == 'Debug With Redis'">
    <DebugSymbols>true</DebugSymbols>
    <Optimize>flase</Optimize>
</PropertyGroup>

as far as I understand, setting the Optimize to false stop the service to be build-out of the docker and make the dev flow slower

@NCarlsonMSFT
Copy link
Member

@mhamri Those properties don't effect the container, but the .NET build.

If you look through Microsoft.NET.Sdk.props (which is what I did when drafting my response). Those properties are all set by default for a Debug Configuration, and control telling the compiler to optimize your code for enabling debugging rather than for production performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants