Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New githubapi docker #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
config.*.json
node_modules
result.json
package-lock.json
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:slim

WORKDIR /app

# avoid package-lock.json since this can run on multi-platforms
COPY package.json ./

RUN apt-get update && apt-get install --no-install-recommends -y git && rm -rf /var/lib/apt/lists/*
RUN npm install --only=production && npm audit fix

COPY . .

EXPOSE 8089
CMD ["npm","start"]
14 changes: 14 additions & 0 deletions arm32v7.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM arm32v7/node:11.6.0-stretch-slim

WORKDIR /app

# avoid package-lock.json since this can run on multi-platforms
COPY package.json ./

RUN apt-get update && apt-get install --no-install-recommends -y git && rm -rf /var/lib/apt/lists/*
RUN npm install --only=production && npm audit fix

COPY . .

EXPOSE 8089
CMD ["npm","start"]
56 changes: 56 additions & 0 deletions docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Build

docker build -t andresvidal/speedtracker-api .

## Build on ARM devices

Clone Git repo locally:

git clone https://github.com/andresvidal/speedtracker-api.git

and run:

docker build -f arm32v7.Dockerfile -t andresvidal/speedtracker-api:arm32v7 .

# Run

## With inline config:

docker run -it --rm \
--name speedtracker-api \
-p 8089:8089 \
-e "PORT=8089" \
-e "WPT_KEY=..." \
-e "GITHUB_TOKEN=..." \
-e "PAGESPEED_API_KEY=..." \
-e "MONGODB_URI=..." \
andresvidal/speedtracker-api:latest

## With local config file:

docker run -it --rm \
--name speedtracker-api \
-v `pwd`:/app \
-p 8089:8089 \
andresvidal/speedtracker-api:latest

## On ARM32 devices as a Daemon:

docker run -d \
--name speedtracker-api \
--restart=unless-stopped \
-p 8089:8089 \
-e "PORT=8089" \
-e "WPT_KEY=..." \
-e "GITHUB_TOKEN=..." \
-e "PAGESPEED_API_KEY=..." \
-e "MONGODB_URI=..." \
andresvidal/speedtracker-api:arm32v7

## Interactive session:

docker exec -it speedtracker-api bash

# Test

http://<server-ip>:8089/v1/test/{USERNAME}/{REPOSITORY}/{BRANCH}/{PROFILE}?key={KEY}
3 changes: 2 additions & 1 deletion lib/GitHub.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const GitHubApi = require('github')
//const GitHubApi = require('github')
const GitHubApi = require('@octokit/rest') // keeping const "GitHubApi" for context

const GITHUB_CONNECT = 1

Expand Down
20 changes: 10 additions & 10 deletions lib/SpeedTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ SpeedTracker.prototype._getPagespeedScore = function (url) {
}

SpeedTracker.prototype._getRemoteFile = function (file) {
return this.options.remote.api.repos.getContent({
user: this.options.user,
return this.options.remote.api.repos.getContents({
owner: this.options.user,
repo: this.options.repo,
path: file,
ref: this.options.branch
}).then(response => {
var content = new Buffer(response.content, 'base64').toString()
var content = new Buffer.from(response.data.content, 'base64').toString()

return {
content,
sha: response.sha
sha: response.data.sha
}
})
}
Expand Down Expand Up @@ -219,14 +219,14 @@ SpeedTracker.prototype._saveTest = function (profile, content, isScheduled) {

// Append results
Utils.mergeObject(payload._r, content, payload._ts.length)

return this.options.remote.api.repos.updateFile({
user: this.options.user,
owner: this.options.user,
repo: this.options.repo,
branch: this.options.branch,
path: path,
sha: data.sha,
content: new Buffer(JSON.stringify(payload)).toString('base64'),
content: new Buffer.from(JSON.stringify(payload)).toString('base64'),
message: message
})
} catch (err) {
Expand All @@ -243,15 +243,15 @@ SpeedTracker.prototype._saveTest = function (profile, content, isScheduled) {
Utils.mergeObject(payload._r, content)

return this.options.remote.api.repos.createFile({
user: this.options.user,
owner: this.options.user,
repo: this.options.repo,
branch: this.options.branch,
path: path,
content: new Buffer(JSON.stringify(payload)).toString('base64'),
content: new Buffer.from(JSON.stringify(payload)).toString('base64'),
message: message
})
} else {
return Promise.reject(Utils.buildError('CORRUPT_RESULT_FILE'))
return Promise.reject(Utils.buildError('CORRUPT_RESULT_FILE_ERR2'))
}
})
}
Expand Down
Loading