Skip to content

Commit 6b230be

Browse files
author
Dustin Blackman
committed
Init
1 parent 67dd46e commit 6b230be

File tree

5 files changed

+195
-0
lines changed

5 files changed

+195
-0
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
.git/

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM ubuntu:14.04
2+
MAINTAINER Gravebot
3+
4+
# Setup system deps
5+
RUN apt-get update
6+
RUN apt-get -y install build-essential curl rsync tar python python-pip git libfontconfig1
7+
8+
# Setup Node
9+
ENV NODE_VERSION 4.2.6
10+
ENV NPM_VERSION 3.7.2
11+
12+
RUN git clone https://github.com/creationix/nvm.git /.nvm
13+
RUN echo "source /.nvm/nvm.sh" >> /etc/bash.bashrc
14+
RUN /bin/bash -c 'source /.nvm/nvm.sh && nvm install $NODE_VERSION && nvm use $NODE_VERSION && nvm alias default $NODE_VERSION && ln -s /.nvm/versions/node/v$NODE_VERSION/bin/node /usr/local/bin/node && ln -s /.nvm/versions/node/v$NODE_VERSION/bin/npm /usr/local/bin/npm'
15+
RUN npm install -g npm@$NPM_VERSION
16+
17+
# Setup dockerize
18+
RUN pip install dockerize
19+
20+
# Copy package.json
21+
COPY ./package.json /app/
22+
WORKDIR /app/
23+
24+
# Install node deps
25+
RUN npm install --production
26+
27+
# Copy script
28+
COPY ./index.js /app/
29+
30+
31+
CMD ["npm", "run", "create"]

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Phantomized
2+
3+
An automated build to tar up dynamic ELFs required by PhantomJS using Dockerized. This make dockerizing PhantomJS with base images like Alpine Linux easy.
4+
5+
This build does not include the phantomjs binary itself so make it easier for application that install PhantomJS through other sources like [npm](https://github.com/Medium/phantomjs). This is based off the work of [dockerized-phantomjs](https://github.com/fgrehm/docker-phantomjs2).
6+
7+
Everything can be found in releases.

index.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env babel-node
2+
3+
import Promise from 'bluebird';
4+
import { spawn, execSync } from 'child_process';
5+
import Github from 'github';
6+
import R from 'ramda';
7+
8+
const fs = Promise.promisifyAll(require('fs-extra'));
9+
const request = Promise.promisify(require('request'));
10+
11+
12+
function spawnAsync(cmd) {
13+
const options = {
14+
env: process.env,
15+
stdio: 'inherit'
16+
};
17+
18+
const parameters = R.filter(R.identity, cmd.replace(/ \\n/g, '').replace('\t', '').split(' '));
19+
const executable = parameters[0];
20+
parameters.shift();
21+
22+
console.log(executable, parameters);
23+
24+
return new Promise(resolve => {
25+
const proc = spawn(executable, parameters, options);
26+
proc.on('close', code => {
27+
if (code !== 0) process.exit(code);
28+
resolve();
29+
});
30+
});
31+
}
32+
33+
if (!process.env.GITHUB_TOKEN) {
34+
console.log('Github token is missing from env. Exiting...');
35+
process.exit(1);
36+
}
37+
38+
if (!process.env.PHANTOM_VERSION) {
39+
console.log('Phantom version is missing from env. Exiting...');
40+
process.exit(1);
41+
}
42+
43+
const github = new Github({
44+
version: '3.0.0',
45+
protocol: 'https',
46+
timeout: 5000,
47+
headers: {
48+
'user-agent': 'Phantomized-Gulp-Release'
49+
}
50+
});
51+
github.authenticate({
52+
type: 'oauth',
53+
token: process.env.GITHUB_TOKEN
54+
});
55+
const releases = Promise.promisifyAll(github.releases);
56+
57+
console.log(`Downloading PhantomJS ${process.env.PHANTOM_VERSION}`);
58+
const download_options = {
59+
url: `https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-${process.env.PHANTOM_VERSION}-linux-x86_64.tar.bz2`,
60+
encoding: null
61+
};
62+
63+
request(download_options)
64+
.then(res => fs.writeFileAsync('./phantomjs.tar.bz2', res.body, null))
65+
.then(() => console.log('Extracting'))
66+
.then(() => spawnAsync('tar -jxvf phantomjs.tar.bz2'))
67+
.then(() => fs.copyAsync(`./phantomjs-${process.env.PHANTOM_VERSION}-linux-x86_64/bin/phantomjs`, '/usr/local/bin/phantomjs', {}))
68+
.then(() => {
69+
console.log('Running dockerize');
70+
const cmd = `dockerize -n -o dockerized-phantomjs \
71+
-e /usr/local/bin/phantomjs \
72+
-a /bin/dash /bin/sh \
73+
-a /etc/fonts /etc \
74+
-a /etc/ssl /etc \
75+
-a /usr/share/fonts /usr/share \
76+
--verbose \
77+
/usr/local/bin/phantomjs \
78+
/usr/bin/curl`;
79+
return spawnAsync(cmd);
80+
})
81+
.then(() => fs.removeAsync('./dockerized-phantomjs/Dockerfile'))
82+
.then(() => fs.removeAsync('./dockerized-phantomjs/usr/local/bin/phantomjs'))
83+
.then(() => {
84+
console.log('Taring archive');
85+
process.chdir('./dockerized-phantomjs');
86+
return execSync('tar -zcf ../dockerized-phantomjs.tar.gz ./*');
87+
})
88+
.then(() => {
89+
console.log('Uploading release to Github');
90+
process.chdir('../');
91+
return releases.createReleaseAsync({
92+
owner: 'Gravebot',
93+
repo: 'phantomized',
94+
tag_name: process.env.PHANTOM_VERSION,
95+
draft: true,
96+
name: `Phantomize ${process.env.PHANTOM_VERSION}`
97+
});
98+
})
99+
.then(release => releases.uploadAssetAsync({
100+
owner: 'Gravebot',
101+
repo: 'phantomized',
102+
id: release.id,
103+
name: 'dockerized-phantomjs.tar.gz',
104+
filePath: './dockerized-phantomjs.tar.gz'
105+
}))
106+
.then(() => console.log('Done'))
107+
.catch(err => {
108+
console.log(err.stack || err);
109+
process.exit(1);
110+
});

package.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "phantomized",
3+
"version": "0.0.1",
4+
"description": "Simple script that creates releases for just the dynamic ELFs required by PhantomJS",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "docker build --rm -t phantomized .",
8+
"create": "babel-node index.js",
9+
"start": "npm run build && docker run -e GITHUB_TOKEN=$GITHUB_TOKEN -e PHANTOM_VERSION=2.1.1 phantomized",
10+
"test": "eslint ."
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/Gravebot/phantomized.git"
15+
},
16+
"author": "Dustin Blackman",
17+
"license": "MIT",
18+
"bugs": {
19+
"url": "https://github.com/Gravebot/phantomized/issues"
20+
},
21+
"homepage": "https://github.com/Gravebot/phantomized#readme",
22+
"dependencies": {
23+
"babel-cli": "^6.5.1",
24+
"babel-preset-es2015-node4": "^2.0.3",
25+
"bluebird": "^3.3.1",
26+
"commander": "^2.9.0",
27+
"fs-extra": "^0.26.5",
28+
"github": "^0.2.4",
29+
"ramda": "^0.19.1",
30+
"request": "^2.69.0"
31+
},
32+
"devDependencies": {
33+
"babel-eslint": "^5.0.0",
34+
"eslint": "^1.10.3",
35+
"eslint-config-busbud": "^0.1.2",
36+
"eslint-config-semistandard": "^5.0.0",
37+
"eslint-config-standard": "^4.4.0",
38+
"eslint-plugin-standard": "^1.3.2"
39+
},
40+
"babel": {
41+
"presets": [
42+
"es2015-node4"
43+
]
44+
}
45+
}

0 commit comments

Comments
 (0)