Skip to content
Merged
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
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git
apt-get install -y git libatomic1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Node wasn't getting successfully installed due to this missing shared dependency, so we're explicitly installing it here and confirming that node is present during the container build.


RUN ["pip", "install", "--no-cache-dir", "setuptools", "cookiecutter"]

# Verify node is working
RUN node -v && npm -v

RUN mkdir /cookiecutter
WORKDIR /cookiecutter
ENTRYPOINT ["cookiecutter"]
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
## Usage

### Option 1: From remote image (recommended)
Run this in whichever parent directory you'd like your project to live in.
```bash
# Build cookiecutter container (Only need to do once)
# Build cookiecutter container to make sure it's up to date
docker build github.com/datamade/cookiecutter-django-app#main -t cookiecutter:latest

# Generate a new project
docker run -it \
docker run --rm -it \
--mount type=bind,source=$(pwd),target=/cookiecutter \
cookiecutter gh:datamade/cookiecutter-django-app
```

### Option 2: From local files
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Useful for when testing local changes

Run this from the parent directory of this repo. Project will be built here.
```bash
# Build cookiecutter container to make sure it's up to date
docker build cookiecutter-django-app -t cookiecutter:latest

# Generate a new project
docker run --rm -it \
--mount type=bind,source=$(pwd),target=/cookiecutter \
cookiecutter cookiecutter-django-app
```

### Notes
In order to make sure tests pass easily on your new repo so you can publish to Heroku, make sure to:
- add all of the cookiecutter output as one initial commit to `main`
Expand Down
12 changes: 12 additions & 0 deletions {{ cookiecutter.project_slug }}/django_module/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.postgres",
{% if cookiecutter.install_wagtail %}"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.contrib.simple_translation",
Expand Down Expand Up @@ -116,6 +117,7 @@

DATABASES = {}

{% if cookiecutter.install_postgis %}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making sure that postgis is only used when asked for

DATABASES["default"] = dj_database_url.parse(
os.getenv(
"DATABASE_URL", "postgis://postgres:postgres@postgres:5432/{{ cookiecutter.module_name }}"
Expand All @@ -124,6 +126,16 @@
ssl_require=True if os.getenv("POSTGRES_REQUIRE_SSL") else False,
engine="django.contrib.gis.db.backends.postgis",
)
{% else %}
DATABASES["default"] = dj_database_url.parse(
os.getenv(
"DATABASE_URL", "postgres://postgres:postgres@postgres:5432/{{ cookiecutter.module_name }}"
),
conn_max_age=600,
ssl_require=True if os.getenv("POSTGRES_REQUIRE_SSL") else False,
engine="django.db.backends.postgresql",
)
{% endif %}

# Caching
# https://docs.djangoproject.com/en/stable/topics/cache/
Expand Down
21 changes: 0 additions & 21 deletions {{ cookiecutter.project_slug }}/django_module/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,6 @@
<!-- Load external scripts -->
<script src="{% static 'js/lib/fontawesome.min.js' %}"></script>

<!-- Matomo -->
<script>
var _paq = (window._paq = window._paq || [])
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["trackPageView"])
_paq.push(["enableLinkTracking"])
;(function () {
var u = "https://datamade.matomo.cloud/"
_paq.push(["setTrackerUrl", u + "matomo.php"])
// replace ZZZ with your site ID
_paq.push(["setSiteId", "ZZZ"])
var d = document,
g = d.createElement("script"),
s = d.getElementsByTagName("script")[0]
g.async = true
g.src = "//cdn.matomo.cloud/datamade.matomo.cloud/matomo.js"
s.parentNode.insertBefore(g, s)
})()
</script>
<!-- End Matomo Code -->

<!-- Load Bootstrap styles and JavaScript -->
{% load render_bundle from webpack_loader %}
{% render_bundle 'bootstrap' js %}
Expand Down
2 changes: 1 addition & 1 deletion {{ cookiecutter.project_slug }}/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ services:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: {{ cookiecutter.module_name }}
volumes:
- {{ cookiecutter.module_name }}-db-data:/var/lib/postgresql/data
- {{ cookiecutter.module_name }}-db-data:/var/lib/postgresql
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got the following error from postgres 18 before this change:

Error: in 18+, these Docker images are configured to store database data in a format which is compatible with "pg_ctlcluster" (specifically, using major-version-specific directory names). This better reflects how PostgreSQL itself works, and how upgrades are to be performed.

See also docker-library/postgres#1259

Counter to that, there appears to be PostgreSQL data in: /var/lib/postgresql/data (unused mount/volume)

This is usually the result of upgrading the Docker image without upgrading the underlying database using "pg_upgrade" (which requires both versions).

The suggested container configuration for 18+ is to place a single mount at /var/lib/postgresql which will then place PostgreSQL data in a subdirectory, allowing usage of "pg_upgrade --link" without mount point boundary issues.

See docker-library/postgres#37 for a (long) discussion around this process, and suggestions for how to do so.

So I've adjusted the location of the volumes as per this suggestion to get things working.

ports:
- 32001:5432

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Migration(migrations.Migration):
dependencies = [
("wagtailcore", "0040_page_draft_title"),
("wagtailcore", "0095_groupsitepermission"),
Copy link
Contributor Author

@xmedr xmedr Jan 12, 2026

Choose a reason for hiding this comment

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

Errored out when first running migrations due to a relation that didn't exist until this wagtail migration ran. So just setting that as the first dependency for our migrations.

]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
class Migration(migrations.Migration):
dependencies = [
("{{ cookiecutter.module_name }}", "0001_initial"),
("wagtailcore", "0094_alter_page_locale"),
]

operations = [
Expand All @@ -17,7 +16,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.AutoField(
models.BigAutoField(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After building the project, there was an immediate warning that a new migration needed to be made, that was just this change.

auto_created=True,
primary_key=True,
serialize=False,
Expand Down