Skip to content

Commit

Permalink
Merge pull request #33 from StableWorld/feature/make
Browse files Browse the repository at this point in the history
Update circle ci for new deployment
  • Loading branch information
srossross committed Jan 13, 2018
2 parents aa328ca + 114b573 commit 06a0062
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 94 deletions.
10 changes: 10 additions & 0 deletions .circleci/InstallBuildDependencies.sh
@@ -0,0 +1,10 @@
set +xe
apk add --no-cache \
openssl \
make \
curl curl-dev \
py-pip \
sudo \
bash

pip install -q docker-compose==1.16.1
7 changes: 7 additions & 0 deletions .circleci/InstallDeployDependencies.sh
@@ -0,0 +1,7 @@
set +xe
curl -o docker.tgz https://download.docker.com/linux/static/stable/x86_64/docker-17.06.2-ce.tgz
tar --extract \
--file docker.tgz \
--strip-components 1 \
--directory /usr/local/bin/
apt-get install -y make
82 changes: 82 additions & 0 deletions .circleci/config.yml
@@ -0,0 +1,82 @@
environment: &env
CONTAINER: stable.world.auth
DEPLOYMENT: auth
GCLOUD_ZONE: us-central1-a
GCLOUD_PROJECT: my-project-1-152801

version: 2
jobs:
build:
working_directory: /workspace
docker:
- image: docker:17.05.0-ce-git
steps:
- checkout
- setup_remote_docker:
version: 17.05.0-ce
- run:
name: Install Dependencies
command: .circleci/InstallBuildDependencies.sh
- run:
name: Install
command: |
pip install --upgrade pip setuptools wheel
pip install -r ./requirements.txt
python setup.py develop
- run:
name: Build apps
command: |
make buildApp
make buildDockerPY2
make buildDockerPY3
- run:
name: Lint
command: make lint
- run:
name: Test
command: |
make testPY2
make testPY3
./bin/stable.world --help
- persist_to_workspace:
# Must be an absolute path, or relative path from working_directory
root: /workspace
# Must be relative path from root
paths:
- bin/stable.world

deploy:
working_directory: /workspace
docker:
- image: google/cloud-sdk
# Environment variable for all commands executed in the primary container
environment: *env
steps:
- checkout
- attach_workspace:
# Must be absolute path or relative path from working_directory
at: /workspace
- run:
name: "Install Dependencies"
command: .circleci/InstallDeployDependencies.sh
- run:
name: "Authorize Google Cloud"
command: |
make deploy-fetch
make deploy-authorize
- run:
name: "Rollout to Stage"
command: |
make deploy-development
workflows:
version: 2
build-test-and-deploy:
jobs:
- build
- deploy:
# filters:
# branches:
# only: master
requires:
- build
55 changes: 55 additions & 0 deletions Makefile
@@ -0,0 +1,55 @@

buildApp: ## build and bundle app
sh scripts/makeapp.sh

buildDocs: ## build docs
(cd docs/ && make html)

buildDockerPY2: ## build python2 docker image
echo "FROM python:2" | cat - Dockerfile.test.template > Dockerfile.py2
docker build -f Dockerfile.py2 -t testpy2 .

buildDockerPY3: ## build python3 docker image
echo "FROM python:3" | cat - Dockerfile.test.template > Dockerfile.py3
docker build -f Dockerfile.py3 -t testpy3 .

test: ## test code
py.test

lint: ## lint code
flake8

testPY2: ## test with python2
docker run testpy2 py.test /app/

testPY3: ## test with python3
docker run testpy3 py.test /app/


testFunctional: ## run functional_tests
py.test functional_tests/

deploy-fetch: ## fetch deploy repo
rm -rf deployment
git clone https://gist.github.com/befb8025b4fdf52d7db8391a1cbe0c22.git deployment

deploy-authorize: ## authorize gcloud
echo $$GCLOUD_SERVICE_KEY | base64 --decode > $${HOME}/gcloud-service-key.json
gcloud auth activate-service-account --key-file $${HOME}/gcloud-service-key.json
gcloud config set project $$GCLOUD_PROJECT

deploy-master: ## deploy master version
sh deployment/master-cli.sh

deploy-development: ## deploy development version
sh deployment/development-cli.sh

release: ## upload release
gsutil -h "Content-Type:text/plain" cp gs://stable-world-downloads/rc gs://stable-world-downloads/latest

.PHONY: help

help: ## show this help and exit
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.DEFAULT_GOAL := help
58 changes: 0 additions & 58 deletions circle.yml

This file was deleted.

23 changes: 0 additions & 23 deletions package.json

This file was deleted.

15 changes: 15 additions & 0 deletions scripts/Dockerfile
@@ -0,0 +1,15 @@
from python:3.6
# set -eux
COPY . /project
WORKDIR /project
# git clean -xdf dist app

RUN python setup.py sdist --quiet
RUN pip install --quiet --target app dist/stable.world-*.tar.gz
RUN python -m compileall app/
RUN python -m zipapp app -o ./bin/stable.world.pyz

RUN cat ./app/header.sh ./bin/stable.world.pyz > ./bin/stable.world
# TODO: windows deploy
# cat ./app/header.bat ./bin/stable.world.pyz > ./bin/stable.world.bat
RUN chmod +x ./bin/stable.world
17 changes: 6 additions & 11 deletions scripts/makeapp.sh
@@ -1,13 +1,8 @@
set -euo pipefail
set -eux

git clean -xdf dist app
python3.6 setup.py sdist
pip install --target app dist/stable.world-*.tar.gz

python2.7 -m compileall app/
python3.6 -m compileall app/

python3.6 -m zipapp app -o ./bin/stable.world.pyz
cat ./app/header.sh ./bin/stable.world.pyz > ./bin/stable.world
cat ./app/header.bat ./bin/stable.world.pyz > ./bin/stable.world.bat
chmod +x ./bin/stable.world
docker build -f scripts/Dockerfile -t makeapp:build .
docker create --name extract makeapp:build
docker cp extract:/project/bin/stable.world ./bin/stable.world
ls -la bin/stable.world
echo "OK!"
2 changes: 1 addition & 1 deletion stable_world/executors.py
Expand Up @@ -121,7 +121,7 @@ def remove_file(filename):
try:
pass
# os.unlink(filename)
except:
except Exception:
pass


Expand Down
2 changes: 1 addition & 1 deletion stable_world/output/error_output.py
Expand Up @@ -32,7 +32,7 @@ def write_error_log(cache_dirname, exctype, value, tb):
tb = '\n'.join(traceback.format_exception(exctype, value, tb))
print(tb, file=fd)
click.echo('\n Wrote full traceback to "{}"\n'.format(logfile), err=True)
except:
except Exception:
click.echo("Failed to write logfile", err=True)
original_excepthook(exctype, value, tb)

Expand Down

0 comments on commit 06a0062

Please sign in to comment.