diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..807566d --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,51 @@ +# Python CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-python/ for more details +# +version: 2 +jobs: + build: + docker: + - image: circleci/python:3.6.2 + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # - image: circleci/postgres:9.4 + + working_directory: ~/repo + + steps: + - checkout + - setup_remote_docker + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "requirements.txt" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - save_cache: + paths: + - ./venv + key: v1-dependencies-{{ checksum "requirements.txt" }} + + # setup + - run: + name: circleci-setup + command: | + docker create -v /usr/src/app -v /usr/src/app/.venv --name holder python:3.6.2 + docker cp . holder:/usr/src/app + docker start holder + # run tests! + - run: + name: run tests + command: | + docker-compose -f docker-compose-circle.yml run flake8 atf_eregs + docker-compose -f docker-compose-circle.yml run py.test atf_eregs/tests + + - store_artifacts: + path: test-reports + destination: test-reports + diff --git a/devops/activate_then b/devops/activate_then index e78b6e7..74a3e04 100755 --- a/devops/activate_then +++ b/devops/activate_then @@ -13,14 +13,14 @@ if [ -n "$DEBUG" ]; then if git diff --exit-code eregs_libs/regulations-site > /dev/null then - git submodule update eregs_libs/regulations-site + git submodule update --init eregs_libs/regulations-site else echo "Warning: Modified version of regulations-site detected" fi if git diff --exit-code eregs_libs/regulations-core > /dev/null then - git submodule update eregs_libs/regulations-core + git submodule update --init eregs_libs/regulations-core else echo "Warning: Modified version of regulations-core detected" fi @@ -33,5 +33,4 @@ else pip-sync requirements.txt fi - exec "$@" diff --git a/docker-compose-circle.yml b/docker-compose-circle.yml new file mode 100644 index 0000000..0ecb938 --- /dev/null +++ b/docker-compose-circle.yml @@ -0,0 +1,90 @@ +version: '2' +services: + persistent_db: + image: postgres:9.4 + volumes_from: + - container:holder + prod: &PROD + image: python:3.6.2 + command: ./devops/activate_then ./devops/run_webserver.sh + ports: + - 9000:9000 + environment: &PROD_ENV + PORT: 9000 + DJANGO_SETTINGS_MODULE: atf_eregs.settings.base + TMPDIR: /tmp + STATIC_ROOT: frontend_build + VCAP_APPLICATION: > + {"uris": ["localhost", "0.0.0.0", "127.0.0.1"]} + volumes_from: + - container:holder + working_dir: /usr/src/app + stdin_open: true + tty: true + dev: &DEV + <<: *PROD + ports: + - 8000:8000 + environment: &DEV_ENV + <<: *PROD_ENV + DEBUG: "true" + PORT: 8000 + dev-with-db: + <<: *DEV + ports: + - 8001:8001 + command: ./devops/wait_for_db_then ./devops/activate_then ./devops/run_webserver.sh + environment: + <<: *DEV_ENV + DATABASE_URL: postgres://postgres@persistent_db/postgres + PORT: 8001 + VCAP_APPLICATION: > + {"uris": ["localhost", "0.0.0.0", "127.0.0.1", "dev-with-db"]} + depends_on: + - persistent_db + + + #---- Commands ---- + manage.py: + <<: *DEV + entrypoint: ./devops/activate_then ./manage.py + command: '' + ports: [] + + py.test: + <<: *DEV + entrypoint: ./devops/activate_then py.test + command: '' + ports: [] + + flake8: + <<: *DEV + entrypoint: ./devops/activate_then flake8 + command: '' + ports: [] + + pip-compile: + <<: *DEV + entrypoint: ./devops/activate_then pip-compile + command: '' + ports: [] + + bandit: + <<: *DEV + entrypoint: ./devops/activate_then bandit + command: '' + ports: [] + + grunt: + image: node:6 + volumes: + - $PWD:/usr/src/app + - npm_libs:/usr/src/app/frontend_build/node_modules/ + working_dir: /usr/src/app/frontend_build/ + entrypoint: ../devops/deps_ok_then ./node_modules/.bin/grunt + +volumes: + database_data: + prod_libs: + dev_libs: + npm_libs: