Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
115c5ae319 |
+33
-14
@@ -1,6 +1,6 @@
|
||||
name: Deploy Company Site
|
||||
|
||||
# Runs after Unit Tests completes on master. Direct pushes only (not PRs).
|
||||
# Deploy pipeline runs only on pushes to master (never on pull requests).
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: [Unit Tests]
|
||||
@@ -8,14 +8,34 @@ on:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
if: gitea.event.workflow_run.conclusion == 'success' && gitea.event.workflow_run.event == 'push'
|
||||
test:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ gitea.event.workflow_run.head_sha }}
|
||||
|
||||
- name: Install uv
|
||||
run: |
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Install dependencies
|
||||
run: uv sync --frozen
|
||||
|
||||
- name: Run unit tests
|
||||
env:
|
||||
DJANGO_ENV: dev
|
||||
DJANGO_SECRET_KEY: test-secret-key
|
||||
run: |
|
||||
cd company_site
|
||||
uv run python manage.py test
|
||||
|
||||
docker:
|
||||
runs-on: self-hosted
|
||||
needs: test
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build Docker image
|
||||
run: docker compose build
|
||||
@@ -33,13 +53,12 @@ jobs:
|
||||
deploy:
|
||||
if: gitea.event.workflow_run.conclusion == 'success' && gitea.event.workflow_run.event == 'push'
|
||||
runs-on: self-hosted
|
||||
needs: docker
|
||||
env:
|
||||
SERVER_INFRA_ROOT: /home/westfarn/Documents/repos/server-infra
|
||||
needs: [test, docker]
|
||||
steps:
|
||||
- name: Deploy company_site prod
|
||||
run: |
|
||||
"${SERVER_INFRA_ROOT}/scripts/deploy.sh" \
|
||||
--app company_site \
|
||||
--env prod \
|
||||
--ref "${{ gitea.event.workflow_run.head_sha }}"
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ gitea.event.workflow_run.head_sha }}
|
||||
|
||||
- name: Deploy to live site
|
||||
run: bash scripts/deploy.sh "${{ gitea.workspace }}"
|
||||
|
||||
@@ -13,18 +13,13 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install uv
|
||||
- name: Set up Python environment
|
||||
run: |
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Install dependencies
|
||||
run: uv sync --frozen
|
||||
python3 -m venv .venv
|
||||
.venv/bin/pip install --upgrade pip
|
||||
.venv/bin/pip install -r requirements.txt
|
||||
|
||||
- name: Run unit tests
|
||||
env:
|
||||
DJANGO_ENV: dev
|
||||
DJANGO_SECRET_KEY: test-secret-key
|
||||
run: |
|
||||
cd company_site
|
||||
uv run python manage.py test
|
||||
../.venv/bin/python manage.py test
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"""Shared Django settings for all environments."""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
@@ -23,15 +22,6 @@ def env_list(key: str, default: str = "") -> list[str]:
|
||||
value = os.environ.get(key, default)
|
||||
if not value:
|
||||
return []
|
||||
value = value.strip()
|
||||
# Accept a JSON array (e.g. '["a","b"]') as well as a comma-separated list.
|
||||
if value.startswith("["):
|
||||
try:
|
||||
parsed = json.loads(value)
|
||||
except ValueError:
|
||||
parsed = None
|
||||
if isinstance(parsed, list):
|
||||
return [str(item).strip() for item in parsed if str(item).strip()]
|
||||
return [item.strip() for item in value.split(",") if item.strip()]
|
||||
|
||||
|
||||
@@ -157,7 +147,7 @@ STATIC_URL = "static/"
|
||||
STATIC_ROOT = BASE_DIR / "staticfiles"
|
||||
STORAGES = {
|
||||
"staticfiles": {
|
||||
"BACKEND": "company_site.storage.TolerantManifestStaticFilesStorage",
|
||||
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
"""Custom static files storage.
|
||||
|
||||
WhiteNoise's manifest storage post-processes JS/CSS during ``collectstatic`` and
|
||||
strictly resolves every referenced file, including ``sourceMappingURL`` comments
|
||||
in vendored bundles. Some third-party assets reference ``.map`` files that are
|
||||
not shipped, which makes ``collectstatic`` fail hard.
|
||||
|
||||
``TolerantManifestStaticFilesStorage`` leaves such unresolved references
|
||||
untouched instead of raising, so a missing source map can't break the build.
|
||||
"""
|
||||
|
||||
from whitenoise.storage import CompressedManifestStaticFilesStorage
|
||||
|
||||
|
||||
class TolerantManifestStaticFilesStorage(CompressedManifestStaticFilesStorage):
|
||||
# Don't 500 at runtime when a {% static %} reference isn't in the manifest;
|
||||
# fall back to the plain name (mirrors non-manifest storage behaviour).
|
||||
manifest_strict = False
|
||||
|
||||
def _stored_name(self, name, hashed_files):
|
||||
"""Tolerate missing references during collectstatic post-processing."""
|
||||
try:
|
||||
return super()._stored_name(name, hashed_files)
|
||||
except ValueError:
|
||||
return name
|
||||
|
||||
def stored_name(self, name):
|
||||
"""Tolerate missing manifest entries at request time."""
|
||||
try:
|
||||
return super().stored_name(name)
|
||||
except ValueError:
|
||||
return name
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 22 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 99 KiB |
@@ -1,40 +1,12 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import Client, TestCase, override_settings
|
||||
from django.urls import reverse
|
||||
|
||||
from .models import Contact, EmailMessage
|
||||
from .models import Contact
|
||||
from .seo import SERVICE_URL_NAMES, get_service_entries
|
||||
|
||||
|
||||
class PreviewEmailAuthTests(TestCase):
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
self.user = User.objects.create_user(username="previewer", password="pass")
|
||||
self.email = EmailMessage.objects.create(
|
||||
subject="Preview subject",
|
||||
body="Preview body content",
|
||||
recipient="recipient@example.com",
|
||||
)
|
||||
self.url = reverse("preview_email", kwargs={"pk": self.email.pk})
|
||||
|
||||
def test_unauthenticated_user_is_redirected_to_login(self):
|
||||
response = self.client.get(self.url)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertIn("/accounts/login/", response.url)
|
||||
|
||||
def test_authenticated_user_can_preview_email(self):
|
||||
self.client.login(username="previewer", password="pass")
|
||||
|
||||
response = self.client.get(self.url)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "Preview subject")
|
||||
self.assertContains(response, "Preview body content")
|
||||
|
||||
|
||||
@override_settings(
|
||||
DEBUG=True,
|
||||
EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend",
|
||||
|
||||
+4
-7
@@ -18,14 +18,11 @@ services:
|
||||
build: .
|
||||
ports:
|
||||
- "8000:8000"
|
||||
# No required env_file — CI has no .env. Defaults below; for local secrets:
|
||||
# docker compose --env-file .env up
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
DJANGO_ENV: ${DJANGO_ENV:-dev}
|
||||
DJANGO_SECRET_KEY: ${DJANGO_SECRET_KEY:-dev-only-change-me}
|
||||
DJANGO_DEBUG: ${DJANGO_DEBUG:-true}
|
||||
DJANGO_ALLOWED_HOSTS: ${DJANGO_ALLOWED_HOSTS:-localhost,127.0.0.1,0.0.0.0}
|
||||
DATABASE_URL: ${DATABASE_URL:-postgres://company_site:company_site@db:5432/company_site}
|
||||
DJANGO_ENV: dev
|
||||
DATABASE_URL: postgres://company_site:company_site@db:5432/company_site
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
|
||||
Reference in New Issue
Block a user