Skip to content

Commit 3f01c1d

Browse files
author
jcob
committed
update deployment files
1 parent e882e64 commit 3f01c1d

File tree

5 files changed

+104
-28
lines changed

5 files changed

+104
-28
lines changed

server/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM python:3.12.0-slim-bookworm
2+
3+
ENV PYTHONBUFFERED 1
4+
ENV PYTHONWRITEBYTECODE 1
5+
6+
ENV APP=/app
7+
8+
# Change the workdir.
9+
WORKDIR $APP
10+
11+
# Install the requirements
12+
COPY requirements.txt $APP
13+
14+
RUN pip3 install -r requirements.txt
15+
16+
# Copy the rest of the files
17+
COPY . $APP
18+
19+
EXPOSE 8000
20+
21+
RUN chmod +x /app/entrypoint.sh
22+
23+
ENTRYPOINT ["/bin/bash","/app/entrypoint.sh"]
24+
25+
CMD ["gunicorn", "--bind", ":8000", "--workers", "3", "djangoproj.wsgi"]

server/deployment.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
run: dealership
6+
name: dealership
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
run: dealership
12+
strategy:
13+
rollingUpdate:
14+
maxSurge: 25%
15+
maxUnavailable: 25%
16+
type: RollingUpdate
17+
template:
18+
metadata:
19+
labels:
20+
run: dealership
21+
spec:
22+
containers:
23+
- image: us.icr.io/sn-labs-jolaya32/dealership:latest
24+
imagePullPolicy: Always
25+
name: dealership
26+
ports:
27+
- containerPort: 8000
28+
protocol: TCP
29+
restartPolicy: Always

server/djangoapp/models.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# Uncomment the following imports before adding the Model code
22

33
from django.db import models
4-
# from django.utils.timezone import now
4+
from django.utils.timezone import now
55
from django.core.validators import MaxValueValidator, MinValueValidator
6-
from django.contrib import admin
7-
from .models import CarMake, CarModel
86

97

108
# Create your models here.
@@ -25,35 +23,38 @@
2523
# - Year (IntegerField) with min value 2015 and max value 2023
2624
# - Any other fields you would like to include in car model
2725
# - __str__ method to print a car make object
26+
class CarMake(models.Model):
27+
name = models.CharField(max_length=100)
28+
description = models.TextField()
29+
# Other fields as needed
30+
31+
def __str__(self):
32+
return self.name # Return the name as the string representation
33+
2834

29-
#class CarMake(models.Model):
30-
# name = models.CharField(max_length=100)
31-
# description = models.TextField()
32-
# # Other fields as needed
33-
34-
# def __str__(self):
35-
# return self.name # Return the name as the string representation
36-
37-
#class CarModel(models.Model):
38-
# car_make = models.ForeignKey(CarMake, on_delete=models.CASCADE) #Many-to-One relationship
39-
# name = models.CharField(max_length=100)
40-
# CAR_TYPES = [
41-
# ('SEDAN', 'Sedan'),
42-
# ('SUV', 'SUV'),
43-
# ('WAGON', 'Wagon'),
35+
class CarModel(models.Model):
36+
car_make = models.ForeignKey(CarMake, on_delete=models.CASCADE) # Many-to-One relationship
37+
name = models.CharField(max_length=100)
38+
CAR_TYPES = [
39+
('SEDAN', 'Sedan'),
40+
('SUV', 'SUV'),
41+
('WAGON', 'Wagon'),
4442
# Add more choices as required
45-
# ]
46-
# type = models.CharField(max_length=10, choices=CAR_TYPES, default='SUV')
47-
# year = models.IntegerField(default=2023,
48-
# validators=[
49-
# MaxValueValidator(2023),
50-
# MinValueValidator(2015)
51-
# ]
52-
# )
43+
]
44+
type = models.CharField(max_length=10, choices=CAR_TYPES, default='SUV')
45+
year = models.IntegerField(default=2023,
46+
validators=[
47+
MaxValueValidator(2023),
48+
MinValueValidator(2015)
49+
])
5350
# Other fields as needed
5451

55-
# def __str__(self):
56-
# return self.name # Return the name as the string representation
52+
def __str__(self):
53+
return self.name # Return the name as the string representation
54+
55+
56+
from django.contrib import admin
57+
from .models import CarMake, CarModel
5758

5859
# Registering models with their respective admins
5960
admin.site.register(CarMake)

server/entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
# Make migrations and migrate the database.
4+
echo "Making migrations and migrating the database. "
5+
python manage.py makemigrations --noinput
6+
python manage.py migrate --noinput
7+
python manage.py collectstatic --noinput
8+
exec "$@"

server/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)