Skip to content

Commit

Permalink
add worker stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
rmb938 committed Oct 9, 2017
1 parent 561f26c commit ad097f2
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[run]
omit =
*/test/*

[report]
exclude_lines =
pragma: no cover
def __repr__
raise NotImplementedError
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
language: python
python:
- '3.6'
env:
#- TOXENV=py36
- TOXENV=flake8
- TOXENV=build
install:
- pip install tox
script: tox
services:
- postgresql

stages:
- test
- name: pypi
if: tag IS present
- name: docker
if: tag IS present

jobs:
include:
- stage: pypi
script: 'echo "Deploying to PyPi"'
deploy:
provider: pypi
user: rmb938
password:
secure: fhdvEq81B9Fl9+gzqVRSNVOBn9Pw5eWGiOJhHp+3N4M7AOUGta35mu5K7BSgIZuwQ+pgWWdQOcrszNyEs9GFIibLiE3aTKhPOIxnR89bINAZLrvm5RfXik1kjOKhx0jCsrEtFfQAfw9hg8cr2I099BBrAoRYQJZrHIVLaO77uvj/rd583OTsLE6smRkjj89yqktuTmhtdh5XK8aFr+wXNFIKcAxq4uDh6L/X521uRSkwvRjlA05OI9/Pyv4B52yXPJK5+QhwrwY0EwdbmfIpI81IQhzfErYwh7cUPyFgExTZitbpEd2+JS8k9VSV709sfHzeglbEe2Z5wkEGCGEPV85IQMpicBV9Am8omOc87qp9pXTerrYS8HSYcXWZqma75sdHy22VTVyPz5hTXu8ssA3tA/QqsES78BJIWOLPdkd1/CyJCTX7fm2rGdwVITn7floGGmhh4DjdciuAHr3/hd+w3uB5D1c57voXGSGfy5tCc+LanItrfberz61oyr0FlOjSo6OCbE41UEYVrRYlRhV5dMXHC2qEk3M9uyJGkf3ZMQlir+/OsTDJD/GDdGz8r8Y2aQ7cLz6fgRvzw9yAuiGhDmWNiADNjJa+JYpjRDYt7xQLZtaeHH8GXQLqIV7BaN9nF0Rhe9beUYiMnDnx9PDRK2Qf0Y5stJy50cwFdGE=
on:
tags: true
- stage: docker
env:
- secure: "1maT8WTEjmCMWLQQV/ZN9KI98TK5ISfCDI265jUuDdhXEHViDRB22AEjCqRRvds1VIWca3o0sivf8d2fAAI15+O2j6UtVg4fnKScycUWx8wbPB0nzCoFLhcRypoDv7Xb19njadAerKDLxMDFRZH2jbpjvANlwaDrb8bgt90lvBFg1lPRzqW5EU1QKe5MtMLBWx1cSiBKguvAsVDNGWyKXwL4cX52EFRQPryyaINDcgbvGUq5SFLRMUd4olE0HhmSsS21I+aZUmIOgJLhi1mwGc9cUYwlz9oSNAYxCK4p/gPem/SDJjNIy+6JmYr7eR3l8ZzOCN7Xso47QydEC+XFBFVwY3IRqQtzKf8DRlI14aV/CHLYc8H15Xlx8hp6Q8ycTGXq4g0FXUDyfTIS2XSYJWmN5tfjloIU0h8C/e3qX76i2lOuHH197T5pHNMhoTdOncDjj+5MqaAeTv5cPFrq5lrWjrZAvW9+PbMPPE+NzP3jyflHAiRYLFTullYW3099VoSkURUeDsMRDF8RxnccKlrmylP4KBqszURCf3Fkl0c4WsdOsQervrPoLkk6Zna3s3uDph36GOYJqs3m1i+eG0EwqrBtrlNO7wp31IS4/EbAuoRBn+TaXN0zaMlgUylorP4Ap5qdGRDyFg7/uMieOn5m3hbi303KAo9ScIlTgVs="
script: ./trigger_docker_build.sh
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM python:3-alpine
WORKDIR /usr/src/app

COPY . .
RUN apk -U add git && python setup.py sdist bdist_wheel

FROM python:3-alpine
WORKDIR /usr/src/app

# Install build time dependencies for uwsgi
# Install dumb-init
# Remove build time dependencies
# Install runtime dependencies
RUN apk --no-cache add --virtual build-deps \
build-base linux-headers pcre-dev postgresql-dev && \
pip install dumb-init psycopg2 && \
apk del build-deps && \
apk --no-cache add bash openssl pcre libpq ca-certificates

# COPY tar.gz from build container
# Install it
# TODO: this should be replaced by a build arg to install the correct version from pypi
COPY --from=0 /usr/src/app/dist/. .
RUN bash -c "pip install *"

# add entrypoint
COPY docker-entrypoint.sh /bin/docker-entrypoint.sh

ENTRYPOINT ["/bin/docker-entrypoint.sh"]
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
deli-worker
-----------

.. image:: https://travis-ci.org/sandwichcloud/deli-worker.svg?branch=master
:target: https://travis-ci.org/sandwichcloud/deli-worker

.. image:: https://badge.fury.io/py/deli-worker.svg
:target: https://badge.fury.io/py/deli-worker

Worker for Sandwich Cloud
Empty file added deli_worker/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions deli_worker/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys

from ingredients_tasks.celary import Messaging, database


def main():
messaging = Messaging('127.0.0.1', 5672, 'sandwich', 'hunter2', '/')
messaging.connect()
database.connect()
# with database.session():
# pass
messaging.app.main = 'deli_worker'
sys.argv.extend(['worker', '-l', 'info', '-Ofair'])
messaging.start(argv=None)


if __name__ == '__main__':
main()
54 changes: 54 additions & 0 deletions deli_worker/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os

from dotenv import load_dotenv

load_dotenv(os.path.join(os.getcwd(), '.env'))

####################
# DATABASE #
####################

DATABASE_DB = 'sandwich'
DATABASE_PORT = '5432'
DATABASE_POOL_SIZE = 20

if os.environ.get('CLI'):
DATABASE_POOL_SIZE = -1

DATABASE_HOST = os.environ['DATABASE_HOST']
DATABASE_USERNAME = os.environ['DATABASE_USERNAME']
DATABASE_PASSWORD = os.environ['DATABASE_PASSWORD']

####################
# RABBITMQ #
####################

RABBITMQ_VHOST = '/'
RABBITMQ_PORT = 5672
RABBITMQ_HOST = os.environ['RABBITMQ_HOST']
RABBITMQ_USERNAME = os.environ['RABBITMQ_USERNAME']
RABBITMQ_PASSWORD = os.environ['RABBITMQ_PASSWORD']

####################
# VMWare #
####################

VCENTER_HOST = os.environ['VCENTER_HOST']
VCENTER_PORT = os.environ['VCENTER_PORT']
VCENTER_USERNAME = os.environ['VCENTER_USERNAME']
VCENTER_PASSWORD = os.environ['VCENTER_PASSWORD']

VCENTER_IMAGES_FOLDER = 'images'
VCENTER_INSTANCES_FOLDER = 'instances'

VCENTER_CLUSTER = 'Management'
VCENTER_DATASTORE = 'datastore2'

####################
# DHCP #
####################

DHCP_SERVER_IP = os.environ['DHCP_SERVER_IP']
DHCP_OMAPI_PORT = os.environ.get('DHCP_OMAPI_PORT', 7911)
DHCP_KEY_NAME = os.environ.get('DHCP_KEY_NAME', None)
DHCP_B64_KEY = os.environ.get('DHCP_B64_KEY', None)
4 changes: 4 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/dumb-init /bin/bash

export SETTINGS_MODULE=deli_worker.settings
deli_worker $@
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ingredients.tasks==0.0.1 # MIT
26 changes: 26 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[metadata]
name = deli-worker
author = Ryan Belgrave
author-email = [email protected]
summary = Worker for Sandwich Cloud
description-file = README.rst
home-page = https://github.com/sandwichcloud/deli-worker
license = MIT
classifier =
Development Status :: 3 - Alpha
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Programming Language :: Python

[files]
packages =
deli_worker

[entry_points]
console_scripts =
deli_worker = deli_worker.main:main

[pbr]
skip_authors = 1
skip_changelog = 1
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from setuptools import setup

setup(
setup_requires=['pbr>=3.0.1', 'setuptools>=17.1'],
pbr=True,
)
Empty file added test-requirements.txt
Empty file.
25 changes: 25 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[tox]
envlist = flake8, build

[testenv:flake8]
commands =
flake8
deps =
flake8

;[testenv:py36]
;commands =
; py.test
;deps =
; -r{toxinidir}/test-requirements.txt

[testenv:build]
commands =
python setup.py sdist bdist_wheel

[flake8]
exclude = .tox, .git, __pycache__, build, dist, *.egg-info, ./.cache, ./.eggs
max-line-length = 120

[pytest]
addopts = --tb=short -rwxs -v --cov=deli_worker --cov-report term-missing:skip-covered
3 changes: 3 additions & 0 deletions trigger_docker_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

curl -H "Content-Type: application/json" -d "{\"source_type\": \"Tag\", \"source_name\": \"$TRAVIS_TAG\"}" -X POST "$DOCKER_HUB_TRIGGER"

0 comments on commit ad097f2

Please sign in to comment.