Skip to content
This repository was archived by the owner on Feb 13, 2019. It is now read-only.

Dockerfile for RC2. Fixes #685 #743

Merged
merged 4 commits into from
Jun 14, 2016
Merged

Conversation

sesispla
Copy link
Contributor

Fixes #685.

Summary of the changes in this PR:

  • Modified Dockerfile.txt template to fit dotnet cli commands (restore, build...)
  • Added Microsoft.Extensions.Configuration.CommandLine NuGet package to project.json web, webapi and web basic templates
  • Added CommandLine ConfigurationBuilder to fix Kestrel endpoint configuration through Dockerfile ENTRYPOINT

Thanks!

/cc
@OmniSharp/generator-aspnet-team-push

Added ConfigurationBuilder to WebHostBuilder for Dockerfile launch configuration

Added ConfigurationBuilder to WebHostBuilder for Dockerfile launch configuration
@peterblazejewicz
Copy link
Member

@sesispla
you need to update tests test/subgenerators.js:
The block:

  describe('aspnet:Dockerfile Mono-based', function() {
    var filename = 'Dockerfile';
    util.goCreate(filename);
    util.fileCheck('should create Dockerfile', filename);
    util.fileContentCheck(filename, 'Check the content for Mono-based image tag', /FROM microsoft\/aspnet:1\.0\.0-rc1-update1/);
  });

  describe('aspnet:Dockerfile CoreCLR-based', function() {
    var arg = '--coreclr';
    var filename = 'Dockerfile';
    util.goCreateWithArgs(filename, [arg]);
    util.fileCheck('should create Dockerfile', filename);
    util.fileContentCheck(filename, 'Check the content for CoreCLR-based image tag', /FROM microsoft\/aspnet:1\.0\.0-rc1-update1-coreclr/);
  });

should be changed to covers only single image now. At the moment PR cannot be merged as tests are failing on Travis CI tests.
Thanks!

@peterblazejewicz
Copy link
Member

It works:
image

Let me know if you need help with tests.

@sesispla
Copy link
Contributor Author

Fixed, sorry :)

@peterblazejewicz
Copy link
Member

Also 'emptyweb' template Program.cs and project.json need the same modification as in web, webbasic, webapi

@sesispla
Copy link
Contributor Author

Done! I also cleaned some code that might change due to #530

@peterblazejewicz
Copy link
Member

It does not work without SQLite I think:

dotnet ef database update
Project app (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
System.DllNotFoundException: Unable to load DLL 'sqlite3': The specified module could not be found.
 (Exception from HRESULT: 0x8007007E)
   at Microsoft.Data.Sqlite.Interop.NativeMethods.Sqlite3_sqlite3.sqlite3_open_v2(IntPtr filename, Sqlite3Handle& ppDb, Int32 flags, IntPtr vfs)
   at Microsoft.Data.Sqlite.Interop.NativeMethods.sqlite3_open_v2(String filename, Sqlite3Handle& ppDb, Int32 flags, String vfs)
   at Microsoft.Data.Sqlite.SqliteConnection.Open()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open()
   at Microsoft.EntityFrameworkCore.Storage.Internal.SqliteRelationalConnection.Open()
   at Microsoft.EntityFrameworkCore.Storage.Internal.SqliteDatabaseCreator.Exists()
   at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
   at Microsoft.EntityFrameworkCore.Tools.Cli.DatabaseUpdateCommand.<>c__DisplayClass0_0.<Configure>b__0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
Unable to load DLL 'sqlite3': The specified module could not be found.
 (Exception from HRESULT: 0x8007007E)

(run from Docker interactive terminal in image). The current EF in RC2 template for starter web with accounts (web template) ships without initialization routine. The user has to initialize EF via: dotnet ef database update before calling dotnet run. The Dockerfile for web template will have to use:

RUN ["dotnet", "ef", "database", "run"]

So the template has to cover SQLite installation on the image and EF migration before app is run

@peterblazejewicz
Copy link
Member

If we need - the template can be instructed with project type in app/index.js:

this.templatedata.type = this.type;

and later in Dockertemplate the relevant IF block can be used to include SQL and EF related Docker instructions.
Thoughts?

@peterblazejewicz
Copy link
Member

@sayedihashimi
Are you folks OK with small changes to Program.cs and project.json required to run Docker file out-of-the-box in generator? Unfortunately current aspnet/Templates implementation does not allow that (when ported as-is to generator).

@sesispla
Copy link
Contributor Author

@peterblazejewicz I tried to create a Docker container using the EF team recommended commands (prior to adding the this.templatedata.type logic for ASP.NET Membership based projects):

FROM microsoft/dotnet:latest

RUN printf "deb http://ftp.us.debian.org/debian jessie main\n" >> /etc/apt/sources.list
RUN apt-get -qq update && apt-get install -qqy sqlite3 libsqlite3-dev && rm -rf /var/lib/apt/lists/*

COPY . /app
WORKDIR /app
RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]

EXPOSE 5000/tcp
ENTRYPOINT ["dotnet", "run", "--server.urls", "http://0.0.0.0:5000"]

BUT it seems the apt-get mirror is down:

Sending build context to Docker daemon  10.9 MB
Step 1 : FROM microsoft/dotnet:latest
 ---> f315e6bbb53f
Step 2 : RUN printf "deb http://ftp.us.debian.org/debian jessie main\n" >> /etc/apt/sources.list
 ---> Running in 03da687e3378
 ---> 316728b4dec0
Removing intermediate container 03da687e3378
Step 3 : RUN apt-get -qq update && apt-get install -qqy sqlite3 libsqlite3-dev && rm -rf /var/lib/apt/lists/*
 ---> Running in 16a6d68e4617
W: Failed to fetch http://llvm.org/apt/jessie/dists/llvm-toolchain-jessie-3.6/main/binary-amd64/Packages  404  Not Found

E: Some index files failed to download. They have been ignored, or old ones used instead.
The command '/bin/sh -c apt-get -qq update && apt-get install -qqy sqlite3 libsqlite3-dev && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 100
Sergios-MacBook-Pro:WebApplicationBasic Sergio$ 

Checked with the browser...
screen shot 2016-06-13 at 19 38 01

So, maybe we can close this PR for #685 (covering empty web, api and basic without authentication) and keep working on a more elaborated solution for #532 (I'll put some thoughts on this issue)

What do you think?

@peterblazejewicz
Copy link
Member

This one worked:

FROM microsoft/dotnet:latest

RUN apt-get update && apt-get install sqlite3 libsqlite3-dev

COPY . /app
WORKDIR /app

RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
RUN ["dotnet", "ef", "database", "update"]

EXPOSE 5000/tcp
ENTRYPOINT ["dotnet", "run", "--server.urls", "http://0.0.0.0:5000"]

The EF (web project) does require:

RUN apt-get update && apt-get install sqlite3 libsqlite3-dev

and:

RUN ["dotnet", "ef", "database", "update"]

The sqlite installation is certainly a go:
dotnet/efcore#5382
The Dockerfile by Microsoft for dotnet app:
https://github.com/Microsoft/generator-docker/blob/master/generators/app/templates/dotnet/Dockerfile

@peterblazejewicz
Copy link
Member

This one runs on Docker beta on OS X:
image

@sesispla
Copy link
Contributor Author

Proceeding to implement the conditional apt-get command for "web" projects

But, very estrange, BTW... Using your Dockerfile spec:

Sending build context to Docker daemon 12.65 MB
Step 1 : FROM microsoft/dotnet:latest
 ---> f315e6bbb53f
Step 2 : RUN apt-get update && apt-get install sqlite3 libsqlite3-dev
 ---> Running in 048921bce8c7
Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]
Ign http://llvm.org llvm-toolchain-jessie-3.6 InRelease
Get:2 http://security.debian.org jessie/updates/main amd64 Packages [342 kB]
Ign http://llvm.org llvm-toolchain-jessie-3.6 Release.gpg
Ign http://httpredir.debian.org jessie InRelease
Get:3 http://httpredir.debian.org jessie-updates InRelease [142 kB]
Ign http://llvm.org llvm-toolchain-jessie-3.6 Release
Err http://llvm.org llvm-toolchain-jessie-3.6/main amd64 Packages

Get:4 http://httpredir.debian.org jessie Release.gpg [2373 B]
Err http://llvm.org llvm-toolchain-jessie-3.6/main amd64 Packages

Get:5 http://httpredir.debian.org jessie Release [148 kB]
Err http://llvm.org llvm-toolchain-jessie-3.6/main amd64 Packages

Err http://llvm.org llvm-toolchain-jessie-3.6/main amd64 Packages

Err http://llvm.org llvm-toolchain-jessie-3.6/main amd64 Packages
  404  Not Found
Get:6 http://httpredir.debian.org jessie-updates/main amd64 Packages [17.6 kB]
Get:7 http://httpredir.debian.org jessie/main amd64 Packages [9032 kB]
Fetched 9747 kB in 7s (1368 kB/s)
W: Failed to fetch http://llvm.org/apt/jessie/dists/llvm-toolchain-jessie-3.6/main/binary-amd64/Packages  404  Not Found

E: Some index files failed to download. They have been ignored, or old ones used instead.
The command '/bin/sh -c apt-get update && apt-get install sqlite3 libsqlite3-dev' returned a non-zero code: 100

After removing all local Docker images it worked... (Some sort of image caching issue)

Sending build context to Docker daemon 12.65 MB
Step 1 : FROM microsoft/dotnet:latest
latest: Pulling from microsoft/dotnet
5c90d4a2d1a8: Pull complete 
ab30c63719b1: Pull complete 
c6072700a242: Pull complete 
2a65fccac866: Pull complete 
973b97c12bc6: Pull complete 
Digest: sha256:f8950190a4dee0eafeba759a36c99a387adb1d3cc5467b2a30b788097b774c1f
Status: Downloaded newer image for microsoft/dotnet:latest
 ---> 1707bb9a2d73
Step 2 : RUN apt-get update && apt-get install sqlite3 libsqlite3-dev
 ---> Running in 5af3813b88b9
Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]
Get:2 http://security.debian.org jessie/updates/main amd64 Packages [342 kB]
Ign http://httpredir.debian.org jessie InRelease
Get:3 http://httpredir.debian.org jessie-updates InRelease [142 kB]
Get:4 http://httpredir.debian.org jessie Release.gpg [2373 B]
Get:5 http://httpredir.debian.org jessie Release [148 kB]
Get:6 http://httpredir.debian.org jessie-updates/main amd64 Packages [17.6 kB]
Get:7 http://httpredir.debian.org jessie/main amd64 Packages [9032 kB]
Fetched 9747 kB in 7s (1348 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
Suggested packages:
  sqlite3-doc
The following NEW packages will be installed:
  libsqlite3-dev sqlite3
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 639 kB of archives.
After this operation, 1686 kB of additional disk space will be used.
Get:1 http://httpredir.debian.org/debian/ jessie/main libsqlite3-dev amd64 3.8.7.1-1+deb8u1 [538 kB]
Get:2 http://httpredir.debian.org/debian/ jessie/main sqlite3 amd64 3.8.7.1-1+deb8u1 [101 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 639 kB in 1s (624 kB/s)
Selecting previously unselected package libsqlite3-dev:amd64.
(Reading database ... 14779 files and directories currently installed.)
Preparing to unpack .../libsqlite3-dev_3.8.7.1-1+deb8u1_amd64.deb ...
Unpacking libsqlite3-dev:amd64 (3.8.7.1-1+deb8u1) ...
Selecting previously unselected package sqlite3.
Preparing to unpack .../sqlite3_3.8.7.1-1+deb8u1_amd64.deb ...
Unpacking sqlite3 (3.8.7.1-1+deb8u1) ...
Setting up libsqlite3-dev:amd64 (3.8.7.1-1+deb8u1) ...
Setting up sqlite3 (3.8.7.1-1+deb8u1) ...
 ---> c7e212eaac71
Removing intermediate container 5af3813b88b9
Step 3 : COPY . /app
 ---> 0c5b6f318dae
Removing intermediate container b55c460729d7
Step 4 : WORKDIR /app
 ---> Running in 3e60be204e55
 ---> abb22a3639bc
Removing intermediate container 3e60be204e55
Step 5 : RUN dotnet restore
 ---> Running in e98bbfbd684b
...

@peterblazejewicz
Copy link
Member

@sesispla
I'll merge this and later refactor EF/SQLite and things.
Many thanks for input and PR!

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

Successfully merging this pull request may close these issues.

Update Docker template for RC2
2 participants