Skip to content

Commit

Permalink
Add files for A3.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Gallagher committed Nov 13, 2020
0 parents commit 0172935
Show file tree
Hide file tree
Showing 266 changed files with 112,347 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM python:3.8-alpine

ENV PATH="/scripts:${PATH}"

COPY requirements.txt /requirements.txt

RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers
RUN apk add --update mysql-client
RUN apk add --update mariadb-dev
RUN pip3 install -r /requirements.txt

RUN apk del .tmp

RUN mkdir /GiftcardSite

COPY ./GiftcardSite /GiftcardSite

WORKDIR /GiftcardSite

COPY ./scripts /scripts

RUN chmod +x /scripts/*

RUN mkdir -p /vol/web/media
RUN mkdir -p /vol/web/static

RUN adduser -D django-app

RUN chown -R django-app:django-app /vol

RUN chmod -R 755 /vol/web

RUN chown -R django-app:django-app /GiftcardSite

USER django-app

CMD ["entrypoint.sh"]
107 changes: 107 additions & 0 deletions FAQ.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Frequently Asked Questions

## How do I shut everything down and restart from scratch?

You can use `kubectl delete -f` to remove the resources specified in a YAML file. So for the resources in this assignment:

```
kubectl delete -f proxy/k8
kubectl delete -f GiftcardSite/k8
kubectl delete -f db/k8
```

Note that removing pods will *not* remove their persistent storage, and even deleting the persistent volume and persistent volume claim won't do it. To actually delete the data, you'll need to use `minikube ssh` to get access to the host container, and then remove the files there.

For example, to get rid of the persistent volume associated with the database (`mysql-pv`), you would do:

```
youruser@$ minikube ssh
docker@minikube:~$ sudo rm -rf /data/mysql-pv
docker@minikube:~$ logout
```

You can find out where the data for a persistent volume is located by looking at its `hostPath` in the PersistentVolume YAML file:

```
hostPath:
path: /data/mysql-pv
```

## How do I see what's going wrong?

Start by looking at what pods are running, and their states:

```
kubectl get pods
```

If a pod is in a state other than "Running", you can get more details about it:

```
kubectl describe pod <pod_name>
```

You can also ask for logs from a pod:


```
kubectl logs <pod_name>
```

Finally, it might be helpful to run a shell inside the pod's container so that you can run commands and see what's going on. You can do that by running:

```
kubectl exec --stdin --tty <pod_name> -- bash
```

Some pods (e.g., the GiftcardSite pod) don't have bash installed, so you'll need to use `sh` instead.

## Why can't kubectl find my Docker image?

The most common reason is that you forgot to run `eval $(minikube docker-env)` before running `docker build`. This points the Docker client at the minikube Docker daemon.

Another common mistake is specifying the image version in the YAML file as `latest` (e.g., `my_image:latest`). This will make kubectl try to fetch the image from a remote repository, which will fail if it's an image you've created locally. You can override this behavior either by removing the `:latest` tag, or by adding `imagePullPolicy: Never` to the YAML file.

## How can I open the web interface for a service?

You can find out what services are available by doing `minikube service list`:

```
caterina:k8s moyix$ minikube service list
|----------------------|-------------------------------|--------------|-----|
| NAMESPACE | NAME | TARGET PORT | URL |
|----------------------|-------------------------------|--------------|-----|
| default | assignment3-django-service | 8000 | |
| default | kubernetes | No node port |
| default | mysql-service | No node port |
| default | prometheus-alertmanager | No node port |
| default | prometheus-kube-state-metrics | No node port |
| default | prometheus-node-exporter | No node port |
| default | prometheus-pushgateway | No node port |
| default | prometheus-server | No node port |
| default | proxy-service | 8080 | |
| kube-system | kube-dns | No node port |
| kubernetes-dashboard | dashboard-metrics-scraper | No node port |
| kubernetes-dashboard | kubernetes-dashboard | No node port |
|----------------------|-------------------------------|--------------|-----|
```

Then pick a service and use `minikube service <name>` to open a browser to that service's URL:

```
caterina:k8s moyix$ minikube service prometheus-server
|-----------|-------------------|-------------|--------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-------------------|-------------|--------------|
| default | prometheus-server | | No node port |
|-----------|-------------------|-------------|--------------|
😿 service default/prometheus-server has no node port
🏃 Starting tunnel for service prometheus-server.
|-----------|-------------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-------------------|-------------|------------------------|
| default | prometheus-server | | http://127.0.0.1:61867 |
|-----------|-------------------|-------------|------------------------|
🎉 Opening service default/prometheus-server in default browser...
❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
```
Empty file.
16 changes: 16 additions & 0 deletions GiftcardSite/GiftcardSite/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for GiftcardSite project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'GiftcardSite.settings')

application = get_asgi_application()
156 changes: 156 additions & 0 deletions GiftcardSite/GiftcardSite/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
"""
Django settings for GiftcardSite project.
Generated by 'django-admin startproject' using Django 3.0.8.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os
import base64

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'kmgysa#fz+9(z1*=c0ydrjizk*7sthm2ga1z4=^61$cxcq8b$l'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(int(os.environ.get('DEBUG', 0)))

ALLOWED_HOSTS = ['*']
#ALLOWED_HOSTS_ENV = os.environ.get('ALLOWED_HOSTS')
#if ALLOWED_HOSTS_ENV:
# ALLOWED_HOSTS.extend(ALLOWED_HOSTS_ENV.split(','))


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# Custom
'LegacySite',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'GiftcardSite.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'GiftcardSite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'GiftcardSiteDB',
'HOST': os.environ.get('MYSQL_HOST'),
'PORT': '3306',
'USER': 'root',
'PASSWORD': os.environ.get('MYSQL_ROOT_PASSWORD'),
}
}


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static Images:

IMAGE_ROOT = os.path.join(BASE_DIR, 'images')

# JS Root.

JS_ROOT = os.path.join(BASE_DIR, "templates/js")

# CSS Root

CSS_ROOT = os.path.join(BASE_DIR, "templates/css")

# Font Root
FONT_ROOT = os.path.join(BASE_DIR, "templates/fonts")

# Random Seed for testing
RANDOM_SEED = base64.b64decode("2RUHYAyJWdDdXOicZfnTRw==")

#AUTH_USER_MODEL
#AUTH_USER_MODEL = 'LegacySite.User'

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/static/'
MEDIA_URL = '/static/media/'

STATIC_ROOT = '/vol/web/static'
MEDIA_ROOT = '/vol/web/media'

# Auth Backends
AUTHENTICATION_BACKENDS = ['LegacySite.models.OurBackend']
28 changes: 28 additions & 0 deletions GiftcardSite/GiftcardSite/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""GiftcardSite URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path
from django.views import static
from django.conf import settings

urlpatterns = [
path('images/<str:path>/', static.serve, {'document_root': settings.IMAGE_ROOT}),
path('js/<str:path>/', static.serve, {'document_root': settings.JS_ROOT}),
path('css/<str:path>/', static.serve, {'document_root': settings.CSS_ROOT}),
path('fonts/<str:path>/', static.serve, {'document_root': settings.FONT_ROOT}),
path('', include('LegacySite.urls')),
path('admin/', admin.site.urls),
]
16 changes: 16 additions & 0 deletions GiftcardSite/GiftcardSite/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for GiftcardSite project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'GiftcardSite.settings')

application = get_wsgi_application()
Empty file.
3 changes: 3 additions & 0 deletions GiftcardSite/LegacySite/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions GiftcardSite/LegacySite/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class LegacysiteConfig(AppConfig):
name = 'LegacySite'
Loading

0 comments on commit 0172935

Please sign in to comment.