feat(docker): add Docker support (#176) r=vladikoff,jbuck

This commit is contained in:
Sean McArthur 2017-03-05 10:02:18 -08:00 коммит произвёл Vlad Filippov
Родитель 7c2b774d8a
Коммит b0cb1fa1a7
7 изменённых файлов: 87 добавлений и 33 удалений

14
Dockerfile-build Normal file
Просмотреть файл

@ -0,0 +1,14 @@
FROM mhart/alpine-node:4.8.0
RUN addgroup -g 10001 app && \
adduser -D -G app -h /app -u 10001 app
WORKDIR /app
USER app
COPY npm-shrinkwrap.json npm-shrinkwrap.json
COPY package.json package.json
RUN npm install --production && rm -rf ~app/.npm /tmp/*
COPY . /app

2
Dockerfile-test Normal file
Просмотреть файл

@ -0,0 +1,2 @@
FROM fxa-customs-server:build
RUN npm install

Просмотреть файл

@ -5,14 +5,7 @@ Firefox Accounts Customs Server
This project is used by the [Firefox Accounts Auth Server](https://github.com/mozilla/fxa-auth-server) to detect and deter [fraud and abuse](https://wiki.mozilla.org/Identity/Firefox_Accounts/Fraud_and_abuse).
## Prerequisites
* node 0.10.x
* npm
* memcached
* On Debian flavors of Linux: `sudo apt-get install memcached`
* On Mac OS X: `brew install memcached`
## Install
## Development
Clone the git repository and install dependencies:
@ -26,6 +19,12 @@ To start the server, run:
It will listen on http://127.0.0.1:7000 by default.
## Docker Based Development
To run the customs server via Docker:
$ docker-compose up mozilla/fxa_customs_server
## Testing
Run tests with:
@ -37,6 +36,13 @@ On Mac OS X, memcached must be manually started for the tests to run.
memcached &
npm test
To run tests via Docker:
```
docker-compose run mozilla/fxa_customs_server npm test
```
## Code
Here are the main components of this project:

44
circle.yml Normal file
Просмотреть файл

@ -0,0 +1,44 @@
machine:
services:
- docker
- memcached
dependencies:
override:
- docker info
- >
printf '{"version":{"hash":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}}\n'
"$CIRCLE_SHA1"
"$CIRCLE_TAG"
"$CIRCLE_PROJECT_USERNAME"
"$CIRCLE_PROJECT_REPONAME"
"$CIRCLE_BUILD_URL"
| tee config/version.json version.json
- docker build -f Dockerfile-build -t fxa-customs-server:build .
- docker build -f Dockerfile-test -t fxa-customs-server:test .
test:
override:
- docker run --net="host" fxa-customs-server:test npm test
deployment:
hub_latest:
branch: "master"
commands:
- "[ ! -z $DOCKERHUB_REPO ]"
- docker login -e "$DOCKER_EMAIL" -u "$DOCKER_USER" -p "$DOCKER_PASS"
- "docker tag fxa-customs-server:build ${DOCKERHUB_REPO}:latest"
- "docker push ${DOCKERHUB_REPO}:latest"
hub_releases:
# push all tags
tag: /.*/
commands:
- "[ ! -z $DOCKERHUB_REPO ]"
- docker login -e "$DOCKER_EMAIL" -u "$DOCKER_USER" -p "$DOCKER_PASS"
- "echo ${DOCKERHUB_REPO}:${CIRCLE_TAG}"
- "docker tag fxa-customs-server:build ${DOCKERHUB_REPO}:${CIRCLE_TAG}"
- "docker images"
- "docker push ${DOCKERHUB_REPO}:${CIRCLE_TAG}"

Просмотреть файл

@ -1,17 +0,0 @@
#!/usr/bin/env node
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* eslint-disable no-console */
var path = require('path'),
spawn = require('child_process').spawn
var COVERAGE_ARGS = ['--coverage', '--cov']
if (process.env.NO_COVERAGE) {
COVERAGE_ARGS = []
}
spawn(path.join(path.dirname(__dirname), 'node_modules', '.bin', 'tap'),
process.argv.slice(2).concat(COVERAGE_ARGS), { stdio: 'inherit', env: process.env })

Просмотреть файл

@ -5,4 +5,10 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
node_modules/.bin/grunt lint copyright || exit 1
node scripts/tap-coverage.js test/local test/remote || exit 1
cov=""
if test "$NO_COVERAGE" = ""; then
cov="--coverage --cov"
fi
tap test/local test/remote $cov

Просмотреть файл

@ -2,6 +2,8 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */
var fs = require('fs')
var os = require('os')
var path = require('path')
var Promise = require('bluebird')
var test = require('tap').test
@ -249,18 +251,15 @@ test(
test(
'IPBlocklistManager, reloads file correctly',
function (t) {
var tmpFilename = './test/mocks/temp.netset'
var tmpFilename = path.join(
os.tmpdir(),
'fxa-customs-ipblocklist-' + Date.now() + '.netset'
)
var tmpFileContents = '87.87.87.87'
var tmpFileContents2 = '87.87.87.86'
var ipBlocklist = new IPBlocklistManager()
// Delete old tmp to ensure starting from scratch
try {
fs.unlinkSync(tmpFilename)
} catch (err) {
}
fs.writeFileSync(tmpFilename, tmpFileContents, {})
ipBlocklist.load([tmpFilename])