ligershark / sidewafflev2

Other
30 stars 11 forks source link

Issue with location of Dockerfile when using template #34

Open mlorbetske opened 6 years ago

mlorbetske commented 6 years ago

From @LeighF51 on June 5, 2018 15:59

Hi,

I have a template with 3 projects (one of them being a docker project) that are setup in a template. When creating a new solution from the template the docker file in my service project is included but it is stored away in a set of folders rather than being left at the root of the project it should be part of.

I've tried including a copyOnly section in my template.json but it doesn't seem to work with the DockerFile.

{
  "author": "Author",
  "classifications": [],
  "description": "Service Package Template, generates a set of projects that can be bundled up into a nuget package for service usage",
  "name": "Service Template (.NET Core)",
  "defaultName": "Test",
  "identity": "Sample.Template.CSharp",
  "groupIdentity": "Sample.Template",
  "tags": {
    "language": "C#",
    "type": "project"
  },
  "shortName": "NetCoreServiceTemplate",
  "sourceName": "NetCoreServiceTemplate",
  "guids": [
    "{05DCBF2B-411C-45E0-B5F2-7E8E3120670F}",
    "{73E50470-2CD5-4CD0-89CB-E54FA997F56B}"
  ],
  "primaryOutputs": [
    {
      "path": "TestServiceTemplate\\TestServiceTemplate.csproj"
    },
    {
      "path": "TestServiceTemplateLibrary\\TestServiceTemplateLibrary.csproj"
    }
  ],
  "sources": [
    {
        "include":[
            "**/*"
        ],
        "exclude": [
            "**/[Tt]estServiceTemplateVsix/**",
            "**/*.sln",
            "**/.template.config/**"
        ],      
        "copyOnly": [
            "**/DockerFile"
        ]
    }  
  ]
}

image As the image above shows the window on the left displays the path where the file gets stored when creating a solution using the template and the one on the right shows the root of the project where the dockerfile should be based on the location it was at in the template.

I'm not sure if the issue with the dockerfile being stored elsewhere is due to it not having an extension? Is there a way of me controlling where this file gets stored to in the projects generated from a template?

Copied from original issue: dotnet/templating#1551

mlorbetske commented 6 years ago

From @seancpeters on June 5, 2018 23:54

Could you post some info on the directory structure of your template source, including:

The existence or lack of a file extension shouldn't affect the output location of any files.

mlorbetske commented 6 years ago

From @LeighF51 on June 6, 2018 7:16

@seancpeters

In the source the dockerfile can be found at the root of the service template project i.e. C:\Users\fyfieldl\source\Templates\ServiceTemplate\NetCore\NetCoreServiceTemplate - from here I have the dockerfile, csproj etc image

This structure for the docker file can also be seen in the template in the solution view image

The template.json file is stored one directory up from the service template itself (as it's a multi project template) inside the .template.config folder image image

Hope this is enough info

mlorbetske commented 6 years ago

From @seancpeters on June 8, 2018 21:26

@LeighF51 - I'm going to need to play with a copy of your template to figure out what's going on. Is the template source in a repo where I can download it?

Also, are you invoking this template only from VS, or also using "dotnet new"?

mlorbetske commented 6 years ago

From @LeighF51 on June 11, 2018 9:50

@seancpeters

You can find a version of the template at https://github.com/LeighF51/ServiceTemplate

Only invoking the template from VS, not using dotnet new at all

mlorbetske commented 6 years ago

Taking a look at the nupkg generated when building the solution in the repo, it looks like the docker file is being placed at a different location than expected.

To get the behavior you expect, the file would need to be located at Content\NetCoreServiceTemplate\Dockerfile

But it's actually located here instead Content\NetCoreServiceTemplate\Dockerfile\NetCoreServiceTemplate\Dockerfile

It looks like this is being done as part of the SideWaffle build process (nothing's jumping out as being a customization that'd have this effect), I'll move this issue to that repo.

rsaltrelli commented 5 years ago

I'm encountering this same problem. Seems to be because Dockerfile has no file extension. If I rename it to Dockerfile.txt then the problem goes away. What is the resolution/workaround for this?

revealyan commented 2 years ago

my Dockerfile doesn't copy to template workaround 1)rename Dockerfile -> Dockerfile.d 2)add the parameter

"RenameDocker": {
            "type": "parameter",
            "datatype": "text",
            "fileRename": "Dockerfile.d",
            "defaultValue": "Dockerfile"
}

3)hide the parameter in dotnetcli.host.json or ide.host.json