diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000000..7e155a5ef8 --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,28 @@ +FROM python:3.8.2 + +ENV PYTHONBUFFERED 1 +ENV PYTHONWRITEBYTECODE 1 + +RUN apt-get update \ + && apt-get install -y netcat + +ENV APP=/app + +# Change the workdir. +WORKDIR $APP + +# Install the requirements +COPY requirements.txt $APP + +RUN pip3 install -r requirements.txt + +# Copy the rest of the files +COPY . $APP + +EXPOSE 8000 + +RUN chmod +x /app/entrypoint.sh + +ENTRYPOINT ["/bin/bash","/app/entrypoint.sh"] + +CMD ["gunicorn", "--bind", ":8000", "--workers", "3", "djangobackend.wsgi"] \ No newline at end of file diff --git a/server/deployment.yaml b/server/deployment.yaml new file mode 100644 index 0000000000..e99170847d --- /dev/null +++ b/server/deployment.yaml @@ -0,0 +1,29 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + run: dealership + name: dealership +spec: + replicas: 1 + selector: + matchLabels: + run: dealership + strategy: + rollingUpdate: + maxSurge: 25% + maxUnavailable: 25% + type: RollingUpdate + template: + metadata: + labels: + run: dealership + spec: + containers: + - image: us.icr.io/sn-labs-seymoneagugn/dealership:latest + imagePullPolicy: Always + name: dealership + ports: + - containerPort: 8000 + protocol: TCP + restartPolicy: Always \ No newline at end of file diff --git a/server/entrypoint.sh b/server/entrypoint.sh new file mode 100755 index 0000000000..1a48bf8972 --- /dev/null +++ b/server/entrypoint.sh @@ -0,0 +1,17 @@ + #!/bin/sh + + if [ "$DATABASE" = "postgres" ]; then + echo "Waiting for postgres..." + + while ! nc -z $DATABASE_HOST $DATABASE_PORT; do + sleep 0.1 + done + + echo "PostgreSQL started" + fi + + # Make migrations and migrate the database. + echo "Making migrations and migrating the database. " + python manage.py makemigrations main --noinput + python manage.py migrate --noinput + exec "$@" \ No newline at end of file