Skip to content

Dockerize #211

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

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4885ab1
initial work on Dockerizing forum app
useffc Oct 27, 2018
dee8b43
seems to be working now. apparently the `command` part of docker-compose
useffc Oct 29, 2018
5384d52
Add Dockerfile for postgres; seems to allow tables.sql to be correctly
useffc Oct 29, 2018
2df7913
clean up comments
useffc Oct 29, 2018
491daf0
try to get travis to run tests
useffc Oct 29, 2018
46b88d6
make test db (with own dockerfile) and test service. point urls to test
useffc Oct 29, 2018
f60a315
map local volumes to container volumes so changes will come through to
useffc Oct 29, 2018
de30588
update docs a bit to mirror how this is currently working
useffc Oct 29, 2018
476008d
update test service name from e2e
useffc Oct 31, 2018
8442772
hot reloading works with docker
useffc Nov 1, 2018
c53f5bd
update docs on hot reloading
useffc Nov 1, 2018
0db8d40
use node 8 in docker, kill unused node8-incompatible dependency
nchase Dec 25, 2018
04254a4
use nodemon to run dev server, expose all at /code in container
nchase Dec 26, 2018
03a41fe
add dockerignore to keep node_modules from being copied to container
nchase Dec 26, 2018
b97e6f9
update signup token
nchase Dec 26, 2018
00f7be4
kill dumb redirect code
nchase Dec 26, 2018
5251b20
Merge branch 'dockerize-plus-server-reload' into dockerize
nchase Dec 27, 2018
d9567f9
noodling with dark theme
useffc Oct 30, 2018
b130abc
move style choice outside of react to avoid flash of mis-styled content
nchase Jan 12, 2019
372bcbe
add a couple of additional dark styles (loading, a couple of text are…
nchase Jan 12, 2019
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v6.3.1
v8
20 changes: 7 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
language: node_js
node_js:
- "6"
env:
- CXX=g++-4.8
addons:
postgresql: "9.3"
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
before_script:
- psql -c 'create database forum;' -U postgres
- psql -c 'create database forum_test;' -U postgres
- "8"
services:
- docker
before_install:
docker-compose build
script:
docker-compose run test
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:8
RUN mkdir /code
ADD . /code
RUN mkdir /code/build
WORKDIR /code
RUN npm install
EXPOSE 80
10 changes: 10 additions & 0 deletions Dockerfile.postgres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM postgres:9.5

ENV POSTGRES_DB forum
ENV POSTGRES_USER forum

# Init db
RUN mkdir -p /docker-entrypoint-initdb.d
COPY tables.sql /docker-entrypoint-initdb.d/

RUN /etc/init.d/postgresql start
10 changes: 10 additions & 0 deletions Dockerfile.test.postgres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM postgres:9.5

ENV POSTGRES_DB forum_test
ENV POSTGRES_USER postgres

# Init db
RUN mkdir -p /docker-entrypoint-initdb.d
COPY tables.sql /docker-entrypoint-initdb.d/

RUN /etc/init.d/postgresql start
22 changes: 8 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,32 @@

Installation:
=============
`npm install`
`docker-compose build`

Persistent Tests:
Persistent Tests (not yet working with Docker):
=================
`npm run test:watch`

Run App Locally:
================
`npm run start:dev`
`docker-compose up web`

Debug App:
Debug App (not yet set up):
==========
`npm run start:debug`

Run Test Suite:
===============
`npm test`
`docker-compose run e2e`

Run Test Suite in Debug Mode:
Run Test Suite in Debug Mode (not yet working):
=============================
`npm run test:debug`

Database
========

```
psql --command="create database forum;" && psql --echo-all --dbname=forum --file=tables.sql
```

Add /build Directory
====================
From installation directory root, `mkdir build`. This directory is needed so the app can write client-side bundles to it.
Created on Install step.

Register a User
===============
Expand All @@ -45,7 +39,7 @@ After registering, login using the user/pass you signed up with.

Hot Reload
==========
`npm run start:dev` does 'hot reloading' by default. This is subject to change.
`docker-compose up web` does 'hot reloading' by default. This is subject to change.

Environment Variables
=====================
Expand Down
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var cssnext = require('postcss-cssnext');
rootRequire('config/environments')(app);
app.set('io', require('socket.io').listen(httpServer));

var conString = process.env.DATABASE_URL || "postgres://postgres@localhost/forum";
var conString = process.env.DATABASE_URL || "postgres://postgres@db/forum";

var Sequelize = require('sequelize');
var sequelize = new Sequelize(conString);
Expand Down
1 change: 1 addition & 0 deletions app/components/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ var Settings = createReactClass({
>
<option value="default">default</option>
<option value="classic">classic</option>
<option value="classic-dark">classic dark</option>
<option value="neoclassical">neoclassical</option>
<option value="giko">giko</option>
</select>
Expand Down
1 change: 0 additions & 1 deletion app/components/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = createReactClass({
render: function() {
return (
<div className="routerContainer">
<link rel="stylesheet" href={`/stylesheets/v2-${this.props.value.settings.style}.css`} />
<Router
history={browserHistory}
createElement={createElement(this.props)}
Expand Down
2 changes: 2 additions & 0 deletions app/reducer-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ function handleSettings(state, action) {
if (action.type === 'STYLECHANGE') {
localStorage.setItem('forumStyleValue', action.value);

document.getElementById('forumstylesheet').href = `/stylesheets/v2-${window.localStorage.getItem('forumStyleValue')}.css`;

return Object.assign({}, state, {
style: action.value
});
Expand Down
2 changes: 1 addition & 1 deletion config/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function(app){
app.set('hostName', 'http://localhost');
app.set('PORT', process.env.PORT || 3000);
app.set('db-test', 'forum_test');
app.set('signupToken', 'e4baa79988b55b8f73affa415a0a7163');
app.set('signupToken', '4f84a8faebe285025181023b2247a51b');


if (process.env.NODE_ENV === 'test') {
Expand Down
9 changes: 0 additions & 9 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ var routes = function(app, passport){

response.locals.user = request.session.user;

if (
app.get('hostName')
.match(request.get('host')
.split(':')[0]
) === null
) {
return response.redirect(301, app.get('hostName') + request.url);
}

next();
}, function(request, response, next) {
if (request.session.user.id === 0){
Expand Down
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: "2"
services:
web:
build: .
ports:
- 80:3000
- 4474:4474
command: bash -c 'while !</dev/tcp/db/5432; do sleep 1; done; npm run start:dev'
depends_on:
- db
environment:
- DATABASE_URL=postgres://forum@db:5432/forum
- PORT=3000
- FORUM_STORAGE_ADAPTER=S3
volumes:
- .:/code
- /code/build
- /code/node_modules
- ./stylesheets:/code/stylesheets:rw
db:
build:
context: .
dockerfile: ./Dockerfile.postgres
# Testing
test:
build: .
ports:
- 80:3099
command: bash -c 'while !</dev/tcp/test_db/5432; do sleep 1; done; npm run test'
depends_on:
- test_db
environment:
- DATABASE_URL=postgres://postgres@test_db:5432/forum_test
- PORT=3099
test_db:
build:
context: .
dockerfile: ./Dockerfile.test.postgres
2 changes: 1 addition & 1 deletion models/Post.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var Sequelize = require('sequelize');
var sequelize = new Sequelize(process.env.DATABASE_URL || "postgres://postgres@localhost/forum");
var sequelize = new Sequelize(process.env.DATABASE_URL || "postgres://postgres@db/forum");

var Post = rootRequire('models/Post.orm')(sequelize);

Expand Down
2 changes: 1 addition & 1 deletion models/User.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var Sequelize = require('sequelize');
var sequelize = new Sequelize(process.env.DATABASE_URL || "postgres://postgres@localhost/forum");
var sequelize = new Sequelize(process.env.DATABASE_URL || "postgres://postgres@db/forum");

var User = rootRequire('models/User.orm')(sequelize);

Expand Down
Loading