Last active
March 16, 2018 09:37
-
-
Save my8bit/d89f992a4153018a0e22e1eb7afe6bbd to your computer and use it in GitHub Desktop.
Docker test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment