diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..8ce1e61774d221052765423ee0803b7830aefd9f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git* +*.py[cod] +static/ diff --git a/.gitignore b/.gitignore index c509547efc0b1c05123488377cb4799114d1a801..a714cd796f0d317748fa195503fb8497962b3466 100644 --- a/.gitignore +++ b/.gitignore @@ -109,3 +109,5 @@ dmypy.json # Pyre type checker .pyre/ + +static/ diff --git a/.platform.app.yaml b/.platform.app.yaml deleted file mode 100644 index 1be33d35853ff06d7071ffd4ab26749b8b7880b4..0000000000000000000000000000000000000000 --- a/.platform.app.yaml +++ /dev/null @@ -1,62 +0,0 @@ -# This file describes an application. You can have multiple applications -# in the same project. -# -# See https://docs.platform.sh/user_guide/reference/platform-app-yaml.html - -# The name of this app. Must be unique within a project. -name: 'app' - -# The runtime the application uses. -type: 'python:3.7' - -# The build-time dependencies of the app. -dependencies: - python3: - pipenv: '2018.10.13' - -# The relationships of the application with services or other applications. -# -# The left-hand side is the name of the relationship as it will be exposed -# to the application in the PLATFORM_RELATIONSHIPS variable. The right-hand -# side is in the form `<service name>:<endpoint name>`. -relationships: - database: "postgresqldb:postgresql" - -# The configuration of app when it is exposed to the web. -web: - # Whether your app should speak to the webserver via TCP or Unix socket - # https://docs.platform.sh/configuration/app-containers.html#upstream - upstream: - socket_family: unix - # Commands are run once after deployment to start the application process. - commands: - start: "gunicorn -w 4 -b unix:$SOCKET myapp.wsgi:application" - locations: - "/": - passthru: true - "/static": - root: "static" - expires: 1h - allow: true - -# The size of the persistent disk of the application (in MB). -disk: 512 - -# Set a local R/W mount for logs -mounts: - 'logs': - source: local - source_path: logs - -# The hooks executed at various points in the lifecycle of the application. -hooks: - # The build hook runs before the application is deployed, and is useful for - # assembling the codebase. - build: | - pipenv install --system --deploy - - mkdir logs - python manage.py collectstatic - rm -rf logs - deploy: | - python manage.py migrate diff --git a/.platform/routes.yaml b/.platform/routes.yaml deleted file mode 100644 index ff74ad9b601936503a7ef3b9ddeb4031e696293a..0000000000000000000000000000000000000000 --- a/.platform/routes.yaml +++ /dev/null @@ -1,13 +0,0 @@ -# The routes of the project. -# -# Each route describes how an incoming URL is going to be processed by Platform.sh. -# -# See https://docs.platform.sh/user_guide/reference/routes-yaml.html - -"https://{default}/": - type: upstream - upstream: "app:http" - -"https://www.{default}/": - type: redirect - to: "https://{default}/" diff --git a/.platform/services.yaml b/.platform/services.yaml deleted file mode 100644 index 2972beb1dcf7181293c9781dfbd6718cd338e925..0000000000000000000000000000000000000000 --- a/.platform/services.yaml +++ /dev/null @@ -1,10 +0,0 @@ -# The services of the project. -# -# Each service listed will be deployed in its own container as part of your -# Platform.sh project. -# -# See https://docs.platform.sh/user_guide/reference/services-yaml.html - -postgresqldb: - type: postgresql:9.6 - disk: 1024 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..e3285241da77dc5207af37a12db15419eef51160 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM kennethreitz/pipenv +COPY . /app +RUN mkdir logs && \ + python3 manage.py collectstatic && \ + rm -rf logs +CMD gunicorn --bind=0.0.0.0:8000 myapp.wsgi:application diff --git a/README.md b/README.md index 6f7d3049214e7d4c144889f3eb2a473760df909e..f6750085f8da97e0e473a5373776b63094c9fd23 100644 --- a/README.md +++ b/README.md @@ -1,25 +1 @@ -# Django 2 LTS template for Platform.sh - -This project provides a starter kit for Django projects hosted on Platform.sh. It is primarily an example, although could be used as the starting point for a real project. - -Notice specifically the `settings.py` where we read some of the environment variables and configure Django -to connect to the correct database, and run in Debug mode when not running the `master` branch. - -In this example we are running Django with Gunicorn. You can check-out other examples to see it run with -other application servers. - -## Starting a new project - -To start a new project based on this template, follow these 3 simple steps: - -1. Clone this repository locally. You may optionally remove the `origin` remote or remove the `.git` directory and re-init the project if you want a clean history. - -2. Create a new project through the Platform.sh user interface and select "Import an existing project" when prompted. - -3. Run the provided Git commands to add a Platform.sh remote and push the code to the Platform.sh repository. - -That's it! You now have a working "hello world" level project you can build on. - -## Using as a reference - -You can also use this repository as a reference for your own projects, and borrow whatever code is needed. The most important parts are the `.platform.app.yaml` file and the `.platform` directory. +# Igentify assignment diff --git a/db.sqlite3 b/db.sqlite3 deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..9ad19e08a44ee6b08c8c7cb4a73146bad93bc747 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +--- +version: '3' +services: + postgres: + image: postgres:alpine + environment: &environment + POSTGRES_PASSWORD: password + POSTGRES_DB: myapp + myapp: + build: + context: ./ + environment: *environment + depends_on: + - postgres + ports: + - 8000:8000 + command: | + /bin/sh -c " + while ! nc -z postgres 5432; do sleep 1; done + python3 manage.py migrate + gunicorn --bind=0.0.0.0:8000 myapp.wsgi:application" diff --git a/manage.py b/manage.py index ed184bffe839a07c5d89eebc1db5c373704f6340..b3a6a1da48bf90f7178a20ed7394538c3c2a911f 100755 --- a/manage.py +++ b/manage.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import sys diff --git a/myapp/settings.py b/myapp/settings.py index 34d2f264f0eee14e34b275a0154383ea023aaf2a..97f45e81d641a7dc5414b350ae9680507e26d2cc 100644 --- a/myapp/settings.py +++ b/myapp/settings.py @@ -74,17 +74,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'myapp.wsgi.application' -# Database -# https://docs.djangoproject.com/en/2.1/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} - - # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators @@ -122,42 +111,14 @@ USE_TZ = True # https://docs.djangoproject.com/en/2.1/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static') -# Import some Platform.sh settings from the environment. - -app_dir = os.getenv('PLATFORM_APP_DIR') -if app_dir: - STATIC_ROOT = os.path.join(app_dir, 'static') - -entropy = os.getenv('PLATFORM_PROJECT_ENTROPY') -if entropy: - SECRET_KEY = entropy - -routes = os.getenv('PLATFORM_ROUTES') -if routes: - routes = json.loads(base64.b64decode(routes).decode('utf-8')) - app_name = os.getenv('PLATFORM_APPLICATION_NAME') - for url, route in routes.items(): - host = urlparse(url).netloc - if (host not in ALLOWED_HOSTS and route['type'] == 'upstream' - and route['upstream'] == app_name): - ALLOWED_HOSTS.append(host) - -relationships = os.getenv('PLATFORM_RELATIONSHIPS') -if relationships: - relationships = json.loads(base64.b64decode(relationships).decode('utf-8')) - db_settings = relationships['database'][0] - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': db_settings['path'], - 'USER': db_settings['username'], - 'PASSWORD': db_settings['password'], - 'HOST': db_settings['host'], - 'PORT': db_settings['port'], - }, - 'sqlite': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } - } +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'myapp', + 'USER': os.getenv('POSTGRES_USER', 'postgres'), + 'PASSWORD': os.getenv('POSTGRES_PASSWORD'), + 'HOST': os.getenv('POSTGRES_HOST', 'postgres'), + }, +}