Skip to content

Commit 6bd761e

Browse files
authored
Merge pull request #19 from cmu-delphi/staging
Staging
2 parents 043d78f + 7fe73bf commit 6bd761e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1995
-33
lines changed

.ci.env

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This file is used to allow CI to start the compose services. It will typcially
2+
# not need to be modified.
3+
4+
MYSQL_DATABASE=mysql_database
5+
MYSQL_USER=mysql_user
6+
MYSQL_PASSWORD=mysql_password
7+
MYSQL_PORT=3306
8+
MYSQL_ROOT_PASSWORD=test123!
9+
MYSQL_HOST=db
10+
11+
ALLOWED_HOSTS='127.0.0.1,localhost'
12+
CORS_ORIGIN_WHITELIST='http://127.0.0.1:3000,http://localhost:3000'
13+
CSRF_TRUSTED_ORIGINS='http://127.0.0.1:8000,http://localhost:8000'
14+
15+
SECRET_KEY='secret_key'
16+
DEBUG='True'
17+
18+
# Add the following to your local .env file. They will be used in the CI process
19+
# and you can largely forget about them, but including them in your .env file
20+
# will act like a safe default and help suppress warnings.
21+
REGISTRY=""
22+
TAG=""
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: 'Build and deploy application containers'
2+
on:
3+
push:
4+
jobs:
5+
build-tag-push-deploy:
6+
runs-on: ubuntu-latest
7+
# CI/CD will run on these branches
8+
if: >
9+
github.ref == 'refs/heads/main' ||
10+
github.ref == 'refs/heads/staging' ||
11+
github.ref == 'refs/heads/development'
12+
13+
strategy:
14+
matrix:
15+
# Specify the docker-compose services to build images from. These should match the service
16+
# names in the docker-compose.yml file.
17+
service: [sdwebapp, sdnginx]
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
- name: Login to GitHub container registry
22+
uses: docker/login-action@v1
23+
with:
24+
registry: ghcr.io
25+
username: cmu-delphi-deploy-machine
26+
password: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_PAT }}
27+
- name: Create container image tags
28+
id: image-tag
29+
run: |
30+
baseRef="${GITHUB_REF#*/}"
31+
baseRef="${baseRef#*/}"
32+
case "${baseRef}" in
33+
main)
34+
image_tag="latest"
35+
;;
36+
*)
37+
image_tag="${baseRef//\//_}" # replace `/` with `_` in branch name
38+
;;
39+
esac
40+
echo "IMAGE_TAG=${image_tag}" >> $GITHUB_OUTPUT
41+
- name: Copy env file
42+
run: |
43+
cp ./.ci.env ./.env
44+
- name: Set up docker-compose
45+
uses: ndeloof/[email protected]
46+
- name: docker-compose build --push
47+
run: |
48+
docker-compose build --push ${{ matrix.service }}
49+
env:
50+
TAG: ":${{ steps.image-tag.outputs.IMAGE_TAG }}"
51+
REGISTRY: "ghcr.io/${{ github.repository_owner }}/"
52+
- name: docker-compose down
53+
run: |
54+
docker-compose down
55+
- name: Trigger smee.io webhook to pull new container images
56+
run: |
57+
curl -H "Authorization: Bearer ${{ secrets.DELPHI_DEPLOY_WEBHOOK_TOKEN }}" \
58+
-X POST ${{ secrets.DELPHI_DEPLOY_WEBHOOK_URL }} \
59+
-H "Content-Type: application/x-www-form-urlencoded" \
60+
-d "repository=ghcr.io/${{ github.repository }}-${{ matrix.service }}&tag=${{ steps.image-tag.outputs.IMAGE_TAG }}"

docker-compose.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
db:
33
image: mysql:latest
4-
container_name: signal_documentation-db
4+
container_name: signal-discovery-db
55
restart: always
66
env_file:
77
- ./.env
@@ -16,21 +16,21 @@ services:
1616
- "3306:3306"
1717

1818
# Production service - "service", "image", and "container_name" should all contain the same
19-
# reference, based on the name of the service.
19+
# reference based on the name of the service.
2020
sdwebapp:
21-
image: ${REGISTRY}signal_documentation-sdwebapp${TAG}
21+
image: ${REGISTRY}signal-discovery-sdwebapp${TAG}
2222
build:
2323
context: .
2424

2525
env_file:
2626
- ./.env
27-
container_name: signal_documentation-sdwebapp
27+
container_name: signal-discovery-sdwebapp
2828
restart: on-failure
29-
command:
30-
sh -c "python3 /usr/src/signal_documentation/src/manage.py migrate --noinput &&
31-
python3 /usr/src/signal_documentation/src/manage.py collectstatic --noinput &&
32-
python3 /usr/src/signal_documentation/src/manage.py loaddata ./fixtures/* &&
33-
python3 /usr/src/signal_documentation/src/manage.py runserver 0.0.0.0:8000"
29+
command: sh -c "python3 /usr/src/signal_documentation/src/manage.py migrate --noinput &&
30+
python3 /usr/src/signal_documentation/src/manage.py collectstatic --noinput &&
31+
python3 /usr/src/signal_documentation/src/manage.py loaddata ./fixtures/* &&
32+
python3 /usr/src/signal_documentation/src/manage.py initadmin &&
33+
python3 /usr/src/signal_documentation/src/manage.py runserver 0.0.0.0:8000"
3434
volumes:
3535
- .:/usr/src/signal_documentation
3636
ports:
@@ -41,11 +41,11 @@ services:
4141
# Production service - "service", "image", and "container_name" should all contain the same
4242
# reference, based on the name of the service.
4343
sdnginx:
44-
image: ${REGISTRY}signal_documentation-sdnginx${TAG}
44+
image: ${REGISTRY}signal-discovery-sdnginx${TAG}
4545
build: ./nginx
4646
env_file:
4747
- ./.env
48-
container_name: signal_documentation-sdnginx
48+
container_name: signal-discovery-sdnginx
4949
restart: on-failure
5050
volumes:
5151
- ./src/staticfiles:/staticfiles

gunicorn/gunicorn.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
bind = "0.0.0.0:8000"
44
workers = multiprocessing.cpu_count() * 2 + 1
5+
keepalive = 120
6+
timeout = 300

nginx/default.conf.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,11 @@ server {
1818
proxy_set_header Host $http_host;
1919
proxy_set_header X-Real-IP $remote_addr;
2020
proxy_set_header X-Forwarded-Proto $scheme;
21+
proxy_read_timeout 300;
22+
proxy_connect_timeout 300;
23+
proxy_send_timeout 300;
24+
send_timeout 300;
25+
keepalive_timeout 300;
26+
client_max_body_size 64m;
2127
}
2228
}

src/base/management/__init__.py

Whitespace-only changes.

src/base/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
from django.core.management.base import BaseCommand
3+
from django.contrib.auth.models import User
4+
5+
6+
ADMIN_USERNAME = os.environ.get("ADMIN_USERNAME", "admin") # Default username
7+
ADMIN_EMAIL = os.environ.get("ADMIN_EMAIL", "[email protected]") # Default email
8+
ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "admin123") # Default password
9+
10+
11+
class Command(BaseCommand):
12+
help = "Automatically creates a superuser"
13+
14+
def handle(self, *args, **kwargs):
15+
if not User.objects.filter(username=ADMIN_USERNAME).exists():
16+
User.objects.create_superuser(ADMIN_USERNAME, ADMIN_EMAIL, ADMIN_PASSWORD)
17+
self.stdout.write(self.style.SUCCESS("Superuser created successfully"))
18+
else:
19+
self.stdout.write(self.style.WARNING("Superuser already exists"))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.0.7 on 2024-10-15 12:31
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('datasources', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='datasource',
15+
name='display_name',
16+
field=models.CharField(blank=True, max_length=128, verbose_name='Display Name'),
17+
),
18+
]

src/datasources/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class DataSource(TimeStampedModel):
1616
display_name: models.CharField = models.CharField(
1717
verbose_name=_('Display Name'),
1818
max_length=128,
19+
blank=True
1920
)
2021
description: models.TextField = models.TextField(
2122
verbose_name=_('Description'),

0 commit comments

Comments
 (0)