Skip to content

Commit 47be12d

Browse files
author
janvt
authored
Merge pull request #27 from geekcell/modernization
Modernization
2 parents 6da0434 + b7cdcf5 commit 47be12d

File tree

103 files changed

+164
-1406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+164
-1406
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
**/node_modules
2+
**/package-lock.json
3+
14
.sass-cache
25
!.gitkeep
36
03-express-gulp-watch/app/public/stylesheets/style.css

00-basic-express-generator/.dockerignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

00-basic-express-generator/Dockerfile

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
FROM node:0.10.38
2-
3-
RUN mkdir /src
4-
5-
RUN npm install express-generator -g
6-
7-
WORKDIR /src
8-
ADD app/package.json /src/package.json
9-
RUN npm install
10-
11-
EXPOSE 3000
12-
13-
CMD node app/bin/www
1+
ARG IMAGE_VERSION_BUILD=latest
2+
ARG IMAGE_VERSION=18.14.2-bullseye-slim
3+
ARG NODE_ENV=development
4+
5+
FROM node:${IMAGE_VERSION_BUILD} AS build
6+
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init
7+
8+
FROM node:${IMAGE_VERSION}
9+
ENV NODE_ENV ${NODE_ENV}
10+
COPY --from=build /usr/bin/dumb-init /usr/bin/dumb-init
11+
RUN mkdir /usr/src/app
12+
RUN chown node:node /usr/src/app
13+
WORKDIR /usr/src/app
14+
USER node
15+
CMD ["dumb-init", "npm", "run", "start"]

00-basic-express-generator/README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,14 @@ Install [Docker](https://www.docker.com/) on your system.
1010
* [Install instructions](https://docs.docker.com/installation/ubuntulinux/) for Ubuntu Linux
1111
* [Install instructions](https://docs.docker.com/installation/) for other platforms
1212

13-
Install [Docker Compose](http://docs.docker.com/compose/) on your system.
14-
15-
* Python/pip: `sudo pip install -U docker-compose`
16-
* Other: ``curl -L https://github.com/docker/compose/releases/download/1.1.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose; chmod +x /usr/local/bin/docker-compose``
13+
[Install Docker Compose](https://docs.docker.com/compose/install/) on your system.
1714

1815
## Setup
1916

20-
1. Run `docker-compose build`. It will pull a base image from the Docker registry and install [express-generator](https://github.com/expressjs/generator) globally in your container. The rest can be ignored for now.
21-
22-
2. Run `docker-compose run web express app`. This will bootstrap a new Express app in your container in the `app` subfolder. Since it already exists, Express will ask you if you want to override, which you can answer with `yes`.
17+
1. Run `docker-compose build`. This will pull the base images, and install image dependencies.
2318

24-
3. Run `docker-compose build` again. It will install install all dependencies from the (generated) package.json, expose port 3000 to the host, and instruct the container to execute `node app/bin/www` on start up.
19+
2. Run `docker-compose run web npm install`. This will install the `package.json` dependencies in the `app` sub-folder. Since this folder is mounted into the Docker image as a volume, any changes made in the image or on your local file system are synced.
2520

2621
## Start
2722

28-
Run `docker-compose up` to create and start the container. The app should then be running on your docker daemon on port 3030 (On OS X you can use `boot2docker ip` to find out the IP address).
23+
Run `docker-compose up` to start the container. The app should then be running at http://localhost:3000.

00-basic-express-generator/app/app.js

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,11 @@
1-
var express = require('express');
2-
var path = require('path');
3-
var favicon = require('serve-favicon');
4-
var logger = require('morgan');
5-
var cookieParser = require('cookie-parser');
6-
var bodyParser = require('body-parser');
1+
const express = require('express');
2+
const app = express();
3+
const port = process.env.APP_PORT;
74

8-
var routes = require('./routes/index');
9-
var users = require('./routes/users');
10-
11-
var app = express();
12-
13-
// view engine setup
14-
app.set('views', path.join(__dirname, 'views'));
15-
app.set('view engine', 'jade');
16-
17-
// uncomment after placing your favicon in /public
18-
//app.use(favicon(__dirname + '/public/favicon.ico'));
19-
app.use(logger('dev'));
20-
app.use(bodyParser.json());
21-
app.use(bodyParser.urlencoded({ extended: false }));
22-
app.use(cookieParser());
23-
app.use(express.static(path.join(__dirname, 'public')));
24-
25-
app.use('/', routes);
26-
app.use('/users', users);
27-
28-
// catch 404 and forward to error handler
29-
app.use(function(req, res, next) {
30-
var err = new Error('Not Found');
31-
err.status = 404;
32-
next(err);
5+
app.get('/', (req, res) => {
6+
res.send('Hello World!')
337
});
348

35-
// error handlers
36-
37-
// development error handler
38-
// will print stacktrace
39-
if (app.get('env') === 'development') {
40-
app.use(function(err, req, res, next) {
41-
res.status(err.status || 500);
42-
res.render('error', {
43-
message: err.message,
44-
error: err
45-
});
46-
});
47-
}
48-
49-
// production error handler
50-
// no stacktraces leaked to user
51-
app.use(function(err, req, res, next) {
52-
res.status(err.status || 500);
53-
res.render('error', {
54-
message: err.message,
55-
error: {}
56-
});
57-
});
58-
59-
60-
module.exports = app;
9+
app.listen(port, () => {
10+
console.log(`Example app listening on port ${port}`)
11+
});

00-basic-express-generator/app/bin/www

Lines changed: 0 additions & 90 deletions
This file was deleted.

00-basic-express-generator/app/package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
6-
"start": "node ./bin/www"
6+
"start": "node app.js"
77
},
88
"dependencies": {
9-
"body-parser": "~1.10.2",
10-
"cookie-parser": "~1.3.3",
11-
"debug": "~2.1.1",
12-
"express": "~4.11.1",
13-
"jade": "~1.9.1",
14-
"morgan": "~1.5.1",
15-
"serve-favicon": "~2.2.0"
9+
"express": "4.18.2"
1610
}
1711
}

00-basic-express-generator/app/public/stylesheets/style.css

Lines changed: 0 additions & 8 deletions
This file was deleted.

00-basic-express-generator/app/routes/index.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

00-basic-express-generator/app/routes/users.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

00-basic-express-generator/app/views/error.jade

Lines changed: 0 additions & 6 deletions
This file was deleted.

00-basic-express-generator/app/views/index.jade

Lines changed: 0 additions & 5 deletions
This file was deleted.

00-basic-express-generator/app/views/layout.jade

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
web:
2-
build: .
3-
volumes:
4-
- "./app:/src/app"
5-
ports:
6-
- "3030:3000"
1+
version: "3.9"
2+
3+
services:
4+
web:
5+
build: .
6+
user: "node:node"
7+
environment:
8+
- APP_PORT=${APP_PORT:-3000}
9+
volumes:
10+
- "./app:/usr/src/app"
11+
ports:
12+
- "3000:3000"

01-express-nodemon/.dockerignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

01-express-nodemon/Dockerfile

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
FROM node:0.10.38
2-
3-
RUN mkdir /src
4-
5-
RUN npm install nodemon -g
6-
7-
WORKDIR /src
8-
ADD app/package.json /src/package.json
9-
RUN npm install
10-
11-
ADD app/nodemon.json /src/nodemon.json
12-
13-
EXPOSE 3000
14-
15-
CMD npm start
1+
ARG IMAGE_VERSION_BUILD=latest
2+
ARG IMAGE_VERSION=18.14.2-bullseye-slim
3+
ARG NODE_ENV=development
4+
5+
FROM node:${IMAGE_VERSION_BUILD} AS build
6+
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init
7+
8+
FROM node:${IMAGE_VERSION}
9+
ENV NODE_ENV ${NODE_ENV}
10+
COPY --from=build /usr/bin/dumb-init /usr/bin/dumb-init
11+
RUN mkdir /usr/src/app
12+
RUN chown node:node /usr/src/app
13+
WORKDIR /usr/src/app
14+
USER node
15+
CMD ["dumb-init", "npm", "run", "start"]

0 commit comments

Comments
 (0)