Bläddra i källkod

add Dockerfile

Nikos Atlas 9 månader sedan
förälder
incheckning
e5ede5d623
4 ändrade filer med 45 tillägg och 1 borttagningar
  1. 29 0
      deploy/Dockerfile
  2. 3 1
      requirements.txt
  3. 1 0
      src/telecaster/settings.py
  4. 12 0
      src/telecaster/views/CosmohomeView.py

+ 29 - 0
deploy/Dockerfile

@@ -0,0 +1,29 @@
+# Use an official Python runtime as a parent image
+FROM python:3.9
+# Set environment variables
+ENV PYTHONDONTWRITEBYTECODE 1
+ENV PYTHONUNBUFFERED 1
+ENV PYTHONPATH "src"
+
+RUN apt-get update && apt-get install -y cron
+
+# Set the working directory in the container
+WORKDIR /app
+COPY requirements.txt /app
+# Install any needed packages specified in requirements.txt
+RUN pip install --no-cache-dir -r requirements.txt
+
+# Copy the current directory contents into the container at /app
+COPY . /app
+WORKDIR /app/src
+# Collect static files
+RUN python manage.py migrate
+RUN python manage.py collectstatic --noinput
+RUN python manage.py crontab add
+RUN python manage.py crontab show
+
+WORKDIR /app
+# Make port 8000 available to the world outside this container
+EXPOSE 8000
+# Run app.py when the container launches
+CMD ["gunicorn", "--bind", "0.0.0.0:8000", "src.wsgi:application"]

+ 3 - 1
requirements.txt

@@ -41,4 +41,6 @@ typing-extensions==4.1.1
 untokenize==0.1.1
 urllib3==1.26.8
 djangorestframework-xml==2.0.0
-django-crontab==0.7.1
+django-crontab==0.7.1
+dicttoxml==1.7.16
+gunicorn==21.2.0

+ 1 - 0
src/telecaster/settings.py

@@ -117,6 +117,7 @@ USE_TZ = True
 # Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/4.0/howto/static-files/
 
+STATIC_ROOT = BASE_DIR / 'static'
 STATIC_URL = 'static/'
 
 # Default primary key field type

+ 12 - 0
src/telecaster/views/CosmohomeView.py

@@ -12,3 +12,15 @@ class CosmohomeView(viewsets.ViewSet):
     def generate_xml(cls, request: Request, *args, **kwargs) -> HttpResponse:
         final_xml = generate_xml_task()
         return HttpResponse('ok')
+
+    @classmethod
+    @action(methods=['get'], detail=False, url_path='xml')
+    def xml(cls, request: Request, *args, **kwargs) -> HttpResponse:
+        file = "cosmohome_products.xml"
+        try:
+            with open(file, 'rb') as f:
+                return HttpResponse(f.read(), content_type='text/xml')
+        except OSError:
+            print(f"No available {file} file. Please generate one first.")
+            pass
+        return HttpResponse('No available xml file. Please generate one first.', status=404)