Skip to content

templatedir is pathlib.PosixPath #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/*.sqlite3
docker
buildspec.yml
.mypy_cache
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ docs/_build
.tox/
*.egg/
.coverage
.env
codebuild_build.sh
30 changes: 30 additions & 0 deletions buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: 0.2
env:
shell: bash
phases:
pre_build:
on-failure: ABORT
commands:
- echo "pre_build"
finally:
- echo "CODEBUILD_BUILD_SUCCEEDING is $CODEBUILD_BUILD_SUCCEEDING"
build:
on-failure: ABORT
commands:
- echo "do some testing. ${BUILD_DOCKER}"
- BUILD_DOCKER=true

post_build:
on-failure: ABORT
commands:
- |
if [ "${BUILD_DOCKER}" = "true" ]; then
SRC_IMAGES=($APPBASE_IMAGE $BUILDBASE_IMAGE)
for SRC_IMAGE in "${SRC_IMAGES[@]}"; do
ECR=$(aws ecr describe-repositories --repository-names $SRC_IMAGE | jq -r ".repositories[0].repositoryUri")
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR
docker build -t $SRC_IMAGE --platform $PLATFORM --build-arg BASE_IMAGE=$ECR --build-arg TAG=$TAG --no-cache -f docker/Dockerfile .
docker tag ${SRC_IMAGE}:${TAG} ${ECR}:${TAG}
docker push ${ECR}:${TAG}
done
fi
5 changes: 3 additions & 2 deletions dbtemplates/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@


class DBTemplatesConfig(AppConfig):
name = 'dbtemplates'
verbose_name = _('Database templates')
name = "dbtemplates"
verbose_name = _("Database templates")
default_auto_field = "django.db.models.AutoField"
3 changes: 1 addition & 2 deletions dbtemplates/management/commands/sync_templates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import io
import os
import sys
from django.contrib.sites.models import Site
from django.core.management.base import CommandError, BaseCommand
from django.template.utils import get_app_template_dirs
Expand Down Expand Up @@ -77,7 +76,7 @@ def handle(self, **options):
for f in [f for f in filenames
if f.endswith(extension) and not f.startswith(".")]:
path = os.path.join(dirpath, f)
name = path.split(templatedir)[1]
name = path.split(str(templatedir))[1]
if name.startswith('/'):
name = name[1:]
try:
Expand Down
17 changes: 3 additions & 14 deletions dbtemplates/utils/cache.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
from django.core import signals
from django.contrib.sites.models import Site
from django.template.defaultfilters import slugify

from dbtemplates.conf import settings


def get_cache_backend():
"""
Compatibilty wrapper for getting Django's cache backend instance
"""
from django.core.cache import _create_cache
cache = _create_cache(settings.DBTEMPLATES_CACHE_BACKEND)
# Some caches -- python-memcached in particular -- need to do a cleanup at
# the end of a request cycle. If not implemented in a particular backend
# cache.close is a no-op
signals.request_finished.connect(cache.close)
from django.core.cache import cache
return cache


Expand All @@ -23,11 +12,11 @@ def get_cache_backend():

def get_cache_key(name):
current_site = Site.objects.get_current()
return 'dbtemplates::%s::%s' % (slugify(name), current_site.pk)
return "dbtemplates::%s::%s" % (slugify(name), current_site.pk)


def get_cache_notfound_key(name):
return get_cache_key(name) + '::notfound'
return get_cache_key(name) + "::notfound"


def remove_notfound_key(instance):
Expand Down
15 changes: 15 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG BASE_IMAGE=python
ARG TAG=3.10.4
FROM ${BASE_IMAGE}:${TAG} as server

ENV APP_BASE=/usr/src/app \
LIB_BASE=/usr/src/lib \
POETRY_VERSION=1.0.10 \
NAME=django-dbtemplates \
PATH="/root/.poetry/bin:$PATH"

WORKDIR ${LIB_BASE}/${NAME}
COPY . ${LIB_BASE}/${NAME}
RUN pip install -e .

CMD ["sleep", "infinity"]
32 changes: 32 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Docker Build

~~~bash
docker build -t $APPBASE_IMAGE --platform $PLATFORM --build-arg BASE_IMAGE=$APPBASE_IMAGE --build-arg TAG=$TAG --no-cache -f docker/Dockerfile .
docker build -t $BUILDBASE_IMAGE --platform $PLATFORM --build-arg BASE_IMAGE=$BUILDBASE_IMAGE --build-arg TAG=$TAG --no-cache -f docker/Dockerfile .
~~~


## CodeBuild Test

### Install

~~~bash
$ # docker pull public.ecr.aws/codebuild/amazonlinux2-x86_64-standard:3.0
$ docker pull public.ecr.aws/codebuild/standard:5.0
$ docker pull public.ecr.aws/codebuild/local-builds:latest
~~~

~~~bash
$ wget https://raw.githubusercontent.com/aws/aws-codebuild-docker-images/master/local_builds/codebuild_build.sh
$ chmod +x codebuild_build.sh
~~~


### Exec

~~~bash
export CODEBUILD_RUNNER=public.ecr.aws/codebuild/amazonlinux2-x86_64-standard:3.0
export PLATFORM=linux/amd64
#
./codebuild_build.sh -c -i $CODEBUILD_RUNNER -a /tmp/artifacts -e .env
~~~