Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2453c62
initial terraform setup
zags Oct 21, 2024
75c4530
draft of ecs
zags Oct 21, 2024
5d919e4
fix
kyfantaz Oct 21, 2024
25388ed
adds rds
zags Oct 21, 2024
2ee4d27
Merge branch 'ecs' of github.com:zagaran/sample-django-app into ecs
zags Oct 21, 2024
697a65b
fix
kyfantaz Oct 21, 2024
c6b2cd2
adds iam config
zags Oct 21, 2024
9d17f36
adds ecs config
zags Oct 21, 2024
0cab76f
fix
kyfantaz Oct 21, 2024
c3755f1
adds alb config
zags Oct 21, 2024
4230026
Merge branch 'ecs' of github.com:zagaran/sample-django-app into ecs
zags Oct 21, 2024
d83557a
converts to per-env main.tf files
zags Oct 21, 2024
ac3f519
fixes
zags Oct 21, 2024
af1c80b
adds readme entry
zags Oct 21, 2024
b9cb306
fix Dockerfile
kyfantaz Oct 21, 2024
1cb5027
adds terraform to gitignore
zags Oct 21, 2024
b5b1fd1
cleanup
zags Oct 21, 2024
3f01245
fixes and refactor; adds outputs
kyfantaz Oct 22, 2024
cdd82b5
adds other secrets
kyfantaz Oct 23, 2024
6bacba9
fix
kyfantaz Oct 23, 2024
ff92b92
adds application name to main.tf
zags Oct 24, 2024
b7eb6dc
fixes several issues with ECS deployment
zags Oct 24, 2024
cfc6a0d
readme
zags Oct 24, 2024
5573372
Dockerfile fixes; adds .env for build purposes
kyfantaz Oct 28, 2024
a0a7346
change 8000->8080 port, matching terraform
kyfantaz Oct 30, 2024
f2f42e9
edits dockerfile; adds docker-compose.yml as option
kyfantaz Oct 31, 2024
e5d39c6
adds whitenoise
zags Oct 31, 2024
2753a6b
Changes secrets to be dynamic, updates names to {app}-{env}
zags Nov 4, 2024
dd00f89
updates readme
zags Nov 4, 2024
7536ef2
Add deployment script
gracewhitney Nov 7, 2024
f79deee
Autogenerate ECR URI and fixes to image tag copy
gracewhitney Nov 8, 2024
69c9021
Add skip logging
gracewhitney Nov 8, 2024
6e012ec
Add use-latest option, update README
gracewhitney Nov 8, 2024
786b795
Update static storage setting
gracewhitney Nov 8, 2024
95d7310
Add ssh script
gracewhitney Nov 8, 2024
016f20e
Wait for deployment to finish
gracewhitney Nov 8, 2024
f0b862f
Cleanup
gracewhitney Nov 8, 2024
5cf77fb
Update prod main.tf and add cloudwatch url
gracewhitney Nov 12, 2024
2a81a6d
updates SES permissions
zags Feb 18, 2025
70d1c85
fix
zags Feb 18, 2025
800afaa
adds subnet group to database, vpc to security groups, and adds docs
zags Mar 13, 2025
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
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@

# Operating system metafiles
.DS_Store

# Local build artifacts
node_modules/
media/
staticfiles/

# Deployment configuration
terraform/
deploy.py
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ staticfiles/*
static/webpack_bundles/
webpack-stats.json
# END_FEATURE django_react

.terraform.lock.hcl
.terraform/
52 changes: 39 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,62 @@
# START_FEATURE docker
FROM python:3.11.4-slim-buster

WORKDIR /app
# reduces file creation
ENV PYTHONDONTWRITEBYTECODE=1
# disables output buffering so logs are flushed to console
ENV PYTHONUNBUFFERED=1

ADD requirements.txt /app/requirements.txt
# Set container working directory
WORKDIR /app

RUN set -ex \
&& buildDeps=" \
build-essential \
libpq-dev \
" \
&& deps=" \
curl \
vim \
nano \
procps \
postgresql-client \
" \
&& apt-get update && apt-get install -y $buildDeps $deps --no-install-recommends \
&& pip install --no-cache-dir -r /app/requirements.txt \
&& apt-get purge -y --auto-remove $buildDeps \
&& apt update && apt install -y $buildDeps $deps --no-install-recommends


# Install python dependencies
ADD requirements.txt /app/requirements.txt
RUN set -ex \
&& pip install --no-cache-dir -r /app/requirements.txt

# Cleanup installs
RUN set -ex \
&& apt purge -y --auto-remove $buildDeps \
$(! command -v gpg > /dev/null || echo 'gnupg dirmngr') \
&& rm -rf /var/lib/apt/lists/*


ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH

# Copy project files into the container
COPY . /app/
# Add temporary copy of env file to allow running management commands
COPY ./config/.env.build /app/config/.env

# LTS Version of Node is 22
ARG NODE_VERSION=22

# START_FEATURE django_react
COPY ./nwb.config.js /app/nwb.config.js
COPY ./package.json /app/package.json
COPY ./package-lock.json /app/package-lock.json
RUN npm install
# if using nwb, nwb requires Node 16. TODO remove nwb
ARG NODE_VERSION=16
# END_FEATURE django_react

COPY . /app/
COPY ./config/.env.example /app/config/.env
# install node
RUN curl -fsSL https://deb.nodesource.com/setup_{$NODE_VERSION}.x | bash -
RUN apt-get update && apt install nodejs -y

RUN npm install

# START_FEATURE django_react
RUN ./node_modules/.bin/nwb build --no-vendor
Expand All @@ -44,7 +70,7 @@ RUN python manage.py collectstatic --noinput

RUN rm /app/config/.env

EXPOSE 8000
EXPOSE 8080

CMD ["gunicorn", "--bind", ":8000", "--workers", "3", "config.wsgi:application"]
CMD ["gunicorn", "--bind", ":8080", "--workers", "3", "config.wsgi:application", "--access-logfile", "-", "--error-logfile", "-"]
# END_FEATURE docker
11 changes: 11 additions & 0 deletions config/.env.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Env file for the purposes of building the docker image
ALLOWED_HOSTS=
SECRET_KEY=
DATABASE_URL=sqlite:///db.sqlite3
GOOGLE_OAUTH2_KEY=
GOOGLE_OAUTH2_SECRET=
DEFAULT_FROM_EMAIL=
EC2_METADATA=False
AWS_SES_REGION_NAME=
AWS_SES_REGION_ENDPOINT=
AWS_STORAGE_BUCKET_NAME=
18 changes: 15 additions & 3 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import environ


env = environ.Env(
# Sets Django's ALLOWED_HOSTS setting
ALLOWED_HOSTS=(list, []),
Expand Down Expand Up @@ -48,6 +47,8 @@
# Set to True to enable the Django Debug Toolbar
DEBUG_TOOLBAR=(bool, False),
# END_FEATURE debug_toolbar

EC2_METADATA=(bool, True)
)
# If ALLWED_HOSTS has been configured, then we're running on a server and
# can skip looking for a .env file (this assumes that .env files
Expand Down Expand Up @@ -76,10 +77,12 @@
# that this is not the production site
PRODUCTION = env("PRODUCTION")

EC2_METADATA = env("EC2_METADATA")

ALLOWED_HOSTS = env("ALLOWED_HOSTS")
if LOCALHOST is True:
ALLOWED_HOSTS = ["127.0.0.1", "localhost"]
else:
elif EC2_METADATA:
# START_FEATURE elastic_beanstalk
# if using AWS hosting
from ec2_metadata import ec2_metadata
Expand Down Expand Up @@ -129,6 +132,9 @@

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
# START_FEATURE docker
"whitenoise.middleware.WhiteNoiseMiddleware",
# END_FEATURE docker
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"common.middleware.MaintenanceModeMiddleware",
Expand Down Expand Up @@ -314,6 +320,12 @@
"default_acl": "private",
}
}

STATIC_BACKEND = "django.contrib.staticfiles.storage.StaticFilesStorage" if LOCALHOST else "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
# START_FEATURE docker
STATIC_BACKEND = "django.contrib.staticfiles.storage.StaticFilesStorage" if LOCALHOST else "whitenoise.storage.CompressedManifestStaticFilesStorage"
# END_FEATURE docker

# END_FEATURE django_storages
STORAGES = {
"default": DEFAULT_STORAGE,
Expand All @@ -328,7 +340,7 @@
},
# END_FEATURE sass_bootstrap
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
"BACKEND": STATIC_BACKEND,
},
}

Expand Down
Loading