Skip to content

Commit

Permalink
Migrate to CircleCI 2 (#129); r=jrgm
Browse files Browse the repository at this point in the history
  • Loading branch information
rfk committed Jul 23, 2018
1 parent 7700f72 commit e388588
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 80 deletions.
63 changes: 63 additions & 0 deletions .circleci/config.yml
@@ -0,0 +1,63 @@
version: 2
jobs:
build:
docker:
- image: circleci/python
steps:
- checkout
- setup_remote_docker

- run:
name: Create version.json
command: |
printf '{"commit":"%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 version.json
- store_artifacts:
path: version.json

- run:
name: Build deployment container image
command: docker build -t app:build .
- run:
name: Test flake8
command: docker run -it app:build test_flake8
- run:
name: Test nose
command: docker run -it app:build test_nose
- run:
name: Functional tests
command: docker run -it app:build test_functional
- run:
name: Push to Dockerhub
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
bin/ci/deploy-dockerhub.sh latest
fi
if [[ "${CIRCLE_BRANCH}" == feature* ]] || [[ "${CIRCLE_BRANCH}" == dockerpush* ]]; then
bin/ci/deploy-dockerhub.sh "$CIRCLE_BRANCH"
fi
if [ -n "${CIRCLE_TAG}" ]; then
bin/ci/deploy-dockerhub.sh "$CIRCLE_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: /.*/
8 changes: 8 additions & 0 deletions .dockerignore
@@ -0,0 +1,8 @@
*.pyc
local
*.egg-info
*.swp
\.coverage
*~
nosetests.xml
syncserver.db
9 changes: 5 additions & 4 deletions Dockerfile
@@ -1,4 +1,4 @@
FROM python:2.7-alpine3.7
FROM python:2.7-alpine

RUN addgroup -g 1001 app \
&& adduser -u 1001 -S -D -G app -s /usr/sbin/nologin app
Expand All @@ -17,11 +17,12 @@ RUN apk --no-cache update \
&& pip install --upgrade --no-cache-dir -r dev-requirements.txt \
&& apk del g++

COPY ./syncserver /app/syncserver
COPY ./setup.py /app
COPY . /app
RUN python ./setup.py develop

# run as non priviledged user
USER app

ENTRYPOINT ["/usr/bin/dumb-init", "--"]
# run the server by default
ENTRYPOINT ["/usr/bin/dumb-init", "/app/docker-entrypoint.sh"]
CMD ["server"]
35 changes: 35 additions & 0 deletions bin/ci/deploy-dockerhub.sh
@@ -0,0 +1,35 @@
#!/bin/bash

# THIS IS MEANT TO BE RUN BY CI

set -e

# Usage: retry MAX CMD...
# Retry CMD up to MAX times. If it fails MAX times, returns failure.
# Example: retry 3 docker push "$DOCKERHUB_REPO:$TAG"
function retry() {
max=$1
shift
count=1
until "$@"; do
count=$((count + 1))
if [[ $count -gt $max ]]; then
return 1
fi
echo "$count / $max"
done
return 0
}

# configure docker creds
retry 3 echo "$DOCKER_PASS" | docker login -u="$DOCKER_USER" --password-stdin

# docker tag and push git branch to dockerhub
if [ -n "$1" ]; then
[ "$1" == master ] && TAG=latest || TAG="$1"
docker tag app:build "$DOCKERHUB_REPO:$TAG" ||
(echo "Couldn't tag app:build as $DOCKERHUB_REPO:$TAG" && false)
retry 3 docker push "$DOCKERHUB_REPO:$TAG" ||
(echo "Couldn't push $DOCKERHUB_REPO:$TAG" && false)
echo "Pushed $DOCKERHUB_REPO:$TAG"
fi
75 changes: 0 additions & 75 deletions circle.yml

This file was deleted.

49 changes: 49 additions & 0 deletions docker-entrypoint.sh
@@ -0,0 +1,49 @@
#!/bin/sh

cd $(dirname $0)
case "$1" in
server)
export SYNCSERVER_SQLURI="${SYNCSERVER_SQLURI:-sqlite:///tmp/syncserver.db}"
exec gunicorn \
--bind ${HOST-0.0.0.0}:${PORT-5000}\
syncserver.wsgi_app
;;

test_all)
$0 test_flake8
$0 test_nose
$0 test_functional
;;

test_flake8)
echo "test - flake8"
flake8 syncserver
;;

test_nose)
echo "test - nose"
nosetests --verbose --nocapture syncstorage.tests
;;

test_functional)
echo "test - functional"
# run functional tests
gunicorn --paste ./syncserver/tests.ini &
SERVER_PID=$!
sleep 2

$0 test_endpoint http://localhost:5000

kill $SERVER_PID
;;

test_endpoint)
exec python -m syncstorage.tests.functional.test_storage \
--use-token-server $2/token/1.0/sync/1.5
;;

*)
echo "Unknown CMD, $1"
exit 1
;;
esac
2 changes: 1 addition & 1 deletion syncserver/tests.ini
Expand Up @@ -13,7 +13,7 @@ use = egg:SyncServer
public_url = http://localhost:5000/

# This defines the database in which to store all server data.
#sqluri = sqlite:////tmp/syncserver.db
sqluri = sqlite:///:memory:

# This is a secret key used for signing authentication tokens.
#secret = INSERT_SECRET_KEY_HERE

0 comments on commit e388588

Please sign in to comment.