Skip to content

Commit

Permalink
Merge pull request #370 from philgyford/improve-dev-setup
Browse files Browse the repository at this point in the history
Improve dev setup
  • Loading branch information
philgyford committed Nov 18, 2021
2 parents 27ba26a + 3ec854c commit e677849
Show file tree
Hide file tree
Showing 82 changed files with 3,379 additions and 4,927 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git/
__pycache__/
*.pyc
node_modules/
yarn-error.log
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
pipenv run ./manage.py collectstatic --verbosity=0 --noinput
pipenv run ./manage.py migrate --verbosity=0 --noinput
pipenv run flake8 hines
pipenv run black . --check
pipenv run coverage run ./manage.py test
pipenv run coverage report -m
env:
Expand Down
9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.coverage
.env
node_modules
node_modules/
db.sqlite3
htmlcov
static_collected
hines/media/
.vscode
htmlcov/
static_collected/
hines/media/
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"editor.formatOnSave": true,
"files.associations": {
"**/*.html": "html",
"**/templates/**/*.html": "django-html",
"**/templates/**/*": "django-txt"
},
"python.formatting.provider": "black",
"python.pythonPath": "/usr/local/bin/python",
"python.linting.pylintArgs": [
"--load-plugins",
"pylint_django",
"--disable=C0111"
]
}
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
release: python manage.py migrate --noinput
web: scripts/heroku-web
web: python ./manage.py clear_cache && gunicorn config.wsgi --preload
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
"LOCATION": get_env_variable("REDIS_TLS_URL"),
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"CONNECTION_POOL_KWARGS": {
"ssl_cert_reqs": None
},
"CONNECTION_POOL_KWARGS": {"ssl_cert_reqs": None},
},
}
}
Expand Down
6 changes: 3 additions & 3 deletions config/settings/tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from .base import * # noqa: F401, F403


HINES_ROOT_DIR = 'terry'
HINES_ROOT_DIR = "terry"

CACHES = {
'default': {
"default": {
# Use dummy cache (ie, no caching):
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
}
}
15 changes: 15 additions & 0 deletions devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
{
"dockerFile": "docker/web/Dockerfile",
// Mount workdir under /code
"workspaceMount": "src=${localWorkspaceFolder},dst=/code,type=bind,consistency=delegated",
"workspaceFolder": "/code",
// HACK: use node_modules from inside image
"runArgs": ["-v", "/code/node_modules"],
"extensions": [
"ms-python.python",
"sibiraj-s.vscode-scss-formatter",
"esbenp.prettier-vscode",
"batisteo.vscode-django"
]
}
38 changes: 27 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@ version: '3.9'
# For use in development only.

services:
# Postgres
db:
container_name: hines_db
env_file: .env
image: postgres:alpine
ports:
- "5432:5432"
restart: unless-stopped
stop_grace_period: "3s"
volumes:
- postgres_data:/var/lib/postgresql/data/

# Redis
# redis:
# restart: always
# image: sameersbn/redis:4.0.9-2 # Or redis:alpine?
# ports:
# - "6379:6379"
# deploy:
# resources:
# limits:
# # When set to 0 these will use as much as needed:
# cpus: 0
# memory: 0
# container_name: hines_redis
# env_file:
# - ".env"
# image: "redis:6.2.6-bullseye"
# restart: unless-stopped
# stop_grace_period: "3s"
# volumes:
# - ./docker/redis:/var/lib/redis:delegated
# environment:
# - REDIS_PASSWORD=${REDIS_PASSWORD}
# - "redis:/data"

# Application
web:
build:
context: .
Expand All @@ -46,5 +50,17 @@ services:
volumes:
- .:/code

assets:
build:
context: .
dockerfile: ./docker/web/Dockerfile
command: sh -c "yarn && yarn watch"
container_name: hines_assets
volumes:
- .:/code
# HACK: use node_modules from inside image instead of one on local machine
- /code/node_modules

volumes:
postgres_data:
postgres_data:
# redis:
16 changes: 14 additions & 2 deletions docker/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ RUN apk update \
# Required for installing/upgrading postgres:
postgresql-libs postgresql-dev musl-dev \
# Required for installing/upgrading Pillow:
jpeg-dev zlib-dev libjpeg
jpeg-dev zlib-dev libjpeg \
# Because?
postgresql-client \
# For front-end build:
nodejs \
yarn

# set work directory
RUN mkdir /code
Expand All @@ -26,5 +31,12 @@ COPY ./Pipfile .
COPY ./Pipfile.lock .
RUN pipenv install --dev --deploy

# For front-end build:
COPY package.json yarn.lock gulpfile.js /code/
RUN yarn install

# copy project
COPY . /code/
COPY . /code/

# Run gulp to build static assets in image
RUN yarn build
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var autoprefixer = require("gulp-autoprefixer");
* VARIABLES
*/

var SRC_DIR = "hines/static/hines/src";
var SRC_DIR = "assets";
var STATIC_DIR = "hines/static";
var TEMPLATES_DIR = "hines/templates/";
// Removed from the start of CSS/JS paths inserted into files by inject:
Expand Down
44 changes: 34 additions & 10 deletions hines/blocks/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,41 @@

@admin.register(Block)
class BlockAdmin(admin.ModelAdmin):
list_display = ('slug', 'title', 'time_modified',)
search_fields = ('slug', 'title', 'content', )
list_display = (
"slug",
"title",
"time_modified",
)
search_fields = (
"slug",
"title",
"content",
)

fieldsets = (
(None, {
'fields': ('slug', 'title', 'content',)
}),
('Times', {
'classes': ('collapse',),
'fields': ('time_created', 'time_modified',)
}),
(
None,
{
"fields": (
"slug",
"title",
"content",
)
},
),
(
"Times",
{
"classes": ("collapse",),
"fields": (
"time_created",
"time_modified",
),
},
),
)

readonly_fields = ('time_created', 'time_modified', )
readonly_fields = (
"time_created",
"time_modified",
)
7 changes: 3 additions & 4 deletions hines/blocks/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@


class BlockFactory(factory.django.DjangoModelFactory):

class Meta:
model = models.Block

slug = factory.Sequence(lambda n: 'block-%s' % n)
title = factory.Sequence(lambda n: 'Block %s' % n)
content = factory.Sequence(lambda n: 'The content %s.' % n)
slug = factory.Sequence(lambda n: "block-%s" % n)
title = factory.Sequence(lambda n: "Block %s" % n)
content = factory.Sequence(lambda n: "The content %s." % n)
2 changes: 1 addition & 1 deletion hines/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ def core(request):
"settings": {
"comments_close_after_days": app_settings.COMMENTS_CLOSE_AFTER_DAYS,
"comments_allowed": app_settings.COMMENTS_ALLOWED,
}
},
}
2 changes: 1 addition & 1 deletion hines/core/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def item_content(self, item):
return '<b>This is my HTML for content:encoded.</b>'
"""

content_type = 'application/xml; charset=utf-8'
content_type = "application/xml; charset=utf-8"

def rss_attributes(self):
attrs = super().rss_attributes()
Expand Down
9 changes: 5 additions & 4 deletions hines/core/sitemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ class PagesSitemap(Sitemap):
"""
Misc pages not included in other Sitemaps.
"""
changefreq = 'daily'

changefreq = "daily"
priority = 1.0

def items(self):
return [
'home',
'photos:home',
'pinboard:home',
"home",
"photos:home",
"pinboard:home",
]

def location(self, item):
Expand Down
5 changes: 1 addition & 4 deletions hines/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ def markdownify(content, output_format="xhtml"):

return markdown2.markdown(
content,
extras=[
"fenced-code-blocks",
"link-patterns"
],
extras=["fenced-code-blocks", "link-patterns"],
html4tags=(output_format == "html5"),
link_patterns=link_patterns,
)
Expand Down
11 changes: 5 additions & 6 deletions hines/custom_comments/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('django_comments', '0003_add_submit_date_index'),
("django_comments", "0003_add_submit_date_index"),
]

operations = [
migrations.CreateModel(
name='CustomComment',
fields=[
],
name="CustomComment",
fields=[],
options={
'proxy': True,
"proxy": True,
},
bases=('django_comments.comment',),
bases=("django_comments.comment",),
),
]
6 changes: 3 additions & 3 deletions hines/custom_comments/migrations/0002_auto_20170407_1654.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
class Migration(migrations.Migration):

dependencies = [
('custom_comments', '0001_initial'),
("custom_comments", "0001_initial"),
]

operations = [
migrations.AlterModelOptions(
name='customcomment',
options={'verbose_name': 'Comment'},
name="customcomment",
options={"verbose_name": "Comment"},
),
]
2 changes: 0 additions & 2 deletions hines/links/templatetags/links_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

@register.inclusion_tag("links/includes/card_tags.html")
def popular_tags_card(limit=10):
"""
"""
return {
"card_title": "Most-used tags",
"tag_list": popular_bookmark_tags(limit=limit),
Expand Down
1 change: 0 additions & 1 deletion hines/static/hines/js/admin.min.js

This file was deleted.

3 changes: 0 additions & 3 deletions hines/static/hines/js/site-ca2c4da7a1.min.js

This file was deleted.

6 changes: 5 additions & 1 deletion hines/weblogs/migrations/0003_auto_20170331_1658.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RenameField(model_name="post", old_name="user", new_name="author",),
migrations.RenameField(
model_name="post",
old_name="user",
new_name="author",
),
migrations.AlterField(
model_name="post",
name="body_html",
Expand Down
3 changes: 2 additions & 1 deletion hines/weblogs/migrations/0004_auto_20170331_1929.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Migration(migrations.Migration):

operations = [
migrations.AlterModelOptions(
name="post", options={"ordering": ["-time_published", "-time_created"]},
name="post",
options={"ordering": ["-time_published", "-time_created"]},
),
migrations.AlterField(
model_name="post",
Expand Down
3 changes: 2 additions & 1 deletion hines/weblogs/migrations/0012_auto_20170929_1509.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Migration(migrations.Migration):

operations = [
migrations.AlterModelOptions(
name="trackback", options={"ordering": ["-time_created"]},
name="trackback",
options={"ordering": ["-time_created"]},
),
]

0 comments on commit e677849

Please sign in to comment.