Create docker configuration

master
Wilco Kruijer 5 years ago
parent d66f172b5d
commit 6a56fdeed9
  1. 2
      backend/.dockerignore
  2. 0
      backend/public/.keep
  3. 12
      backend/src/app.js
  4. 12
      docker-compose.yml
  5. 18
      dockerfile
  6. 2
      frontend/.dockerignore
  7. 1
      frontend/src/App.tsx
  8. 1
      frontend/src/index.tsx

@ -0,0 +1,2 @@
node_modules/
build/

@ -1,14 +1,22 @@
const express = require("express"); const express = require("express");
const socketIO = require("socket.io"); const socketIO = require("socket.io");
const state = require("./state.js"); const state = require("./state.js");
const path = require("path");
const HOST = '0.0.0.0';
const PORT = 3001; const PORT = 3001;
const app = express(); const app = express();
const server = app.listen(PORT, () => console.log(`Example app listening on port ${PORT}!`)); const server = app.listen(PORT, HOST,() => console.log(`Example app listening on port ${PORT}!`));
app.use(express.static(path.join(__dirname, '../public')));
const io = socketIO(server); const io = socketIO(server);
app.get('/', (req, res) => res.send('<pre>' + JSON.stringify(state) + '</pre>')); app.get('/state', (req, res) => res.send('<pre>' + JSON.stringify(state) + '</pre>'));
process.on('SIGINT', function() {
process.exit();
});
module.exports = { module.exports = {
app, server, io app, server, io

@ -0,0 +1,12 @@
version: "3.4"
services:
centurion:
build:
context: .
dockerfile: ./dockerfile
environment:
NODE_ENV: production
ports:
- 8800:3001
restart: always
command: "node src/index.js"

@ -0,0 +1,18 @@
# Stage 1 - the build process
FROM node:13-alpine as build-deps
WORKDIR /usr/src/app
COPY frontend/package.json frontend/package-lock.json frontend/config-overrides.js ./
RUN yarn
COPY frontend/ ./
RUN yarn build
# Backend
FROM node:13-alpine
WORKDIR /app
COPY backend/package.json backend/package-lock.json ./
RUN yarn
COPY backend/ ./
COPY --from=build-deps /usr/src/app/build public
EXPOSE 3001

@ -0,0 +1,2 @@
node_modules/
build/

@ -13,7 +13,6 @@ const App = () => {
const [started, setStarted] = useState(false); const [started, setStarted] = useState(false);
const player = useRef(new Audio("centurion.m4a")); const player = useRef(new Audio("centurion.m4a"));
useEffect(() => { useEffect(() => {
socket.on('started', async () => { socket.on('started', async () => {
setStarted(true); setStarted(true);

@ -3,5 +3,4 @@ import ReactDOM from 'react-dom';
import './index.css'; import './index.css';
import App from './App'; import App from './App';
ReactDOM.render(<App/>, document.getElementById('root')); ReactDOM.render(<App/>, document.getElementById('root'));

Loading…
Cancel
Save