Skip to content

Instantly share code, notes, and snippets.

@my8bit
Last active March 16, 2018 09:37

Revisions

  1. my8bit revised this gist Mar 16, 2018. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion 213
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    13
  2. my8bit revised this gist Mar 16, 2018. 2 changed files with 64 additions and 0 deletions.
    1 change: 1 addition & 0 deletions 213
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    13
    63 changes: 63 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    FROM node:8-slim

    MAINTAINER Eric Bidelman <ebidel@>

    # Install utilities
    RUN apt-get update --fix-missing && apt-get -y upgrade

    # Install latest chrome dev package.
    RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
    && apt-get update \
    && apt-get install -y google-chrome-unstable git --no-install-recommends \
    && rm -rf /var/lib/apt/lists/* \
    && rm -rf /src/*.deb

    ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
    RUN chmod +x /usr/local/bin/dumb-init

    # Download latest Lighthouse from npm.
    # cache bust so we always get the latest version of LH when building the image.
    ARG CACHEBUST=1
    RUN npm i lighthouse -g

    # Install express.
    RUN git clone https://github.com/ebidel/lighthouse-ci.git
    WORKDIR lighthouse-ci/builder
    RUN pwd

    # COPY package.json .
    RUN npm i --production

    # Add the simple server.
    # COPY server.js /
    RUN cp server.js /
    RUN chmod +x /server.js

    # COPY entrypoint.sh /
    RUN cp entrypoint.sh /
    RUN chmod +x /entrypoint.sh

    # Add a chrome user and setup home dir.
    RUN groupadd -r chrome && useradd -r -m -g chrome -G audio,video chrome && \
    mkdir -p /home/chrome/reports && \
    chown -R chrome:chrome /home/chrome

    USER chrome

    #VOLUME /home/chrome/reports
    #WORKDIR /home/chrome/reports

    # Disable Lighthouse error reporting to prevent prompt.
    ENV CI=true

    # WORKDIR /
    # RUN git clone https://gist.github.com/d89f992a4153018a0e22e1eb7afe6bbd.git
    # WORKDIR d89f992a4153018a0e22e1eb7afe6bbd
    # RUN npm i
    # RUN npm start

    EXPOSE 8080

    ENTRYPOINT ["dumb-init", "--", "/entrypoint.sh"]
    #CMD ["lighthouse", "--help"]
  3. my8bit created this gist Mar 16, 2018.
    30 changes: 30 additions & 0 deletions docker.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    const Docker = require('dockerode');
    const docker = new Docker({host: 'http://127.0.0.1', port: 8081});
    const {Writable} = require('stream');

    let data = '';

    const outStream = new Writable({
    write(chunk, encoding, callback) {
    data += chunk.toString();
    callback();
    }
    });

    const api = {
    run() {
    const done = new Buffer([]);
    return docker.run('lighthouse_ci',
    ['https://tomatoes.work', '--quiet', '--output=json'],
    outStream,
    {
    "CapAdd": ["SYS_ADMIN"],
    "Tty": true,
    "Detach": true
    }).then(done => {
    return JSON.parse(data);
    });
    }
    }

    module.exports = api;
    17 changes: 17 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    const docker = require('./docker');
    const express = require('express');
    const bodyParser = require('body-parser');

    const app = express();

    app.use(bodyParser.json());
    // app.use(express.static('public'));
    app.use('/', express.static('static/dist'));

    app.get('/run', function (req, res) {
    docker.run().then(result => {
    res.send(result);
    });
    });

    app.listen(3000, () => console.log('Example app listening on port 3000!'))
    16 changes: 16 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    {
    "name": "dkr",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
    "start": "node index.js"
    },
    "author": "",
    "license": "ISC",
    "dependencies": {
    "dockerode": "^2.5.4",
    "express": "^4.16.3",
    "npm": "^5.7.1"
    }
    }