Skip to content

Commit

Permalink
Upgrade dependencies, fix docker setup, cleanup frontend.
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWorkman committed Jan 22, 2020
1 parent 3490f97 commit 69467f1
Show file tree
Hide file tree
Showing 47 changed files with 1,528 additions and 490 deletions.
29 changes: 29 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# https://editorconfig.org
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{md,rst,txt}]
indent_style = space
indent_size = 4

[*.{ini,toml}]
indent_style = space
indent_size = 4

[*.{js,json,yml,yaml}]
indent_style = space
indent_size = 2

[*.{css,py,scss,html}]
indent_size = 4
indent_style = space

[*.md]
trim_trailing_whitespace = false
32 changes: 27 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# general things to ignore
build/
dist/
# dist/
*.egg-info/
*.egg
*.py[cod]
Expand All @@ -23,15 +23,37 @@ __pycache__
/node_modules

# project dist static files
/static/
/media/
/static
media
/finder/static/assets

.vscode
# project secrets
.env

# due to ansible logs
*.log
*.retry

# local db backups
backups/
# background process stuff
nohup.out

# Ignore data dumps
fixtures/
initial_data.dump

# ignore scraper things
# Google Scraper specific
Drivers/chromedriver
Drivers/geckodriver
Private/
keywords.txt
out.csv
# cache for GoogleScraper testings
.scrapecache/
*.db
/results
*.log


#
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
FROM python:3.6.10-buster
LABEL Nathan Workman <nathancworkman@gmail.com>

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN apt-get update && apt-get -y upgrade && apt-get install -y sudo
RUN apt-get install -y git apt-utils build-essential

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . .

RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 8000
205 changes: 145 additions & 60 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,99 +2,102 @@ PROJECT_NAME = seeker
SHELL := /bin/sh
help:
@echo "Please use 'make <target>' where <target> is one of"
@echo " reset Complete reset of database and migrations (Be Careful)"
@echo " migrate Run Django migrations"
@echo " migrations Create Django migrations"
@echo " user Create user account"
@echo " clean Remove all *.pyc, .DS_Store and temp files from the project"
@echo " collectstatic Collect static assets"
@echo " run Run Django Server"
@echo " crawl_spider <spidername> Run Scrapy Spider"
@echo " crawl Run ALL Scrapy Spiders"
@echo " dump Create database dump/backup"
@echo "migrate Run database migrations"
@echo "collectstatic Collect static assets"


.PHONY: requirements


# Command variables
COMPOSE = docker-compose
COMPOSE_CMD = exec app python manage.py
MANAGE_CMD = python manage.py
PIP_INSTALL_CMD = pip install
PLAYBOOK = ansible-playbook
VIRTUALENV_NAME = venv
APP_NAME = seeker

# Helper functions to display messagse
ECHO_BLUE = @echo "\033[33;34m $1\033[0m"
ECHO_RED = @echo "\033[33;31m $1\033[0m"
ECHO_GREEN = @echo "\033[33;32m $1\033[0m"
DATE= `date +'%m_%d_%y'`

# The default server host local development
HOST ?= localhost:8000

reset: dropdb createdb migrations migrate user run

migrate:
# Run django migrations
# Run django migrations inside docker
$(call ECHO_GREEN, Running migrations... )
( \
$(MANAGE_CMD) migrate; \
$(COMPOSE) $(COMPOSE_CMD) migrate --no-input; \
)

user:
# Create user account
$(call ECHO_GREEN, Creating super user... )
collectstatic:
# Run django migrations inside docker
$(call ECHO_GREEN, Collect static assets... )
( \
echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@email.com', 'pass')" | ./manage.py shell; \
$(COMPOSE) $(COMPOSE_CMD) collectstatic --no-input; \
)

test:
# Run the test cases
migrations:
# Run django migrations inside docker
$(call ECHO_GREEN, Create new database migrations... )
( \
$(MANAGE_CMD) test; \
$(COMPOSE) $(COMPOSE_CMD) makemigrations; \
)

clean:
# Remove all *.pyc, .DS_Store and temp files from the project
$(call ECHO_BLUE,removing .pyc files...)
@find . -name '*.pyc' -exec rm -f {} \;
$(call ECHO_BLUE,removing static files...)
@rm -rf $(PROJECT_NAME)/_static/
$(call ECHO_BLUE,removing temp files...)
@rm -rf $(PROJECT_NAME)/_tmp/
$(call ECHO_BLUE,removing .DS_Store files...)
@find . -name '.DS_Store' -exec rm {} \;

shell:
# Run a local shell for debugging
build:
# Run django migrations inside docker
$(call ECHO_GREEN, Building new images... )
( \
$(MANAGE_CMD) shell_plus; \
$(COMPOSE) build; \
)

migrations:
# Create database migrations
down:
# Run django migrations inside docker
$(call ECHO_GREEN, Tear down containers... )
( \
$(MANAGE_CMD) makemigrations; \
$(COMPOSE) down; \
)

collectstatic:
# Collect static assets
$(call ECHO_GREEN, Collecting static assets...)
up:
# Run django migrations inside docker
$(call ECHO_GREEN, Launching starship... )
( \
$(MANAGE_CMD) collectstatic; \
$(COMPOSE) up; \
)

visual:
# Generate visual representation of database
$(call ECHO_GREEN, Generating a pretty image...)
(\
$(COMPOSE) $(COMPOSE_CMD) graph_models --pygraphviz -a -g -o visualized.png; \
)

dumpdata:
# Dump database to fixture file
$(call ECHO_RED, Database dump...)
(\
$(COMPOSE) $(COMPOSE_CMD) dumpdata --exclude auth.permission --exclude contenttypes > ./initial_data.json; \
)

run:
# run django server
$(call ECHO_GREEN, Starting Django Server...)
shell:
# Run a local shell for debugging
$(call ECHO_GREEN, Opening iPython shell...)
( \
$(MANAGE_CMD) runserver 0.0.0.0:8300 ; \
$(COMPOSE) $(COMPOSE_CMD) shell; \
)


crawl:


######################
# OLD
######################

r_crawl:
# Run ALL scrapy spiders
$(call ECHO_GREEN, Running spiders... )
$(call ECHO_GREEN, Running Spiders Background Process... )
(\
python seeker/crawl.py; \
cd recognition; \
nohup python crawl.py & \
)

crawl_spider:
Expand All @@ -104,17 +107,99 @@ crawl_spider:
scrapy crawl $(spider); \
)

createdb:
r_crawl_spider:
# Run scrapy spider
$(call ECHO_GREEN, Running $(spider) spider as background process... )
(\
nohup scrapy crawl $(spider) & \
)

delete_sqlite:
# delete project db
( \
createdb -p 5433 $(APP_NAME); \
rm -rf db.sqlite3;\
)

dropdb:
reset_migrations:
# delete all migrations furing initial development
( \
dropdb -p 5433 $(APP_NAME);\
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete; \
find . -path "*/migrations/*.pyc" -delete; \
)

dump:
map_points:
( \
pg_dump -Fc seeker -p 5433 > backups/data_dump_$(DATE).dump; \
python manage.py plot_lng_lat;\
)

r_map_points:
( \=
nohup python manage.py plot_lng_lat & \
)

validate_urls:
( \
python manage.py valid_url;\
)

r_validate_urls:
( \
nohup python manage.py valid_url & \
)

find_contacts:
( \
nohup python manage.py find_contacts & \
)

map_locations:
( \
nohup python manage.py plot_lng_lat & \
)

rank:
# Start ranking centers
(\
python manage.py rank; \
)

r_rank:
# Start ranking centers
(\
nohup python manage.py rank & \
)

sql_dump:
# dump to fixtures file
(\
rm -rf recognition/fixtures/dump.json; \
./manage.py dumpdata --natural-primary --natural-foreign > fixtures/dump.json ; \
)


initial_data:
# load initial db data
( \
pg_restore -p 5433 -d recognition --verbose initial_data.dump; \
)

r_initial_data:
# load initial db data in vm
( \
sudo -u postgres pg_restore -p 5433 -d recognition --verbose initial_data.dump; \
)


createuser:

# docker exec -it seeker_app echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@email.com', 'pass')" | ./manage.py shell;
( \
docker exec -it seeker_app python manage.py createsuperuser
)



# docker exec -it seeker_app python manage.py createsuperuser


# echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@email.com', 'pass')" | ./manage.py shell;
Loading

0 comments on commit 69467f1

Please sign in to comment.