This commit is contained in:
Vlad Filippov 2018-07-24 06:05:26 -04:00 коммит произвёл Ryan Kelly
Родитель 7e61fe8ac5
Коммит 96b83cba4d
2 изменённых файлов: 85 добавлений и 56 удалений

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

@ -0,0 +1,85 @@
# 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
#
version: 2
jobs:
build:
docker:
- image: circleci/node
steps:
- checkout
- setup_remote_docker
- run:
name: Create version.json
command: >
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
- store_artifacts:
path: version.json
- run:
name: Build deployment container image
command: docker build -f Dockerfile-build -t fxa-basket-proxy:build .
- run:
name: Check npm install
command: docker run --rm -it fxa-basket-proxy:build npm ls --production
- run:
name: Build test container image
command: docker build -f Dockerfile-test -t fxa-basket-proxy:test .
- run:
name: Run Tests
command: docker run fxa-basket-proxy:test npm test
- run:
name: Push to Dockerhub
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
DOCKER_TAG="latest"
fi
if [[ "${CIRCLE_BRANCH}" == feature* ]] || [[ "${CIRCLE_BRANCH}" == dockerpush* ]]; then
DOCKER_TAG="${CIRCLE_BRANCH}"
fi
if [ -n "${CIRCLE_TAG}" ]; then
DOCKER_TAG="$CIRCLE_TAG"
fi
if [ -n "${DOCKER_TAG}" ]; then
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
echo ${DOCKERHUB_REPO}:${DOCKER_TAG}
docker tag fxa-basket-proxy:build ${DOCKERHUB_REPO}:${DOCKER_TAG}
docker images
docker push ${DOCKERHUB_REPO}:${DOCKER_TAG}
fi
workflows:
version: 2
# workflow jobs are _not_ run in tag builds by default
# we use filters to whitelist jobs that should be run for tags
# workflow jobs are run in _all_ branch builds by default
# we use filters to blacklist jobs that shouldn't be run for a branch
# see: https://circleci.com/docs/2.0/workflows/#git-tag-job-execution
build-test-push:
jobs:
- build:
filters:
tags:
only: /.*/

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

@ -1,56 +0,0 @@
# 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
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-basket-proxy:build .
- docker build -f Dockerfile-test -t fxa-basket-proxy:test .
test:
override:
- docker run fxa-basket-proxy:test npm test
# appropriately tag and push the container to dockerhub
deployment:
hub_latest:
# push certain branches, they are used by fxa-dev for deployment
branch: /^(master|feature.*|dockerpush.*)$/
commands:
- "[ ! -z $DOCKERHUB_REPO ]"
- docker login -e "$DOCKER_EMAIL" -u "$DOCKER_USER" -p "$DOCKER_PASS"
- |
if [ $CIRCLE_BRANCH = "master" ]; then
CIRCLE_BRANCH=latest
fi
echo ${DOCKERHUB_REPO}:${CIRCLE_BRANCH}
docker tag fxa-basket-proxy:build ${DOCKERHUB_REPO}:${CIRCLE_BRANCH}
docker push ${DOCKERHUB_REPO}:${CIRCLE_BRANCH}
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-basket-proxy:build ${DOCKERHUB_REPO}:${CIRCLE_TAG}"
- "docker images"
- "docker push ${DOCKERHUB_REPO}:${CIRCLE_TAG}"