Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#106 #109

Merged
merged 23 commits into from
Nov 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1427e67
!#106 Add: ignore cache and files
luismayta Nov 22, 2017
24cda9c
!#106 Update: info readme actions for makefile
luismayta Nov 22, 2017
83bd498
!#106 Add: actions for test for make
luismayta Nov 22, 2017
2bb7e5f
!#106 Fix: settings actions for makefile
luismayta Nov 22, 2017
412c1fe
!#106 Fix: change paths for app
luismayta Nov 22, 2017
8727d6e
!#106 Fix: Actions for docker make
luismayta Nov 22, 2017
9b8411f
!#106 Add: package gunicorn
luismayta Nov 22, 2017
6ef8db4
!#106 Add: package behave for python
luismayta Nov 22, 2017
2711584
!#106 Add: templates for docker
luismayta Nov 22, 2017
77f0509
!#106 Add: settings dockerfile for app, docs
luismayta Nov 22, 2017
e79a81a
!#106 Add: ignore path tags
luismayta Nov 22, 2017
c054e7d
!#106 Add: actions for help
luismayta Nov 22, 2017
cfc1aad
!#106 Fix: deleted unnecesary uwsgi
luismayta Nov 22, 2017
df8cd91
!#106 Add: code entrypoint
luismayta Nov 22, 2017
7e1f633
!#106 Fix: change bind all ip
luismayta Nov 23, 2017
9785219
!#106 Fix: clean unnecesary run in app
luismayta Nov 23, 2017
ba43d27
!#106 Add: settings ignore b104 for bandit
luismayta Nov 23, 2017
f13da27
!#106 Fix: exclude bind all interfaces
luismayta Nov 23, 2017
3bb268a
!#106 Add: script for runserver
luismayta Nov 23, 2017
a2f3259
!#106 Fix: settings nginx for app
luismayta Nov 23, 2017
b8f5386
!#106 Fix: settings supervisord application
luismayta Nov 23, 2017
84a8197
!#106 Fix: clean unnecesary package gunicorn
luismayta Nov 23, 2017
c9b8c8b
!#106 Add: settings docker
luismayta Nov 23, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ Dockerfile
*.log
*.pyc
*.tar*
*.zip
.cache
*.rar
# path build sphinx
docs/_build
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ terraform.tfstate.d
*.log
*.aux
*.pdf
GPATH
GRTAGS
GTAGS
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
sha: v1.0.3
hooks:
- id: python-bandit-vulnerability-check
args: []
args:
- --skip=B104
files: .py$
- repo: https://github.com/pre-commit/mirrors-csslint
sha: v1.0.5
Expand Down
77 changes: 77 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
FROM python:3.6.1-alpine
MAINTAINER Luis Mayta <@slovacus>

LABEL NAME python-facebook-chatbot
LABEL VERSION 0.1.0

ENV PACKAGES nginx supervisor bash git libmagic
ENV PACKAGES_DEPENDENCES git \
gcc \
make \
musl-dev \
libc-dev \
libmagic \
gcc \
zlib-dev \
linux-headers \
build-base \
musl \
musl-dev \
build-base \
openssl \
pcre-dev
# By default, allow unlimited file sizes, modify it to limit the file sizes
# To have a maximum of 1 MB (Nginx's default) change the line to:
# ENV NGINX_MAX_UPLOAD 1m
ENV NGINX_MAX_UPLOAD 0

COPY ./requirements/ /usr/src/requirements/
COPY ./requirements.txt /usr/src/requirements.txt

RUN apk add --update --no-cache --virtual .build-deps \
$PACKAGES_DEPENDENCES \
&& pip install --force-reinstall -r /usr/src/requirements.txt \
&& find /usr/local \
\( -type d -a -name test -o -name tests \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + \
&& runDeps="$( \
scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --virtual .rundeps $runDeps \
&& apk del .build-deps \
&& apk add --update --no-cache $PACKAGES \
# nginx
&& mkdir -p /run/nginx \
&& mkdir -p /var/lib/nginx \
&& mkdir -p /var/lib/nginx/tmp \
# forward request and error logs to docker log collector
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
# Remove default configuration from Nginx
&& rm -rf /etc/nginx/conf.d/default.conf

# Copy the modified Nginx conf
COPY docker/templates/etc/nginx/nginx.conf /etc/nginx/nginx.conf
COPY docker/templates/etc/nginx/conf.d/nginx.conf /etc/nginx/conf.d/
# Custom Supervisord config
COPY docker/templates/etc/supervisord.conf /etc/
COPY docker/templates/etc/supervisor/conf.d/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

EXPOSE 80

# Copy the entrypoint that will generate Nginx additional configs
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

# Add demo app
COPY ./ /usr/src
WORKDIR /usr/src

CMD ["/usr/bin/supervisord", "-n"]
34 changes: 23 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,48 @@ END :=""
.PHONY: help build up requirements clean lint test help
.DEFAULT_GOAL := help

PROJECT_NAME := python-facebook-chatbot
PROJECT_NAME_DEV := $(PROJECT_NAME)_dev
PROJECT_NAME_STAGE := $(PROJECT_NAME)_stage
PROJECT_NAME_TEST := $(PROJECT_NAME)_test

PROJECT := python-facebook-chatbot
PROJECT_DEV := $(PROJECT)_dev
PROJECT_STAGE := $(PROJECT)_stage
PROJECT_TEST := $(PROJECT)_test
PYTHON_VERSION=3.6.1
PYENV_NAME="${PROJECT_NAME}"
PYENV_NAME="${PROJECT}"
TERRAFORM_VERSION := 0.10.0
# Git
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)

# Configuration.
SHELL := /bin/bash
ROOT_DIR=$(shell pwd)
MESSAGE:=༼ つ ◕_◕ ༽つ
MESSAGE_HAPPY:="${MESSAGE} Happy Coding"
SCRIPT_DIR=$(ROOT_DIR)/extras/scripts
EXTRAS_DIR:= $(ROOT_DIR)/extras
SCRIPT_DIR=$(EXTRAS_DIR)/scripts
SOURCE_DIR=$(ROOT_DIR)/
REQUIREMENTS_DIR=$(ROOT_DIR)/requirements/
FILE_README=$(ROOT_DIR)/README.rst

include *.mk

help:
@echo '${MESSAGE} Makefile for bot lannister'
@echo '${MESSAGE} Makefile for ${PROJECT}'
@echo ''
@echo 'Usage:'
@echo ' environment create environment with pyenv'
@echo ' install install dependences python by env'
@echo ' clean remove files of build'
@echo ' setup install requirements'
@echo ' hooks copy hooks for git'
@echo ''
@echo ' Docker:'
@echo ''
@echo ' docker.build build all services with docker-compose'
@echo ' docker.cleanup Clean images docker unnecesary'
@echo ' docker.down down services docker-compose'
@echo ' docker.list list services of docker'
@echo ' docker.ssh connect by ssh to container'
@echo ' docker.stop stop services by env'
@echo ' docker.status status container by env'
@echo ' docker.verify_network verify network'
@echo ' docker.up up services of docker-compose'
@echo ' docker.run run {service} {env}'
Expand All @@ -56,6 +63,7 @@ help:
@echo ''
@echo ' Tests:'
@echo ''
@echo ' test Run All tests with coverage'
@echo ' test.lint Run all pre-commit'
@echo ' test.syntax Run all syntax in code'
@echo ''
Expand All @@ -66,8 +74,12 @@ clean:
@find . -name '__pycache__' -delete -print -o -name '*.pyc' -delete -print -o -name '*.tmp' -delete -print
@echo

hook:
cp -rf $(EXTRAS_DIR)/git/hooks/prepare-commit.msg .git/hooks/
chmod a+x .git/hooks/prepare-commit.msg

setup: clean
pip install -r "${REQUIREMENTS_DIR}/setup.txt"
$(pip_install) "${REQUIREMENTS_DIR}/setup.txt"
pre-commit install
cp -rf .env-sample .env

Expand All @@ -82,7 +94,7 @@ environment: clean
install: clean
@echo $(MESSAGE) "Deployment environment: ${env}"
@if [ "${env}" == "" ]; then \
pip install -r requirements.txt; \
$(pip_install) requirements.txt; \
else \
pip install -r "${REQUIREMENTS_DIR}/${env}.txt"; \
$(pip_install) "${REQUIREMENTS_DIR}/${env}.txt"; \
fi
45 changes: 28 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Requirements:

List of applications:

- `Python 3.6.0`_
- `Python 3.6.1`_
- `Docker`_
- `Docker Compose`_

Expand All @@ -50,6 +50,7 @@ Build images

λ make docker.build


Up services
-----------

Expand All @@ -63,27 +64,37 @@ Actions:
.. code-block:: bash

λ make
༼ つ ◕_◕ ༽つ Actions for python-facebook-chatbot

༼ つ ◕_◕ ༽つ Makefile for python-facebook-chatbot
Usage:
make environment create environment with pyenv
make install install dependences python by env
make clean remove files of build
make setup install requirements
environment create environment with pyenv
install install dependences python by env
clean remove files of build
setup install requirements
hooks copy hooks for git

Docker:

make docker.build build all services with docker-compose
make docker.down down services docker-compose
make docker.ssh connect by ssh to container
make docker.stop stop services by env
make docker.verify_network verify network
make docker.up up services of docker-compose
make docker.list list services of docker
docker.build build all services with docker-compose
docker.cleanup Clean images docker unnecesary
docker.down down services docker-compose
docker.list list services of docker
docker.ssh connect by ssh to container
docker.stop stop services by env
docker.status status container by env
docker.verify_network verify network
docker.up up services of docker-compose
docker.run run {service} {env}
docker.list list services of docker

Docs:

docs.show Show restview README
docs.make.html Make documentation html
docs.make.pdf Make documentation pdf

Tests:

test Run All tests with coverage
test.lint Run all pre-commit
test.syntax Run all syntax in code

Expand All @@ -109,7 +120,7 @@ Credits
- `author`_
- `contributors`_

Made with ♥️and ☕️by `author`_ and `company`_.
Made with :heart: ️:coffee:️ and :pizza: by `author`_ and `company`_.

.. |Wercker| image::
https://app.wercker.com/status/642f4288274e91f723ec2ecf7c03966c/s/ 'wercker status'
Expand All @@ -129,6 +140,6 @@ Made with ♥️and ☕️by `author`_ and `company`_.
.. _`author`: https://github.com/luismayta

.. dependences
.. _Python 3.6.0: https://www.python.org/downloads/release/python-361
.. _Python 3.6.1: https://www.python.org/downloads/release/python-361
.. _Docker: https://www.docker.com/
.. _Docker Compose: https://docs.docker.com/compose/
.. _Docker Compose: https://docs.docker.com/compose/
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ version: '3'
services:

app:
hostname: app
ports:
- "80:8000"
restart: always
image: python:3.6.0
image: python:3.6.1-alpine
environment: &environment
- APP_NAME=python-facebook-chatbot
build:
Expand All @@ -27,6 +28,6 @@ services:
context: .
dockerfile: docker/docs/Dockerfile
volumes:
- .:/app
- .:/usr/src
env_file:
- .env
26 changes: 19 additions & 7 deletions docker.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Docker
.PHONY: docker.build docker.test docker.pkg

DOCKER_NETWORK = $(PROJECT_NAME)_network
DOCKER_NETWORK = $(PROJECT)_network

docker.run: clean
@if [ "${env}" == "" ]; then \
Expand All @@ -13,30 +13,42 @@ docker.run: clean
docker.build: clean
@echo $(MESSAGE) "Building environment: ${env}"
@if [ "${env}" == "" ]; then \
docker-compose build --pull --no-cache; \
docker-compose build; \
else \
docker-compose -f docker-compose.yml -f docker-compose/"${env}".yml build --pull --no-cache; \
docker-compose -f docker-compose.yml -f docker-compose/"${env}".yml build; \
fi

docker.down: clean
@echo $(MESSAGE) "Down Services Environment: ${env}"
@if [ "${env}" == "" ]; then \
docker-compose -p "${PROJECT_NAME}" down --remove-orphans; \
docker-compose -p "${PROJECT}" down --remove-orphans; \
else \
docker-compose -f docker-compose.yml -f docker-compose/"${env}".yml down --remove-orphans; \
fi

docker.ssh: clean
docker exec -it $(CONTAINER) bash

docker.status: clean
@echo $(MESSAGE) "status Services: ${env}"
@if [ "${env}" == "" ]; then \
docker-compose -p "${PROJECT}" ps; \
else \
docker-compose -p "${PROJECT}" -f docker-compose.yml -f docker-compose/"${env}".yml ps; \
fi

docker.stop: clean
@echo $(MESSAGE) "Stop Services: ${env}"
@if [ "${env}" == "" ]; then \
docker-compose -p "${PROJECT_NAME}" stop; \
docker-compose -p "${PROJECT}" stop; \
else \
docker-compose -f docker-compose.yml -f docker-compose/"${env}".yml stop; \
fi

docker.cleanup: clean
@echo $(MESSAGE) "Removing dangling docker images...:"
docker images -q --filter 'dangling=true' | xargs docker rmi

docker.verify_network: ## Verify network
@if [ -z $$(docker network ls | grep $(DOCKER_NETWORK) | awk '{print $$2}') ]; then\
(docker network create $(DOCKER_NETWORK));\
Expand All @@ -45,15 +57,15 @@ docker.verify_network: ## Verify network
docker.up: clean
@echo $(MESSAGE) "Up Services: ${env}"
@if [ "${env}" == "" ]; then \
docker-compose -p "${PROJECT_NAME}" up --remove-orphans; \
docker-compose -p "${PROJECT}" up --remove-orphans; \
else \
docker-compose -f docker-compose.yml -f docker-compose/"${env}".yml up --remove-orphans; \
fi

docker.list: clean
@echo $(MESSAGE) "List Services: ${env}"
@if [ "${env}" == "" ]; then \
docker-compose -p "${PROJECT_NAME_DEV}" ps; \
docker-compose -p "${PROJECT_DEV}" ps; \
else \
docker-compose -f docker-compose.yml -f docker-compose/"${env}".yml ps; \
fi
Loading