Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
ci: setup travis and docker (#1)
Browse files Browse the repository at this point in the history
ci: setup travis and docker
  • Loading branch information
sergeysova committed Sep 8, 2019
2 parents 5a440ca + b2e1642 commit 1c7ec89
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
41 changes: 41 additions & 0 deletions .travis.yml
@@ -0,0 +1,41 @@
language: minimal

os:
- linux

services:
- docker

env:
- DOCKER_IMAGE=howtocards/preview

before_script:
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD

jobs:
include:
- stage: build
script:
- echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
- docker pull $DOCKER_IMAGE:latest || true
- docker build -t $DOCKER_IMAGE:$TRAVIS_COMMIT --cache-from $DOCKER_IMAGE:latest .
- docker images
- docker push $DOCKER_IMAGE:$TRAVIS_COMMIT
- stage: push latest
if: branch = master AND type != pull_request
script:
- docker pull $DOCKER_IMAGE:$TRAVIS_COMMIT
- docker tag $DOCKER_IMAGE:$TRAVIS_COMMIT $DOCKER_IMAGE:latest
- docker push $DOCKER_IMAGE:latest
- stage: push nightly
if: branch = dev AND type != pull_request
script:
- docker pull $DOCKER_IMAGE:$TRAVIS_COMMIT
- docker tag $DOCKER_IMAGE:$TRAVIS_COMMIT $DOCKER_IMAGE:nightly
- docker push $DOCKER_IMAGE:nightly
- stage: push tag
if: tag =~ /^v\d+\.\d+\.\d+/
script:
- docker pull $DOCKER_IMAGE:$TRAVIS_COMMIT
- docker tag $DOCKER_IMAGE:$TRAVIS_COMMIT $DOCKER_IMAGE:$TRAVIS_TAG
- docker push $DOCKER_IMAGE:$TRAVIS_TAG
37 changes: 37 additions & 0 deletions Dockerfile
@@ -0,0 +1,37 @@
FROM node:10-slim
WORKDIR /app

RUN apt-get update \
# Install latest chrome dev package, which installs the necessary libs to
# make the bundled version of Chromium that Puppeteer installs work.
&& apt-get install -y wget --no-install-recommends \
&& 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 --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& wget --quiet https://gist.githubusercontent.com/sergeysova/275b55e6212136818dbe2324dcfc9952/raw/4ca2cfe8fec071e7b344038a9c4ecedf745f392e/wait-for-it.sh -O /usr/sbin/wait-for-it.sh \
&& chmod +x /usr/sbin/wait-for-it.sh

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

COPY package.json yarn.lock ./
RUN yarn install
COPY . .
RUN yarn test

# Add user so we don't need --no-sandbox.
RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
&& mkdir -p /home/pptruser/Downloads \
&& chown -R pptruser:pptruser /home/pptruser \
&& chown -R pptruser:pptruser ./node_modules

# Run everything after as non-privileged user.
USER pptruser

EXPOSE 9000
VOLUME ["/app/screenshots"]

ENTRYPOINT ["dumb-init", "--"]
CMD [ "yarn", "start" ]
9 changes: 7 additions & 2 deletions main.js
Expand Up @@ -6,7 +6,9 @@ const cardPath = () =>
path.resolve(__dirname, `screenshots/${new Date().toISOString()}.png`);

async function main() {
const browser = await puppeteer.launch();
const browser = await puppeteer.launch({
args: ["--disable-dev-shm-usage", "--no-sandbox"]
});
try {
const page = await browser.newPage();
await page.goto(CARD, { waitUntil: "networkidle0" });
Expand All @@ -22,4 +24,7 @@ async function main() {
}
}

main().catch(console.error);
main().catch(error => {
console.error(error);
process.exit(-1);
});
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"start": "node main.js",
"test": "echo \"Error: no test specified\" && true"
},
"repository": {
"type": "git",
Expand All @@ -17,6 +18,6 @@
},
"homepage": "https://github.com/howtocards/preview#readme",
"dependencies": {
"puppeteer": "^1.19.0"
"puppeteer": "1.17.0"
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -211,10 +211,10 @@ proxy-from-env@^1.0.0:
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.0.0.tgz#33c50398f70ea7eb96d21f7b817630a55791c7ee"
integrity sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=

puppeteer@^1.19.0:
version "1.19.0"
resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-1.19.0.tgz#e3b7b448c2c97933517078d7a2c53687361bebea"
integrity sha512-2S6E6ygpoqcECaagDbBopoSOPDv0pAZvTbnBgUY+6hq0/XDFDOLEMNlHF/SKJlzcaZ9ckiKjKDuueWI3FN/WXw==
puppeteer@1.17.0:
version "1.17.0"
resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-1.17.0.tgz#371957d227a2f450fa74b78e78a2dadb2be7f14f"
integrity sha512-3EXZSximCzxuVKpIHtyec8Wm2dWZn1fc5tQi34qWfiUgubEVYHjUvr0GOJojqf3mifI6oyKnCdrGxaOI+lWReA==
dependencies:
debug "^4.1.0"
extract-zip "^1.6.6"
Expand Down

0 comments on commit 1c7ec89

Please sign in to comment.