Skip to content

Commit

Permalink
Use docker to run, instead of vagrant.
Browse files Browse the repository at this point in the history
  • Loading branch information
midgleyc committed Jul 14, 2020
1 parent a4942d0 commit 560a794
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 170 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ Basic user account management for the web.
Example & Getting Started
-------------------------

With Vagrant installed run the following:
With Docker installed run the following:

```
cd vagrant
vagrant up
vagrant ssh
cd src
npm install
node example
./docker/docker-node npm install
./docker/docker-run
```

Access the site in your browser at [http://user-accounts.local:3000](http://user-accounts.local:3000).
Access the site in your browser at [http://localhost:3000](http://localhost:3000). View email sent at `http://localhost:2525/`.

A full working example with skeleton templates is provided in the `./example` folder.

Expand Down
15 changes: 15 additions & 0 deletions docker/docker-node
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# This script runs a command using node:10 against the source code in docker.
# It simplifies the development process by not containerising the entire
# source code and provides volumes for the home directory.

SCRIPT_DIR=$(dirname "$0")
SCRIPT_DIR_PARENT=$(cd "$SCRIPT_DIR" && cd ../ && pwd)

docker run -it \
-u $(id -u):$(id -g) \
-v "${SCRIPT_DIR_PARENT}:/tmp/src" \
-w /tmp/src \
node:10 \
"$@"
8 changes: 8 additions & 0 deletions docker/docker-run
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# This script runs the server and required components.

SCRIPT_DIR=$(dirname "$0")
SCRIPT_DIR_PARENT=$(cd "$SCRIPT_DIR" && cd ../ && pwd)

RUNAS="$(id -u):$(id -g)" docker-compose -f "$SCRIPT_DIR_PARENT/docker/docker-run-compose.yml" up
21 changes: 21 additions & 0 deletions docker/docker-run-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3.3'
services:
email:
image: ksokol/mailsink
user: ${RUNAS}
ports:
- "2525:2525"
web:
image: node:10
user: ${RUNAS}
depends_on:
- email
ports:
- "3000:3000"
volumes:
- ../:/tmp/src
environment:
SMTP_HOST: email
SMTP_PORT: 2500
working_dir: /tmp/src
command: bash -c 'sleep 5; npm start'
14 changes: 12 additions & 2 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const multer = require("multer");
const os = require('os');
const path = require("path");
const ExpressUserAccounts = require("..");
const nodemailer = require("nodemailer");

const app = express();

Expand All @@ -25,7 +26,16 @@ const userAccounts = new ExpressUserAccounts({
templatePath: path.join(__dirname, "user-account-templates"),

// Pluggable data-stores are supported, this uses CouchDB.
store: new ExpressUserAccounts.PouchDbStore(path.join(os.homedir(), "users.pouchdb"))
store: new ExpressUserAccounts.PouchDbStore(path.join(os.homedir(), "users.pouchdb")),

// Use a custom mail transport for a mailsink for testing
mailTransport: nodemailer.createTransport({
host: process.env.SMTP_HOST || "localhost",
port: process.env.SMTP_PORT || 25,
tls: {
rejectUnauthorized: false
}
})
});
app.use(userAccounts.createMiddleware());
app.use("/accounts", userAccounts.createUserInterface());
Expand All @@ -36,4 +46,4 @@ app.get("/", function(req, res, next) {
});

app.listen(3000);
console.warn("Listening on port 3000");
console.warn("Listening on port 3000");
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "express-user-accounts",
"version": "0.0.2",
"version": "0.0.3",
"private": true,
"scripts": {
"start": "node example"
},
"dependencies": {
"async": "^2.5.0",
"base64url": "^2.0.0",
Expand Down
87 changes: 0 additions & 87 deletions vagrant/Vagrantfile

This file was deleted.

10 changes: 0 additions & 10 deletions vagrant/netplan-config.yaml

This file was deleted.

1 change: 0 additions & 1 deletion vagrant/provision-user.sh

This file was deleted.

47 changes: 0 additions & 47 deletions vagrant/provision.sh

This file was deleted.

14 changes: 0 additions & 14 deletions vagrant/vagrant-bind-mounts

This file was deleted.

0 comments on commit 560a794

Please sign in to comment.