josephg-sharejs
SUCCESS
23m 51s
History Source
SummaryIterations1Transcript22Dockerfile
Dockerfile68 lines · 1750 chars
FROM node:slim

# Basic tooling for building JS bundles (no prepublish hooks will be run)
RUN apt-get update \
  && apt-get install -y --no-install-recommends ca-certificates \
  && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install dependencies without running scripts that might require a Makefile
COPY package.json ./
COPY package-lock.json* ./
RUN npm install --ignore-scripts

# Copy the rest of the repository
COPY . .

# Build the browserified bundle (do not minify to avoid older uglify issues)
RUN mkdir -p dist \
  && ./node_modules/.bin/browserify -s sharejs lib/client/index.js -o dist/share.js

# Simple server to serve dist/ content
RUN cat > /app/server.js << 'JS'
const http = require('http');
const path = require('path');
const fs = require('fs');

const distDir = path.resolve(__dirname, 'dist');

const mime = {
  '.js': 'application/javascript',
  '.css': 'text/css',
  '.html': 'text/html',
  '.json': 'application/json',
  '.png': 'image/png',
  '.jpg': 'image/jpeg',
  '.jpeg': 'image/jpeg',
  '.gif': 'image/gif',
  '.svg': 'image/svg+xml'
};

function serve(req, res) {
  let url = req.url.split('?')[0];
  if (url === '/' || url === '') url = '/index.html';
  const filePath = path.join(distDir, url.startsWith('/') ? url.slice(1) : url);
  fs.readFile(filePath, (err, data) => {
    if (err) {
      res.statusCode = 404;
      res.end('Not found');
      return;
    }
    const ext = path.extname(filePath);
    res.setHeader('Content-Type', mime[ext] || 'application/octet-stream');
    res.end(data);
  });
}

const server = http.createServer(serve);
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
  console.log('Serving dist/ on port', PORT);
});
JS

EXPOSE 3000

CMD ["node", "/app/server.js"]