Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

Implement empty response #1

Merged
merged 21 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.mypy_cache/
.pytest_cache/
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: minimal

services: docker

install:
- travis_retry make build

script:
- make all-tests
GiancarloFusiello marked this conversation as resolved.
Show resolved Hide resolved

if: |
branch = master OR \
branch =~ /^[0-9\.]+$/ OR \
tag IS present OR \
type = pull_request
3 changes: 1 addition & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Code of conduct
===============
# Code of conduct
GiancarloFusiello marked this conversation as resolved.
Show resolved Hide resolved

The Libero community follows a [code of conduct](https://libero.pub/code-of-conduct).
87 changes: 87 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
PROJECT_CODEBASE_DIR = "search/"
TESTS_DIR = "tests/"
FILES_TO_CHECK = $(PROJECT_CODEBASE_DIR) $(TESTS_DIR)
DOCKER_COMPOSE = docker-compose -f docker/docker-compose.dev.yml

help:
@echo "start - builds and/or starts all services"
@echo "stop - stops all running containers belonging to the project"
@echo "checks - runs static checks such as linting without running unit tests"
@echo "tests - runs unit tests in debug mode (able to use pdb breakpoints)"
@echo "all-tests - runs static checks and unit tests"
@echo "fix-imports - silently modifies imports on all project files that do not"
@echo " adhere to project coding standards regarding imports"
@echo "run - only runs the application service (able to use pdb breakpoints)"
@echo "shell - enter the shell of the application service"
@echo "build - builds the application service"
@echo "---------------------------------------------------------------"
@echo "make build should be run after adding and removing dependencies"
@echo "---------------------------------------------------------------"
@echo "dependency-tree - show dependency tree"
@echo "d-tree - alias for \"dependency-tree\""
@echo "dependency - add or update a python dependency by specifying a package"
@echo " e.g. make dependency package=flask"
@echo " e.g. make dependency package=flask==1.0.2"
@echo "dev-dependency - same as \"dependency\" except the package will be installed"
@echo " during development only"
@echo "remove-dependency - remove a python dependency by specifying a package"
@echo " e.g. make remove-dependency package=flask"
@echo "remove-dev-dependency - same as \"remove-dependency\" regarding development dependencies"

start:
$(DOCKER_COMPOSE) up

stop:
$(DOCKER_COMPOSE) down -v

checks:
$(DOCKER_COMPOSE) run --rm web /bin/bash -c "\
echo \"Running checks...\" && \
echo \"- check for breakpoints\" && \
source scripts/find-breakpoints.sh && \
echo \"- mypy\" && \
mypy $(FILES_TO_CHECK) && \
echo \"- flake8\" && \
flake8 $(FILES_TO_CHECK) && \
echo \"- pylint\" && \
pylint --rcfile=setup.cfg $(FILES_TO_CHECK) && \
echo \"All checks completed\" \
"

.PHONY: tests
tests:
$(DOCKER_COMPOSE) run --rm --service-ports web /bin/bash -c \
"pytest -s --pdbcls=IPython.terminal.debugger:Pdb -vv"

all-tests: checks tests

fix-imports:
$(DOCKER_COMPOSE) run --rm web /bin/bash -c "isort -y"

.PHONY: run
run:
$(DOCKER_COMPOSE) run --rm --service-ports web

shell:
$(DOCKER_COMPOSE) run --rm --service-ports web /bin/bash

build:
$(DOCKER_COMPOSE) build web

dependency-tree:
$(DOCKER_COMPOSE) run --rm web /bin/bash -c "poetry show --tree"

d-tree: dependency-tree # alias for dependency-tree

dependency:
$(DOCKER_COMPOSE) run --rm web /bin/bash -c "poetry add $(package)"

dev-dependency:
$(DOCKER_COMPOSE) run --rm web /bin/bash -c "poetry add $(package) --dev"

remove-dependency:
$(DOCKER_COMPOSE) run --rm web /bin/bash -c "poetry remove $(package)"

remove-dev-dependency:
$(DOCKER_COMPOSE) run --rm web /bin/bash -c "poetry remove $(package) --dev"

99 changes: 95 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,99 @@
Libero search
=============
# Libero Search
This project is an implementation of Libero search API

Getting help
------------
## Dependencies

* [Docker](https://www.docker.com/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And Make?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make is installed everywhere by default. Technically not required but makes running the software locally easier.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Cavaet: My knowledge of Make is pretty much just from Symfony starting to adopt it then stopping.)

Not everywhere; Windows didn't but maybe Windows 10 fixed it with its Linux compatibility? There are different flavours of Make too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem like a strict (optional?) dependency, if the user can still run the docker-compose commands on their own

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could mention that in order to use the commands below gnu make is required. Would that suffice?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the README to include information about gnu make. Please check.


## Getting started
This project provides a `Makefile` with short commands to run common tasks.

```bash
make help
```
Run this for a full list of commands.

```bash
make start
```
This command will build and/or run the site locally configured for development purposes.

```bash
make stop
```
Use this command to stop containers and clean up any anonymous volumes.

## Running the tests
```bash
make tests
```
Use this command to run unit tests.

```bash
make checks
```
Use this command to run static checks such as: mypy, flake8, pylint.

```bash
make all-tests
```
Combines the two commands above by running all checks followed by unit tests

## Adding and removing dependencies

The following commands update files that keep track of project dependencies.
```bash
make build
```
Run this if you would like to persist changes to dependencies to your docker container.

```bash
make dependency package=<package name>
make dev-dependency package=<package name>

# examples:
make dependency package=flask
make dependency package=flask==1.0.2
make dev-dependency package=pytest
```
Run either of these commands to add a python package as a project dependency or
development dependency alike. You can specify just the package name to get the
latest version or specify a specific version number.

```bash
make remove-dependency package=<package name>
make remove-dev-dependency package=<package name>
```
Run either of these commands to remove dependencies accordingly.

## Other useful commands
```bash
make run
```
Use this command to only run the python service.
It is possible to use pdb breakpoints with this configuration.

```bash
make shell
```
Use this to run the python container that would run the application and enter a
bash prompt.

```bash
make dependency-tree
# or
make d-tree
```
Use this to display a dependency tree

```bash
make fix-imports
```
When checks are run warnings are displayed because imports do not follow the
project conventions as specified in `setup.cfg` under `[isort]`.
Use this command to automatically fix imports for all project python files.

## Getting help

- Report a bug or request a feature on [GitHub](https://github.com/libero/libero/issues/new/choose).
- Ask a question on the [Libero Community Slack](https://libero.pub/join-slack).
Expand Down
25 changes: 25 additions & 0 deletions docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM python:3.7.2-alpine3.8

ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PATH "/root/.poetry/bin:$PATH"

WORKDIR /srv/app

COPY ./pyproject.toml ./
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can probably merge these two COPY into one (it's like cp)

COPY ./poetry.lock ./
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple files can be done in one COPY.


RUN apk add --no-cache \
GiancarloFusiello marked this conversation as resolved.
Show resolved Hide resolved
bash \
grep \
libxslt-dev \
&& \
apk add --no-cache --virtual .build-deps \
curl \
gcc \
musl-dev \
&& \
curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python && \
poetry config settings.virtualenvs.create false && \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can probably push poetry config up too when it is installed? Very minor

poetry install && \
apk del .build-deps
2 changes: 2 additions & 0 deletions docker/dev.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FLASK_APP=search
FLASK_ENV=development
15 changes: 15 additions & 0 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'

services:
web:
build:
context: ..
dockerfile: docker/Dockerfile.dev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading this correctly, all of these images will be created when referencing this file. Is that correct? I don't see the advantage of having everything in one file. Could you explain please?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could leave the test and prod image for later when we setup a pipeline

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Was just bit concerned that this looked like it would be a dev-only container.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is at the moment (doesn't have the code), but it should be transformed into a prod container derivative as soon as the prod container image is there

working_dir: /srv/app
volumes:
- ..:/srv/app
command: "flask run --host=0.0.0.0"
ports:
- "5000:5000"
env_file:
- dev.env
Loading