зеркало из https://github.com/mozilla/doorman.git
99 строки
2.9 KiB
YAML
99 строки
2.9 KiB
YAML
# 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:
|
|
environment:
|
|
|
|
# make some env vars to save typing
|
|
# GWS should already exists on the ubuntu trusty build image
|
|
GWS: "$HOME/.go_workspace"
|
|
A: "$GWS/src/github.com/$CIRCLE_PROJECT_USERNAME"
|
|
B: "$A/$CIRCLE_PROJECT_REPONAME"
|
|
|
|
# Use to install Custom golang from https://golang.org/dl/
|
|
GODIST: "go1.9.linux-amd64.tar.gz"
|
|
GODIST_HASH: "d70eadefce8e160638a9a6db97f7192d8463069ab33138893ad3bf31b0650a79"
|
|
|
|
services:
|
|
- docker
|
|
|
|
# install custom golang
|
|
post:
|
|
- mkdir -p download
|
|
- test -e download/$GODIST || curl -o download/$GODIST https://storage.googleapis.com/golang/$GODIST
|
|
# verify it
|
|
- echo "$GODIST_HASH download/$GODIST" | sha256sum -c
|
|
- sudo rm -rf /usr/local/go
|
|
|
|
- sudo tar -C /usr/local -xzf download/$GODIST
|
|
|
|
dependencies:
|
|
cache_directories:
|
|
- "~/docker"
|
|
- "~/download"
|
|
|
|
pre:
|
|
- sudo apt-get update; sudo apt-get install pigz
|
|
|
|
override:
|
|
- mkdir -p $GWS/pkg $GWS/bin $A
|
|
- ln -fs $HOME/$CIRCLE_PROJECT_REPONAME $A
|
|
|
|
- echo 'export GOPATH=$GWS' >> ~/.circlerc
|
|
|
|
- docker info
|
|
|
|
# Build the container, using Circle's Docker cache. Only use 1 image per
|
|
# day to keep the cache size down.
|
|
- I="image-$(date +%j).gz"; if [ -e "~/docker/$I" ]; then echo "Loading $I"; pigz -d -c "~/docker/$I" | docker load || rm -f "~/docker/$I"; fi
|
|
|
|
# create a version.json
|
|
- >
|
|
printf '{"name":"%s","commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n'
|
|
"doorman"
|
|
"$CIRCLE_SHA1"
|
|
"$CIRCLE_TAG"
|
|
"mozilla"
|
|
"$CIRCLE_PROJECT_REPONAME"
|
|
"$CIRCLE_BUILD_URL"
|
|
> version.json
|
|
|
|
# build the actual deployment container
|
|
- go version
|
|
- cd "$B" && make
|
|
- docker build --pull -t app .
|
|
|
|
# Clean up any old images; save the new one.
|
|
- I="image-$(date +%j).gz"; mkdir -p ~/docker; rm ~/docker/*; docker save app | pigz --fast -c > ~/docker/$I; ls -l ~/docker
|
|
|
|
test:
|
|
override:
|
|
- git checkout version.json
|
|
- cd "$B" && make 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 images"
|
|
- "docker tag app ${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 app ${DOCKERHUB_REPO}:${CIRCLE_TAG}"
|
|
- "docker images"
|
|
- "docker push ${DOCKERHUB_REPO}:${CIRCLE_TAG}"
|