Permalink
Browse files

🐳 Use explicit 1.1.0 version tag in Dockerfile. Closes #854

* Use explicit version tag for Docker base image

* Make sure the project.json and Dockerfile reference the same CLR

* No ES2015 syntax

* Fix copy&paste error

* Add Dockerfile for Windows Nano Server

Thansk to @mauricedb!
  • Loading branch information...
1 parent 4e49c21 commit 20b75f380c467f71517868d00aab6b61fc90a8bd @mauricedb mauricedb committed with peterblazejewicz Dec 3, 2016
Showing with 38 additions and 3 deletions.
  1. +7 −0 app/index.js
  2. +15 −0 templates/Dockerfile.nano.txt
  3. +1 −1 templates/Dockerfile.txt
  4. +15 −2 test/subgenerators.js
View
@@ -228,6 +228,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({
this.copy(this.sourceRoot() + '/web.config', this.applicationName + '/web.config');
this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.txt', this.applicationName + '/Dockerfile', this.templatedata);
+ this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.nano.txt', this.applicationName + '/Dockerfile.nano', this.templatedata);
/// Properties
this.fs.copyTpl(this.templatePath('Properties/**/*'), this.applicationName + '/Properties', this.templatedata);
@@ -240,6 +241,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({
this.fs.copy(this.sourceRoot() + '/../../gitignore.txt', this.applicationName + '/.gitignore');
this.copy(this.sourceRoot() + '/appsettings.json', this.applicationName + '/appsettings.json');
this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.txt', this.applicationName + '/Dockerfile', this.templatedata);
+ this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.nano.txt', this.applicationName + '/Dockerfile.nano', this.templatedata);
this.fs.copyTpl(this.sourceRoot() + '/Startup.cs', this.applicationName + '/Startup.cs', this.templatedata);
this.fs.copyTpl(this.sourceRoot() + '/Program.cs', this.applicationName + '/Program.cs', this.templatedata);
this.fs.copyTpl(this.sourceRoot() + '/project.json', this.applicationName + '/project.json', this.templatedata);
@@ -254,6 +256,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({
this.sourceRoot(path.join(__dirname, '../templates/projects/' + this.type));
// individual files (configs, etc)
this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.txt', this.applicationName + '/Dockerfile', this.templatedata);
+ this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.nano.txt', this.applicationName + '/Dockerfile.nano', this.templatedata);
this.fs.copy(this.templatePath('.bowerrc'), this.applicationName + '/.bowerrc');
this.fs.copy(this.sourceRoot() + '/../../gitignore.txt', this.applicationName + '/.gitignore');
this.fs.copyTpl(this.templatePath('appsettings.json'), this.applicationName + '/appsettings.json', this.templatedata);
@@ -298,6 +301,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({
this.sourceRoot(path.join(__dirname, '../templates/projects/' + this.type));
// individual files (configs, etc)
this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.txt', this.applicationName + '/Dockerfile', this.templatedata);
+ this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.nano.txt', this.applicationName + '/Dockerfile.nano', this.templatedata);
this.fs.copy(this.templatePath('.bowerrc'), this.applicationName + '/.bowerrc');
this.fs.copy(this.templatePath('bundleconfig.json'), this.applicationName + '/bundleconfig.json');
this.fs.copy(this.sourceRoot() + '/../../gitignore.txt', this.applicationName + '/.gitignore');
@@ -390,6 +394,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({
this.copy(this.sourceRoot() + '/web.config', this.applicationName + '/web.config');
this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.txt', this.applicationName + '/Dockerfile', this.templatedata);
+ this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.nano.txt', this.applicationName + '/Dockerfile.nano', this.templatedata);
/// Properties
this.fs.copyTpl(this.templatePath('Properties/**/*'), this.applicationName + '/Properties', this.templatedata);
@@ -402,6 +407,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({
this.fs.copy(this.sourceRoot() + '/../../gitignore.txt', this.applicationName + '/.gitignore');
this.copy(this.sourceRoot() + '/appsettings.json', this.applicationName + '/appsettings.json');
this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.txt', this.applicationName + '/Dockerfile', this.templatedata);
+ this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.nano.txt', this.applicationName + '/Dockerfile.nano', this.templatedata);
this.fs.copyTpl(this.sourceRoot() + '/Startup.fs', this.applicationName + '/Startup.fs', this.templatedata);
this.fs.copyTpl(this.sourceRoot() + '/Program.fs', this.applicationName + '/Program.fs', this.templatedata);
this.fs.copyTpl(this.sourceRoot() + '/project.json', this.applicationName + '/project.json', this.templatedata);
@@ -416,6 +422,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({
this.sourceRoot(path.join(__dirname, '../templates/projects/' + this.type));
// individual files (configs, etc)
this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.txt', this.applicationName + '/Dockerfile', this.templatedata);
+ this.fs.copyTpl(this.sourceRoot() + '/../../Dockerfile.nano.txt', this.applicationName + '/Dockerfile.nano', this.templatedata);
this.fs.copy(this.templatePath('.bowerrc'), this.applicationName + '/.bowerrc');
this.fs.copy(this.templatePath('bundleconfig.json'), this.applicationName + '/bundleconfig.json');
this.fs.copy(this.sourceRoot() + '/../../gitignore.txt', this.applicationName + '/.gitignore');
@@ -0,0 +1,15 @@
+FROM microsoft/dotnet:1.1.0-sdk-projectjson-nanoserver
+
+COPY . /app
+
+WORKDIR /app
+
+RUN ["dotnet", "restore"]
+
+RUN ["dotnet", "build"]
+<% if(sqlite){ %>
+RUN ["dotnet", "ef", "database", "update"]
+<% } %>
+EXPOSE 5000/tcp
+
+CMD ["dotnet", "run", "--server.urls", "http://*:5000"]
@@ -1,4 +1,4 @@
-FROM microsoft/dotnet:latest
+FROM microsoft/dotnet:1.1.0-sdk-projectjson
<% if(sqlite){ %>
RUN apt-get update && apt-get install -y sqlite3 libsqlite3-dev && rm -rf /var/lib/apt/lists/*
<% } %>
View
@@ -90,6 +90,19 @@ describe('Subgenerators without arguments tests', function() {
util.fileCheck('should create tsconfig.json file', 'tsconfig.json');
});
+ describe('aspnet:dockerfile has the same .NET version', function() {
+ var sdkVersion = '1.1.0';
+ var arg = 'file';
+ var dir = util.makeTempDir();
+
+ util.goCreateApplication('web', 'webTest', dir);
+ util.goCreateWithArgs('mvccontroller', [arg], path.join(dir, 'webTest'));
+
+ util.fileContentCheck('project.json', 'file content check', new RegExp('"Microsoft.NETCore.App":\\s*{\\s*"version": "' + sdkVersion + '"'));
+ util.fileContentCheck('Dockerfile', 'Check the content for dotnet latest image tag', new RegExp('FROM microsoft\/dotnet:' + sdkVersion + '-sdk-projectjson\\b'));
+ util.fileContentCheck('Dockerfile.nano', 'Check the content for dotnet nanoserver latest image tag', new RegExp('FROM microsoft\/dotnet:' + sdkVersion + '-sdk-projectjson-nanoserver\\b'));
+ });
+
/**
* Dockerfile can be created with two versions:
* - without SQLite installed
@@ -99,7 +112,7 @@ describe('Subgenerators without arguments tests', function() {
var filename = 'Dockerfile';
util.goCreate(filename.toLowerCase());
util.fileCheck('should create Dockerfile', filename);
- util.fileContentCheck(filename, 'Check the content for dotnet latest image tag', /FROM microsoft\/dotnet:latest/);
+ util.fileContentCheck(filename, 'Check the content for dotnet latest image tag', /FROM microsoft\/dotnet:/);
util.noFileContentCheck(filename, 'Does not contain SQLite install', /RUN apt-get update && apt-get install -y sqlite3 libsqlite3-dev/);
util.noFileContentCheck(filename, 'Does not call database migrations', /RUN \["dotnet", "ef", "database", "update"\]/);
});
@@ -109,7 +122,7 @@ describe('Subgenerators without arguments tests', function() {
var filename = 'Dockerfile';
util.goCreateWithArgs(filename.toLowerCase(), [arg]);
util.fileCheck('should create Dockerfile', filename);
- util.fileContentCheck(filename, 'Check the content for dotnet latest image tag', /FROM microsoft\/dotnet:latest/);
+ util.fileContentCheck(filename, 'Check the content for dotnet latest image tag', /FROM microsoft\/dotnet:/);
util.fileContentCheck(filename, 'Contains SQLite install', /RUN apt-get update && apt-get install -y sqlite3 libsqlite3-dev/);
util.fileContentCheck(filename, 'Calls database migrations', /RUN \["dotnet", "ef", "database", "update"\]/);
});

0 comments on commit 20b75f3

Please sign in to comment.