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

Commit 286b6f9

Browse files
🐳 Dockerfile support refactoring with optional SQLite support (#750)
* ✅ Add unit tests for Dockerfile options The Dockerfile will support two different options: - without SQLite package installation and without call to EF migrations - with SQLite and EF migrations implementation * 🎨 Add Dockerfile --sqlite option implementation The --sqlite option controls if SQLite support is added to generated Docker dotnet image - required by MVC web starter projects that use EntityFramework The --sqlite option can be used with subgenerator and is pre-set when project type if starter web (with SQLite backed EF database implementation) * 📝 Dockerfile SQLite support documentation
1 parent 5cb0e28 commit 286b6f9

File tree

7 files changed

+91
-13
lines changed

7 files changed

+91
-13
lines changed

Dockerfile/USAGE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Description:
22
Creates a new Docker configuration file.
3-
By default Mono-based definition file is created.
4-
To create CoreCLR based definition file use --coreclr option
3+
To create Docker image with SQLite support for EntityFramework
4+
use --sqlite option
55

66
Example:
7-
yo aspnet:Dockerfile [--coreclr]
7+
yo aspnet:Dockerfile [--sqlite]
88

99
This will create:
1010
Dockerfile

Dockerfile/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ var Generator = module.exports = function Generator() {
99
util.inherits(Generator, ScriptBase);
1010

1111
Generator.prototype.createItem = function() {
12-
// support CoreCLR runtime version of Docker image
13-
// is provided by --coreclr option
12+
// support SQLite library is provided by sqlite option
13+
// is provided by --sqlite option
1414
this.generateTemplateFile(
15-
'Dockerfile.txt',
15+
'Dockerfile.txt',
1616
'Dockerfile', {
17-
coreclr: (this.options.coreclr) ? this.options.coreclr : false
17+
sqlite: (this.options.sqlite) ? this.options.sqlite : false
1818
});
1919
};

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ Produces `filename.coffee`
257257
### Dockerfile
258258

259259
Creates a new Docker configuration file.
260-
By default `Mono` based definition file is created.
261-
To create `CoreCLR` based definition file use `--coreclr` option
260+
To create Docker image with SQLite support for EntityFramework use `--sqlite` option
262261

263262
Example:
264263
```

app/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({
116116
this.templatedata.applicationname = this.applicationName;
117117
this.templatedata.guid = guid.v4();
118118
this.templatedata.grunt = this.options.grunt || false;
119-
this.templatedata.coreclr = this.options.coreclr || false;
119+
this.templatedata.sqlite = (this.type === 'web') ? true : false;
120120
this.templatedata.ui = this.ui;
121121
},
122122

templates/Dockerfile.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
FROM microsoft/dotnet:latest
2-
2+
<% if(sqlite){ %>
3+
RUN apt-get update && apt-get install sqlite3 libsqlite3-dev
4+
<% } %>
35
COPY . /app
6+
47
WORKDIR /app
8+
59
RUN ["dotnet", "restore"]
10+
611
RUN ["dotnet", "build"]
7-
12+
<% if(sqlite){ %>
13+
RUN ["dotnet", "ef", "database", "update"]
14+
<% } %>
815
EXPOSE 5000/tcp
16+
917
ENTRYPOINT ["dotnet", "run", "--server.urls", "http://0.0.0.0:5000"]

test/subgenerators.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,28 @@ describe('Subgenerators without arguments tests', function() {
9999
util.fileCheck('should create tsconfig.json file', 'tsconfig.json');
100100
});
101101

102+
/**
103+
* Dockerfile can be created with two versions:
104+
* - without SQLite installed
105+
* - with SQLite installed and EF migrations called
106+
*/
102107
describe('aspnet:Dockerfile dotnet', function() {
103108
var filename = 'Dockerfile';
104109
util.goCreate(filename);
105110
util.fileCheck('should create Dockerfile', filename);
106-
util.fileContentCheck(filename, 'Check the content for dotnet latest image tag', /FROM microsoft\/dotnet:latest/);
111+
util.fileContentCheck(filename, 'Check the content for dotnet latest image tag', /FROM microsoft\/dotnet:latest/);
112+
util.noFileContentCheck(filename, 'Does not contain SQLite install', /RUN apt-get update && apt-get install sqlite3 libsqlite3-dev/);
113+
util.noFileContentCheck(filename, 'Does not call database migrations', /RUN \["dotnet", "ef", "database", "update"\]/);
114+
});
115+
116+
describe('aspnet:Dockerfile dotnet with --sqlite', function() {
117+
var arg = '--sqlite';
118+
var filename = 'Dockerfile';
119+
util.goCreateWithArgs(filename, [arg]);
120+
util.fileCheck('should create Dockerfile', filename);
121+
util.fileContentCheck(filename, 'Check the content for dotnet latest image tag', /FROM microsoft\/dotnet:latest/);
122+
util.fileContentCheck(filename, 'Contains SQLite install', /RUN apt-get update && apt-get install sqlite3 libsqlite3-dev/);
123+
util.fileContentCheck(filename, 'Calls database migrations', /RUN \["dotnet", "ef", "database", "update"\]/);
107124
});
108125

109126
describe('aspnet:nuget', function() {

test/test-core.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ describe('aspnet - Empty Web Application', function() {
5050
for (var i = 0; i < files.length; i++) {
5151
util.filesCheck(files[i]);
5252
}
53+
54+
it('Dockerfile does not include SQLite', function() {
55+
assert.noFileContent('emptyWebTest/Dockerfile', /RUN apt-get update && apt-get install sqlite3 libsqlite3-dev/);
56+
});
57+
58+
it('Dockerfile does not contain migrations', function() {
59+
assert.noFileContent('emptyWebTest/Dockerfile', /RUN \["dotnet", "ef", "database", "update"\]/);
60+
});
61+
5362
});
5463

5564
});
@@ -288,6 +297,15 @@ describe('aspnet - Web Application (Bootstrap)', function() {
288297
it('bower.json name field is lower case', function() {
289298
assert.fileContent('webTest/bower.json', /"name": "webtest"/);
290299
});
300+
301+
it('Dockerfile includes SQLite', function() {
302+
assert.fileContent('webTest/Dockerfile', /RUN apt-get update && apt-get install sqlite3 libsqlite3-dev/);
303+
});
304+
305+
it('Dockerfile contains migrations', function() {
306+
assert.fileContent('webTest/Dockerfile', /RUN \["dotnet", "ef", "database", "update"\]/);
307+
});
308+
291309
});
292310

293311
});
@@ -457,6 +475,15 @@ describe('aspnet - Web Application (Semantic UI)', function() {
457475
it('bower.json name field is lower case', function() {
458476
assert.fileContent('webTest/bower.json', /"name": "webtest"/);
459477
});
478+
479+
it('Dockerfile includes SQLite', function() {
480+
assert.fileContent('webTest/Dockerfile', /RUN apt-get update && apt-get install sqlite3 libsqlite3-dev/);
481+
});
482+
483+
it('Dockerfile contains migrations', function() {
484+
assert.fileContent('webTest/Dockerfile', /RUN \["dotnet", "ef", "database", "update"\]/);
485+
});
486+
460487
});
461488

462489

@@ -597,6 +624,15 @@ describe('aspnet - Web Application Basic (Bootstrap)', function() {
597624
it('bower.json name field is lower case', function() {
598625
assert.fileContent('webTest/bower.json', /"name": "webtest"/);
599626
});
627+
628+
it('Dockerfile does not include SQLite', function() {
629+
assert.noFileContent('webTest/Dockerfile', /RUN apt-get update && apt-get install sqlite3 libsqlite3-dev/);
630+
});
631+
632+
it('Dockerfile does not contain migrations', function() {
633+
assert.noFileContent('webTest/Dockerfile', /RUN \["dotnet", "ef", "database", "update"\]/);
634+
});
635+
600636
});
601637

602638
});
@@ -697,6 +733,15 @@ describe('aspnet - Web Application Basic (Semantic UI)', function() {
697733
it('bower.json name field is lower case', function() {
698734
assert.fileContent('webTest/bower.json', /"name": "webtest"/);
699735
});
736+
737+
it('Dockerfile does not include SQLite', function() {
738+
assert.noFileContent('webTest/Dockerfile', /RUN apt-get update && apt-get install sqlite3 libsqlite3-dev/);
739+
});
740+
741+
it('Dockerfile does not contain migrations', function() {
742+
assert.noFileContent('webTest/Dockerfile', /RUN \["dotnet", "ef", "database", "update"\]/);
743+
});
744+
700745
});
701746

702747
describe('Checking file content for overrides', function() {
@@ -777,6 +822,15 @@ describe('aspnet - Web API Application', function() {
777822
for (var i = 0; i < files.length; i++) {
778823
util.filesCheck(files[i]);
779824
}
825+
826+
it('Dockerfile does not include SQLite', function() {
827+
assert.noFileContent('webAPITest/Dockerfile', /RUN apt-get update && apt-get install sqlite3 libsqlite3-dev/);
828+
});
829+
830+
it('Dockerfile does not contain migrations', function() {
831+
assert.noFileContent('webAPITest/Dockerfile', /RUN \["dotnet", "ef", "database", "update"\]/);
832+
});
833+
780834
});
781835

782836
});

0 commit comments

Comments
 (0)