Skip to content

Modernization #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
**/node_modules
**/package-lock.json

.sass-cache
!.gitkeep
03-express-gulp-watch/app/public/stylesheets/style.css
Expand Down
5 changes: 0 additions & 5 deletions 00-basic-express-generator/.dockerignore

This file was deleted.

28 changes: 15 additions & 13 deletions 00-basic-express-generator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM node:0.10.38

RUN mkdir /src

RUN npm install express-generator -g

WORKDIR /src
ADD app/package.json /src/package.json
RUN npm install

EXPOSE 3000

CMD node app/bin/www
ARG IMAGE_VERSION_BUILD=latest
ARG IMAGE_VERSION=18.14.2-bullseye-slim
ARG NODE_ENV=development

FROM node:${IMAGE_VERSION_BUILD} AS build
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init

FROM node:${IMAGE_VERSION}
ENV NODE_ENV ${NODE_ENV}
COPY --from=build /usr/bin/dumb-init /usr/bin/dumb-init
RUN mkdir /usr/src/app
RUN chown node:node /usr/src/app
WORKDIR /usr/src/app
USER node
CMD ["dumb-init", "npm", "run", "start"]
13 changes: 4 additions & 9 deletions 00-basic-express-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@ Install [Docker](https://www.docker.com/) on your system.
* [Install instructions](https://docs.docker.com/installation/ubuntulinux/) for Ubuntu Linux
* [Install instructions](https://docs.docker.com/installation/) for other platforms

Install [Docker Compose](http://docs.docker.com/compose/) on your system.

* Python/pip: `sudo pip install -U docker-compose`
* 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``
[Install Docker Compose](https://docs.docker.com/compose/install/) on your system.

## Setup

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.

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`.
1. Run `docker-compose build`. This will pull the base images, and install image dependencies.

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.
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.

## Start

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).
Run `docker-compose up` to start the container. The app should then be running at http://localhost:3000.
65 changes: 8 additions & 57 deletions 00-basic-express-generator/app/app.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,11 @@
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
const express = require('express');
const app = express();
const port = process.env.APP_PORT;

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
app.get('/', (req, res) => {
res.send('Hello World!')
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});


module.exports = app;
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
});
90 changes: 0 additions & 90 deletions 00-basic-express-generator/app/bin/www

This file was deleted.

10 changes: 2 additions & 8 deletions 00-basic-express-generator/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
"start": "node app.js"
},
"dependencies": {
"body-parser": "~1.10.2",
"cookie-parser": "~1.3.3",
"debug": "~2.1.1",
"express": "~4.11.1",
"jade": "~1.9.1",
"morgan": "~1.5.1",
"serve-favicon": "~2.2.0"
"express": "4.18.2"
}
}
8 changes: 0 additions & 8 deletions 00-basic-express-generator/app/public/stylesheets/style.css

This file was deleted.

9 changes: 0 additions & 9 deletions 00-basic-express-generator/app/routes/index.js

This file was deleted.

9 changes: 0 additions & 9 deletions 00-basic-express-generator/app/routes/users.js

This file was deleted.

6 changes: 0 additions & 6 deletions 00-basic-express-generator/app/views/error.jade

This file was deleted.

5 changes: 0 additions & 5 deletions 00-basic-express-generator/app/views/index.jade

This file was deleted.

7 changes: 0 additions & 7 deletions 00-basic-express-generator/app/views/layout.jade

This file was deleted.

18 changes: 12 additions & 6 deletions 00-basic-express-generator/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
web:
build: .
volumes:
- "./app:/src/app"
ports:
- "3030:3000"
version: "3.9"

services:
web:
build: .
user: "node:node"
environment:
- APP_PORT=${APP_PORT:-3000}
volumes:
- "./app:/usr/src/app"
ports:
- "3000:3000"
5 changes: 0 additions & 5 deletions 01-express-nodemon/.dockerignore

This file was deleted.

30 changes: 15 additions & 15 deletions 01-express-nodemon/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM node:0.10.38

RUN mkdir /src

RUN npm install nodemon -g

WORKDIR /src
ADD app/package.json /src/package.json
RUN npm install

ADD app/nodemon.json /src/nodemon.json

EXPOSE 3000

CMD npm start
ARG IMAGE_VERSION_BUILD=latest
ARG IMAGE_VERSION=18.14.2-bullseye-slim
ARG NODE_ENV=development

FROM node:${IMAGE_VERSION_BUILD} AS build
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init

FROM node:${IMAGE_VERSION}
ENV NODE_ENV ${NODE_ENV}
COPY --from=build /usr/bin/dumb-init /usr/bin/dumb-init
RUN mkdir /usr/src/app
RUN chown node:node /usr/src/app
WORKDIR /usr/src/app
USER node
CMD ["dumb-init", "npm", "run", "start"]
Loading