Skip to content

Commit

Permalink
Upgrade build
Browse files Browse the repository at this point in the history
- Upgrade to Python3.8 as the minimal supported
- Upgrade actions to test Python 3.8+
- Copy Makefile from other projects
- Upgrade to use pip-compile workflow
- Use django-zakka for celery compatiblity
  • Loading branch information
kfdm committed May 4, 2023
1 parent f3aa263 commit 14bee9f
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 92 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: "weekly"
11 changes: 7 additions & 4 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ jobs:
--health-retries 5
strategy:
fail-fast: false
matrix:
python-version: ["3.6", "3.7", "3.8"]
# https://endoflife.date/python
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
Expand All @@ -56,9 +58,10 @@ jobs:
path: ~/.cache/pip
key: ${{ hashFiles('setup.cfg') }}-${{ hashFiles('docker/requirements.txt') }}

- name: Run tests
run: make test
env:
- name: Run Tests
run: make test
env:
SYSTEM_PYTHON: python${{ matrix.python-version }}
SECRET_KEY: github-actions
DATABASE_URL: postgres://postgres:postgres@localhost/${{ matrix.python-version }}
CELERY_BROKER_URL: redis://localhost:6379/0
14 changes: 8 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.6-alpine
FROM python:3.9-alpine
LABEL maintainer=kungfudiscomonkey@gmail.com

ENV PYTHONDONTWRITEBYTECODE 1
Expand All @@ -22,15 +22,17 @@ RUN set -ex \
RUN set -ex \
&& apk add --no-cache jpeg-dev zlib-dev \
&& apk add --no-cache --virtual build-deps build-base \
&& pip install --no-cache-dir Pillow==6.2.2 \
&& pip install --no-cache-dir Pillow \
&& apk del build-deps

# Finish installing app
WORKDIR ${APP_DIR}
ADD quickstats ${APP_DIR}/quickstats
ADD docker ${APP_DIR}/docker
ADD setup.py ${APP_DIR}/setup.py
RUN set -ex && pip install --no-cache-dir -r ${APP_DIR}/docker/requirements.txt
COPY quickstats ${APP_DIR}/quickstats
COPY docker ${APP_DIR}/docker
COPY setup.* ${APP_DIR}/
RUN pip install --no-cache-dir \
-r ${APP_DIR}/docker/requirements.txt \
-e .[standalone]
RUN SECRET_KEY=1 quickstats collectstatic --noinput
USER nobody
EXPOSE 8000
Expand Down
141 changes: 102 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,45 +1,108 @@
APP_BIN := .venv/bin/quickstats
PIP_BIN := .venv/bin/pip
PKG_NAME = quickstats
CLI_NAME = quickstats
PKG_OPTS = .[standalone,dev]

SYSTEM_PYTHON ?= python3.9
VENV_PATH := .venv
APP_BIN := $(VENV_PATH)/bin/$(CLI_NAME)
PIP_BIN := $(VENV_PATH)/bin/pip

# Help 'function' taken from
# https://gist.github.com/prwhite/8168133#gistcomment-2278355
lessopts="--tabs=4 --quit-if-one-screen --RAW-CONTROL-CHARS --no-init"

# COLORS
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)

TARGET_MAX_CHAR_NUM=20
.PHONY: help
## Show help
help:
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[\%a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)

.PHONY: test
test: ${APP_BIN}
${APP_BIN} test -v 2

###############################################################################
### Pip Tasks
###############################################################################
PIPDEPTREE := $(VENV_PATH)/bin/pipdeptree
PIP_COMPILE := $(VENV_PATH)/bin/pip-compile

$(PIP_BIN):
python3 -m venv .venv
$(SYSTEM_PYTHON) -m venv $(VENV_PATH)

${APP_BIN}: $(PIP_BIN)
$(PIP_BIN) install pip -U
${PIP_BIN} install -r docker/requirements.txt
${PIP_BIN} install -e .[dev,standalone]
$(APP_BIN): $(PIP_BIN)
$(PIP_BIN) install -r docker/requirements.txt -e $(PKG_OPTS)

.PHONY: pip
.PHONY: pip
## Pip: Reinstall into our virtual env
pip: $(PIP_BIN)
$(PIP_BIN) install pip -U
${PIP_BIN} install -r docker/requirements.txt
${PIP_BIN} install -e .[dev,standalone]

# Django and Python Commands

.PHONY: migrate
migrate: ${APP_BIN}
${APP_BIN} migrate
.PHONY: run
run: migrate
${APP_BIN} runserver
.PHONY: shell
shell: migrate
${APP_BIN} shell
.PHONY: clean
clean:
rm -rf .venv

# Docker and Release
.PHONY: build
build:
docker-compose build

.PHONY: release
release: ${PIP_BIN}
${PYTHON_BIN} setup.py sdist
twine check dist/*
$(PIP_BIN) install --upgrade pip setuptools wheel
$(PIP_BIN) install -r docker/requirements.txt -e $(PKG_OPTS)

.PHONY: outdated
## Pip: Show outdated dependencies
outdated: $(PIP_BIN)
$(PIP_BIN) list --outdated

$(PIPDEPTREE): $(PIP_BIN)
$(PIP_BIN) install pipdeptree

.PHONY: deps
## Pip: Show dependencies for our package
deps: $(PIPDEPTREE)
$(PIPDEPTREE) -p $(PKG_NAME)

$(PIP_COMPILE): $(PIP_BIN)
$(PIP_BIN) install pip-tools

docker/requirements.txt: $(PIP_COMPILE) setup.py setup.cfg docker/requirements.in
$(PIP_COMPILE) --extra=standalone --output-file docker/requirements.txt setup.py docker/requirements.in --no-emit-index-url

.PHONY: compile
## Pip: Compile requirements
compile: docker/requirements.txt


###############################################################################
### Docker Tasks
###############################################################################

.PHONY: build
## Docker: Build docker container
build: docker/requirements.txt
docker build . --tag test

###############################################################################
### Django Tasks
###############################################################################

.PHONY: web
## Django: Launch runserver for testing
web: $(APP_BIN)
$(APP_BIN) runserver 9000

.PHONY: shell
## Django: Open Python shell
shell: $(APP_BIN)
$(APP_BIN) shell

.PHONY: test
## Django: Run tests
test: $(APP_BIN)
$(APP_BIN) test -v2
4 changes: 4 additions & 0 deletions docker/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
django~=3.2
gunicorn
sentry-sdk
whitenoise
140 changes: 118 additions & 22 deletions docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,119 @@
-i https://pypi.org/simple
-e .[standalone]
celery[redis]==4.3.0
certifi==2019.3.9
chardet==3.0.4
django-environ==0.4.5
django==2.2.24
djangorestframework-csv==2.1.0
djangorestframework==3.11.2
gunicorn
idna==2.8
Pillow==8.2.0
prometheus-client==0.7.0
python-dateutil==2.8.0
pytz==2021.1
redis
requests==2.26.0
six==1.12.0
sqlparse==0.3.0
#
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --extra=standalone --no-emit-index-url --output-file=docker/requirements.txt docker/requirements.in setup.py
#
amqp==5.1.1
# via kombu
asgiref==3.6.0
# via django
async-timeout==4.0.2
# via redis
billiard==3.6.4.0
# via celery
celery[redis]==5.2.7
# via quickstats-django (setup.py)
certifi==2022.12.7
# via
# requests
# sentry-sdk
charset-normalizer==3.1.0
# via requests
click==8.1.3
# via
# celery
# click-didyoumean
# click-plugins
# click-repl
click-didyoumean==0.3.0
# via celery
click-plugins==1.1.1
# via celery
click-repl==0.2.0
# via celery
django==3.2.19
# via
# -r docker/requirements.in
# django-filter
# django-zakka
# djangorestframework
# drf-nested-routers
# quickstats-django (setup.py)
django-environ==0.10.0
# via quickstats-django (setup.py)
django-filter==23.2
# via quickstats-django (setup.py)
django-zakka==0.5.2
# via quickstats-django (setup.py)
djangorestframework==3.14.0
# via
# djangorestframework-csv
# drf-nested-routers
# quickstats-django (setup.py)
djangorestframework-csv==2.1.1
# via quickstats-django (setup.py)
drf-nested-routers==0.93.4
# via quickstats-django (setup.py)
gunicorn==20.1.0
# via -r docker/requirements.in
icalendar==5.0.5
# via quickstats-django (setup.py)
idna==3.4
# via requests
importlib-metadata==6.6.0 ; python_version < "3.10"
# via quickstats-django (setup.py)
kombu==5.2.4
# via celery
pillow==9.5.0
# via quickstats-django (setup.py)
prometheus-client==0.16.0
# via quickstats-django (setup.py)
prompt-toolkit==3.0.38
# via click-repl
python-dateutil==2.8.2
# via
# icalendar
# quickstats-django (setup.py)
pytz==2023.3
# via
# celery
# django
# djangorestframework
# icalendar
# quickstats-django (setup.py)
redis==4.5.4
# via celery
requests==2.29.0
# via quickstats-django (setup.py)
sentry-sdk==1.21.1
# via
# -r docker/requirements.in
# quickstats-django (setup.py)
six==1.16.0
# via
# click-repl
# djangorestframework-csv
# python-dateutil
sqlparse==0.4.4
# via django
unicodecsv==0.14.1
urllib3==1.26.6
vine==1.3.0
whitenoise
# via djangorestframework-csv
urllib3==1.26.15
# via
# requests
# sentry-sdk
vine==5.0.0
# via
# amqp
# celery
# kombu
wcwidth==0.2.6
# via prompt-toolkit
whitenoise==6.4.0
# via -r docker/requirements.in
zipp==3.15.0
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# setuptools
2 changes: 1 addition & 1 deletion quickstats/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import requests
from celery import shared_task
from celery.decorators import periodic_task
from celery.schedules import crontab
from zakka.contrib.celery.decorators import periodic_task

from . import models

Expand Down
Loading

0 comments on commit 14bee9f

Please sign in to comment.