Skip to content

Commit

Permalink
ADD base structure && CD/CD && deployment with k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgechato committed Apr 2, 2019
1 parent e3ad5e7 commit 831e302
Show file tree
Hide file tree
Showing 11 changed files with 468 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/*.pyc
.DS_Store
**/*_tests.py
**/__pycache__/
178 changes: 178 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
tensorflow/

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# celery
*.db

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject

**/*.pyc
**/migrations/*
media
static
compass/.sass-cache
**/local_settings.py
**/*.swp

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see
http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

#intellij
Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion,
Android Studio and Webstorm

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

.vscode

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Keras output
/data/
/output/
/out/
43 changes: 43 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
dist: trusty
sudo: required
language: python
python:
- "3.6"
sudo: true
services:
- docker
env:
global:
- IMAGE_NAME=jorgechato/word-search-engine

notifications:
email: false


before_install:
- docker login -u "$REGISTRY_USER" -p "$REGISTRY_PASS"
- docker pull "$IMAGE_NAME" || true

install:
- pip install -Ur src/requirements.txt

script:
- echo "Running tests"
# # TODO: add specific test files
# - python src/api/**/*_tests.py -v

after_success:
- docker build --pull --cache-from "$IMAGE_NAME" --tag "$IMAGE_NAME" .

before_deploy:
- docker tag "$IMAGE_NAME" "${IMAGE_NAME}:latest"

deploy:
provider: script
script: docker push "${IMAGE_NAME}:latest"
target-branch: master
on:
branch: master

after_script:
- docker images
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.7-alpine

ENV PYTHONUNBUFFERED 1
ENV FLASK_DEBUG false
ENV FLASK_APP /code/app

WORKDIR /code
COPY /src /code

# Install our requirements.
RUN pip install -U pip
RUN pip install -Ur requirements.txt

EXPOSE 8000

ENTRYPOINT flask run -h 0.0.0.0 -p $PORT
91 changes: 89 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Word search engine
[![Build Status](https://travis-ci.com/jorgechato/word-search-engine.svg?token=x3vLcsQVEzf1kfJyx1Uv&branch=master)](https://travis-ci.com/jorgechato/word-search-engine)
[![Docker](https://img.shields.io/badge/docker-image-blue.svg)](https://hub.docker.com/r/jorgechato/word-search-engine)

Input:

Expand All @@ -15,19 +17,104 @@ Constrains:

## Architecture

TODO: architecture

## API

Swagger file
TODO: Swagger file

## Run

```bash
$ FLASK_APP=src/app flask run
# or
$ python src/app.py
```

## Deploy

The deployment is automated by the CI/CD pipeline but you can always run it in
your local machine.

```bash
# Build docker
$ docker build -t word-search-engine:latest .
$ docker run -p 8000:8000 -e PORT=8000 --name word-search-engine word-search-engine:latest
```

Pull the latest version from [hub.docker](https://hub.docker.com/r/jorgechato/word-search-engine) from any machine with docker installed on it.
You can automate the process with Terraform, and a CI/CD pipeline if you are
using ECS or create a deploy/rollback in K8s

```bash
$ docker pull jorgechato/word-search-engine:latest
# example with k8s
# do not forget to export the ENV_VARIABLES for the DB connection first
$ kubectl apply -f deploy/k8s.yml
```

---

## Requirements

### Must have

- [python 3.x](https://www.python.org/downloads/)
- pip3

### Recommendation for development

- [anaconda](https://anaconda.org/anaconda/python)

#### Install dependencies

```bash
# with anaconda
$ conda env create -f environment.yml # create virtual environment
$ conda activate backend # enter VE
# or
$ source activate backend
(backend) $ conda deactivate # exit VE
```

---

## FAQ

**Can the word be part of any html tag, css or js embedded in the source code of
the page?**

See also:

* [business] MVP Questions ([#1][i1])

**Does the scrapping search take place in the hole site-map of the domain?**

**How does it work?**
No, the search engine only search in the endpoint provided by the requester.

**Why K8S and not AWS lambdas?**

**P 1**: When using Serverless platforms the first invocation of a function takes
some time since the code needs to be initialized. In this case we will need a fast
response since this service will be integrated with a stack of MS.

**P 2**: Kubernetes might provide better scalability features than some Serverless
platforms, since Kubernetes is more mature and provides even HA (high availability)
between different zones which not all Serverless platforms provide yet.
And we plan to expand our business to different zones.


**P 3**: it might be easier to use Kubernetes for more complex applications because
the platform is more mature. And since we are planning to use a database to
store the outcome of the logic, that make sense.


**P 4**: Serverless doesn’t automatically mean lower costs, like when your
applications need to run 24/7. There can also be some hidden costs like extra
costs for API management or the costs for the function invocations for tests.

**P 5**: The monitoring capabilities of Kubernetes applications are much more
mature.


[i1]: https://github.com/jorgechato/word-search-engine/issues/1

0 comments on commit 831e302

Please sign in to comment.