feat(docker): add docker via Circle CI (#212) r=jbuck,seanmonstar

Fixes #208
This commit is contained in:
Vlad Filippov 2017-03-05 12:42:58 -05:00 коммит произвёл GitHub
Родитель 70dcc5b899
Коммит 8f913be7fd
5 изменённых файлов: 74 добавлений и 31 удалений

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

@ -1,11 +0,0 @@
FROM ubuntu:trusty
RUN DEBIAN_FRONTEND=noninteractive apt-get -y update && DEBIAN_FRONTEND=noninteractive apt-get -y install nodejs npm git
RUN ln -sf /usr/bin/nodejs /usr/local/bin/node
RUN useradd --home-dir /opt/fxa fxa
USER fxa
WORKDIR /opt/fxa
CMD npm start

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

@ -0,0 +1,19 @@
FROM mhart/alpine-node:4.8.0
RUN addgroup -g 10001 app && \
adduser -D -G app -h /app -u 10001 app
WORKDIR /app
# S3 bucket in Cloud Services prod IAM
ADD https://s3.amazonaws.com/dumb-init-dist/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init
ENTRYPOINT ["/usr/local/bin/dumb-init", "--"]
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-auth-db-mysql:build
RUN npm install

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

@ -1,6 +1,7 @@
# Firefox Accounts database service
[![Build Status][ci-status-icon]][ci-status]
[![CircleCI](https://circleci.com/gh/mozilla/fxa-auth-db-mysql.svg?style=svg)](https://circleci.com/gh/mozilla/fxa-auth-db-mysql)
Node.js-based database service
for Firefox Accounts.
@ -171,26 +172,6 @@ mysql -u root -p -e 'DROP DATABASE fxa'
It will be recreated automatically
next time you run `npm start`.
### Docker-based development
To run the MySQL backend
inside a container,
use the following commands:
```sh
docker build --rm -t mozilla/fxa_auth_db_mysql .
docker run --rm -v $PWD:/opt/fxa mozilla/fxa_auth_db_mysql npm install
docker run -it --rm -v $PWD:/opt/fxa --net=host mozilla/fxa_auth_db_mysql
```
This method shares the codebase
into a container
and runs the MySQL backend inside it.
You can `npm install`
and edit code
in your normal desktop environment
and the changes will be picked up automatically.
## License
[MPL 2.0][license]

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

@ -0,0 +1,52 @@
# These environment variables must be set in CircleCI UI
#
# DOCKERHUB_REPO - docker hub repo, format: <username>/<repo>
# DOCKER_EMAIL - login info for docker hub
# DOCKER_USER
# DOCKER_PASS
#
machine:
services:
- docker
- mysql
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-auth-db-mysql:build .
- docker build -f Dockerfile-test -t fxa-auth-db-mysql:test .
test:
override:
- docker run --net="host" fxa-auth-db-mysql:test npm test
# appropriately tag and push the container to dockerhub
deployment:
hub_latest:
branch: "master"
commands:
- "[ ! -z $DOCKERHUB_REPO ]"
- docker login -e "$DOCKER_EMAIL" -u "$DOCKER_USER" -p "$DOCKER_PASS"
- "docker tag fxa-auth-db-mysql: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-auth-db-mysql:build ${DOCKERHUB_REPO}:${CIRCLE_TAG}"
- "docker images"
- "docker push ${DOCKERHUB_REPO}:${CIRCLE_TAG}"