Skip to content

Commit

Permalink
moving tailwind and collectstatic commands to docker image; added env…
Browse files Browse the repository at this point in the history
… var defaults

tailwind commands requires env vars set for some reason,
  • Loading branch information
qtrinh2 committed Jun 4, 2024
1 parent b29aa51 commit 0be6986
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 47 deletions.
15 changes: 0 additions & 15 deletions .env.j2

This file was deleted.

23 changes: 6 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ ENV PYTHONUNBUFFERED 1
# Set working directory
WORKDIR /app

# Copy project
COPY . /app/

# Install dependencies with Poetry
COPY poetry.lock pyproject.toml /app/
RUN pip3 install poetry

RUN poetry config virtualenvs.create false
Expand All @@ -40,24 +42,11 @@ RUN ln -s /root/.volta/bin/volta-shim /root/.volta/bin/npx
RUN ln -s /root/.volta/bin/volta-shim /root/.volta/bin/pnpm
RUN ln -s /root/.volta/bin/volta-shim /root/.volta/bin/yarn

# Copy project
COPY . /app/

# triggers node installation
RUN node -v && npm -v

RUN npm install

#ENV TAILWIND_CSS_PATH='../../static/css/dist/styles.css'
#RUN poetry run python3 manage.py tailwind install --no-input
#RUN poetry run python3 manage.py tailwind build --no-input
#RUN poetry run python3 manage.py collectstatic --no-input

#CMD poetry run python3 manage.py runserver 0.0.0.0:8000
RUN poetry run python manage.py tailwind install
RUN poetry run python manage.py tailwind build
RUN poetry run python manage.py collectstatic --no-input

CMD bash -c " \
poetry run python3 manage.py tailwind install --no-input && \
poetry run python3 manage.py tailwind build --no-input && \
poetry run python3 manage.py collectstatic --no-input && \
poetry run python3 manage.py runserver 0.0.0.0:8000 \
"
8 changes: 4 additions & 4 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
# ------------------------------------------------------------------------------

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env("DJANGO_SECRET_KEY")
SECRET_KEY = env("DJANGO_SECRET_KEY", default="django-insecure cin)v(4&89%_$17s0yezo=t+^1b*mq)=+348r-bv(ms#pm2y2#")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env("DEBUG")

ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS")
CSRF_TRUSTED_ORIGINS = env.list("DJANGO_CSRF_TRUSTED_ORIGINS")
ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS", default=['localhost'])
CSRF_TRUSTED_ORIGINS = env.list("DJANGO_CSRF_TRUSTED_ORIGINS", default=['http://localhost'])


# Application definition
Expand Down Expand Up @@ -126,7 +126,7 @@
"PORT": env("DB_PORT", default="5432"),
"NAME": env("DB_NAME", default="denig"),
"USER": env("DB_USER", default="denig"),
"PASSWORD": env("DB_PASSWORD"),
"PASSWORD": env("DB_PASS", default="password"),
}
}

Expand Down
24 changes: 18 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,36 @@ services:
build: .
image: "rrchnm/winterthur"
container_name: "winterthur-app"
env_file: .env
ports:
- 8000:8000
volumes:
- dj-data:/app
environment:
- DEBUG=True
- DJANGO_SECRET_KEY=thisisnotasecretkey
- DJANGO_ALLOWED_HOSTS=localhost
- DJANGO_CSRF_TRUSTED_ORIGINS=http://localhost
- DB_HOST=db
- DB_PORT=5432
- DB_NAME=winterthur
- DB_USER=winterthur
- DB_PASSWORD=password
command: >
sh -c "poetry run python3 manage.py migrate &&
poetry run python3 manage.py tailwind install --no-input &&
poetry run python3 manage.py tailwind build --no-input &&
poetry run python3 manage.py collectstatic --no-input &&
poetry run python3 manage.py runserver 0.0.0.0:8000"
depends_on:
db:
condition: service_healthy
db:
image: postgres:12
image: postgres:16
container_name: "winterthur-db"
env_file: .env
volumes:
- pg-data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=winterthur
- POSTGRES_USER=winterthur
- POSTGRES_PASSWORD=password
- POSTGRES_HOST=db
healthcheck:
test: ["CMD-SHELL", "pg_isready -U winterthur"]
interval: 2s
Expand Down
20 changes: 15 additions & 5 deletions docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ services:
image: ghcr.io/{{ template.git.package.image_name }}:{{ template.git.package.tag }}
container_name: {{ template.name }}_app
restart: unless-stopped
env_file: .env
ports:
- "{{ template.env.host_app_port }}:8000"
environment:
- DEBUG={{ template.env.debug_flag }}
- DJANGO_SECRET_KEY={{ template.env.secret_key }}
- DJANGO_ALLOWED_HOSTS={{ template.env.allowed_hosts }}
- DJANGO_CSRF_TRUSTED_ORIGINS={{ template.env.trusted_origins }}
- DB_HOST=db
- DB_PORT={{ template.env.host_db_port }}
- DB_NAME={{ template.env.db_name }}
- DB_USER={{ template.env.db_user }}
- DB_PASSWORD={{ template.env.db_pass }}
command: >
sh -c "poetry run python3 manage.py migrate &&
poetry run python3 manage.py tailwind install --no-input &&
poetry run python3 manage.py tailwind build --no-input &&
poetry run python3 manage.py collectstatic --no-input &&
poetry run python3 manage.py runserver 0.0.0.0:8000"
volumes:
- dj-static:/app/staticfiles
Expand All @@ -25,9 +31,13 @@ services:
image: postgres:12
container_name: {{ template.name }}_db
restart: unless-stopped
env_file: .env
volumes:
- pg-data:/var/lib/postgresql/data/
environment:
- POSTGRES_DB={{ template.env.db_name }}
- POSTGRES_USER={{ template.env.db_user }}
- POSTGRES_PASSWORD={{ template.env.db_pass }}
- POSTGRES_HOST=db
healthcheck:
test: ["CMD-SHELL", "pg_isready -U {{ template.env.db_user }}"]
interval: 5s
Expand Down

0 comments on commit 0be6986

Please sign in to comment.