Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cead9d5aea | ||
|
|
03de5aacfb | ||
|
|
5b9e568d54 | ||
|
|
eafbffce25 | ||
|
|
06c49d551d | ||
|
|
8c9389ba1f | ||
|
|
b9b948a8b5 | ||
|
|
a0e0afff1f |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
venv/
|
||||
__pycache__/
|
||||
db/
|
||||
staticfiles/
|
||||
staticfiles/
|
||||
.vscode/settings.json
|
||||
@@ -1,6 +1,7 @@
|
||||
variables:
|
||||
CI_PROJECT_DIR: "."
|
||||
CI_REGISTRY_IMAGE: hub.ducoterra.net/ducoterra/mysite
|
||||
CI_REGISTRY_IMAGE: hub.ducoterra.net/ducoterra/button
|
||||
DEPLOY: button
|
||||
|
||||
stages:
|
||||
- build
|
||||
@@ -16,21 +17,25 @@ build:
|
||||
name: gcr.io/kaniko-project/executor:debug
|
||||
entrypoint: [""]
|
||||
script:
|
||||
- echo $DEPLOY
|
||||
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
|
||||
|
||||
test:
|
||||
stage: test
|
||||
variables:
|
||||
POSTGRES_PASSWORD: postgres
|
||||
only:
|
||||
variables:
|
||||
- $CI_COMMIT_TAG
|
||||
services:
|
||||
- name: postgres:12
|
||||
alias: postgres
|
||||
image:
|
||||
name: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
|
||||
entrypoint: [""]
|
||||
script:
|
||||
- python manage.py test
|
||||
|
||||
deploy_to_test:
|
||||
deploy:
|
||||
variables:
|
||||
DEPLOY: test
|
||||
stage: deploy
|
||||
@@ -42,35 +47,9 @@ deploy_to_test:
|
||||
entrypoint: [""]
|
||||
script:
|
||||
- apt -qq update >> /dev/null && apt -qq install -y curl gettext >> /dev/null
|
||||
- curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
|
||||
- chmod +x ./kubectl
|
||||
- mkdir /deploy
|
||||
- for f in $(find k8s -regex '.*\.ya*ml'); do envsubst < $f > "/deploy/$(basename $f)"; done
|
||||
- for f in $(find k8s/test -regex '.*\.ya*ml'); do envsubst < $f > "/deploy/$(basename $f)"; done
|
||||
- ./kubectl apply -f /deploy
|
||||
- ./kubectl rollout status deploy $DEPLOY
|
||||
- POD=$(./kubectl get pods --selector=app=$DEPLOY --output=jsonpath='{.items[*].metadata.name}')
|
||||
- ./kubectl exec $POD -- python manage.py migrate
|
||||
|
||||
deploy_to_prod:
|
||||
variables:
|
||||
DEPLOY: prod
|
||||
stage: deploy
|
||||
only:
|
||||
variables:
|
||||
- $CI_COMMIT_TAG
|
||||
when: manual
|
||||
image:
|
||||
name: debian:10
|
||||
entrypoint: [""]
|
||||
script:
|
||||
- apt -qq update >> /dev/null && apt -qq install -y curl gettext >> /dev/null
|
||||
- curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
|
||||
- chmod +x ./kubectl
|
||||
- mkdir /deploy
|
||||
- for f in $(find k8s -regex '.*\.ya*ml'); do envsubst < $f > "/deploy/$(basename $f)"; done
|
||||
- for f in $(find k8s/prod -regex '.*\.ya*ml'); do envsubst < $f > "/deploy/$(basename $f)"; done
|
||||
- ./kubectl apply -f /deploy
|
||||
- ./kubectl rollout status deploy $DEPLOY
|
||||
- curl -o /usr/bin/kubectl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
|
||||
- chmod +x /usr/bin/kubectl
|
||||
- curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
|
||||
- helm upgrade --install $DEPLOY ./helm --set image=$CI_REGISTRY_IMAGE --set tag=$CI_COMMIT_TAG
|
||||
- POD=$(./kubectl get pods --selector=app=$DEPLOY --output=jsonpath='{.items[*].metadata.name}')
|
||||
- ./kubectl exec $POD -- python manage.py migrate
|
||||
11
.vscode/launch.json
vendored
11
.vscode/launch.json
vendored
@@ -12,8 +12,11 @@
|
||||
"args": [
|
||||
"test",
|
||||
],
|
||||
"env": {
|
||||
"DB_HOST": "localhost"
|
||||
},
|
||||
"django": true,
|
||||
"preLaunchTask": "Migrate"
|
||||
"preLaunchTask": "docker-compose up"
|
||||
},
|
||||
{
|
||||
"name": "Run Server",
|
||||
@@ -22,10 +25,12 @@
|
||||
"program": "${workspaceFolder}/manage.py",
|
||||
"args": [
|
||||
"runserver",
|
||||
"--noreload"
|
||||
],
|
||||
"env": {
|
||||
"DB_HOST": "localhost"
|
||||
},
|
||||
"django": true,
|
||||
"preLaunchTask": "Migrate"
|
||||
"preLaunchTask": "docker-compose up"
|
||||
}
|
||||
]
|
||||
}
|
||||
20
.vscode/tasks.json
vendored
20
.vscode/tasks.json
vendored
@@ -2,23 +2,9 @@
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Collect Static",
|
||||
"command": "venv/bin/python manage.py collectstatic --no-input",
|
||||
"type": "shell",
|
||||
"presentation": {
|
||||
"reveal": "always"
|
||||
},
|
||||
"group": "build"
|
||||
},
|
||||
{
|
||||
"dependsOn": "Collect Static",
|
||||
"label": "Migrate",
|
||||
"command": "venv/bin/python manage.py migrate",
|
||||
"type": "shell",
|
||||
"presentation": {
|
||||
"reveal": "always"
|
||||
},
|
||||
"group": "build"
|
||||
"label": "docker-compose up",
|
||||
"command": "docker-compose up -d",
|
||||
"type": "shell"
|
||||
}
|
||||
]
|
||||
}
|
||||
21
README.md
21
README.md
@@ -2,23 +2,4 @@
|
||||
|
||||
My CI testing pipeline for a django project.
|
||||
|
||||
[](http://gitlab.ducoterra.net/ducoterra/ci_builder/-/commits/master)
|
||||
|
||||
## Django Environment Variables
|
||||
|
||||
### Django Secret
|
||||
|
||||
```bash
|
||||
kubectl create secret generic django-secrets --from-literal=SECRET_KEY=$(python -c "import secrets ; print(secrets.token_urlsafe(32))")
|
||||
```
|
||||
|
||||
### Django Allowed Hosts
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: test
|
||||
data:
|
||||
ALLOWED_HOSTS: localhost,test.ducoterra.net
|
||||
```
|
||||
[](http://gitlab.ducoterra.net/ducoterra/ci_builder/-/commits/master)
|
||||
@@ -79,8 +79,12 @@ WSGI_APPLICATION = 'config.wsgi.application'
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db/db.sqlite3'),
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': os.getenv('DB_NAME', 'postgres'),
|
||||
'USER': os.getenv('POSTGRES_USER', 'postgres'),
|
||||
'PASSWORD': os.getenv('POSTGRES_PASSWORD', 'postgres'),
|
||||
'HOST': os.getenv('DB_HOST', 'postgres'),
|
||||
'PORT': os.getenv('DB_PORT', '5432'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
56
docker-compose.yml
Executable file
56
docker-compose.yml
Executable file
@@ -0,0 +1,56 @@
|
||||
version: '3.5'
|
||||
|
||||
services:
|
||||
button:
|
||||
build: .
|
||||
labels:
|
||||
- "traefik.http.routers.button.rule=Host(`button.localhost`)"
|
||||
- "traefik.http.services.button-service.loadbalancer.server.port=8000"
|
||||
- "traefik.http.middlewares.btn-ratelimit.ratelimit.average=50"
|
||||
- "traefik.http.middlewares.btn-ratelimit.ratelimit.burst=10"
|
||||
- "traefik.http.routers.button.middlewares=btn-ratelimit@docker"
|
||||
volumes:
|
||||
- ./manage.py:/app/manage.py
|
||||
- ./config:/app/config
|
||||
- ./api:/app/api
|
||||
environment:
|
||||
- DEBUG=True
|
||||
- SECRET_KEY=secret
|
||||
- ALLOWED_HOSTS=button.localhost
|
||||
- DJANGO_SUPERUSER_PASSWORD=django
|
||||
|
||||
postgres:
|
||||
image: postgres:12
|
||||
volumes:
|
||||
- data:/var/lib/postgresql/data
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
ports:
|
||||
- 5432:5432
|
||||
|
||||
pgadmin:
|
||||
image: dpage/pgadmin4:4
|
||||
labels:
|
||||
- "traefik.http.routers.pgadmin.rule=Host(`pgadmin.localhost`)"
|
||||
- "traefik.http.services.pgadmin-service.loadbalancer.server.port=80"
|
||||
volumes:
|
||||
- pgadmin:/var/lib/pgadmin
|
||||
environment:
|
||||
PGADMIN_DEFAULT_EMAIL: postgres
|
||||
PGADMIN_DEFAULT_PASSWORD: postgres
|
||||
|
||||
traefik:
|
||||
image: traefik:v2.2
|
||||
labels:
|
||||
- "traefik.http.routers.traefik.rule=Host(`traefik.localhost`)"
|
||||
- "traefik.http.services.traefik-service.loadbalancer.server.port=8080"
|
||||
command: --api.insecure=true --providers.docker --log.level=ERROR --accesslog=true
|
||||
ports:
|
||||
- 80:80
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
|
||||
volumes:
|
||||
data:
|
||||
pgadmin:
|
||||
38
heavy_load.py
Normal file
38
heavy_load.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import getpass
|
||||
import threading
|
||||
import requests
|
||||
import time
|
||||
import sys
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
rate = int(sys.argv[1]) # /second
|
||||
if rate == 0:
|
||||
burst = True
|
||||
print("Burst mode activated")
|
||||
else:
|
||||
burst = False
|
||||
sleep = 1 / rate
|
||||
print(f"Beginning load test at {rate} calls/second")
|
||||
url = 'https://button.ducoterra.net/'
|
||||
# url = 'http://button.localhost/'
|
||||
|
||||
def timer(func, *args, **kwargs):
|
||||
then = time.time()
|
||||
func(*args, **kwargs)
|
||||
print(time.time() - then)
|
||||
|
||||
# init = requests.get('https://button.ducoterra.net/button/')
|
||||
init = requests.get(url)
|
||||
csrf = init.cookies.get('csrftoken')
|
||||
session = init.cookies.get('sessionid')
|
||||
me = lambda num: print(num) or print(requests.post(url, headers = {'Content-Type': 'application/json', 'X-CSRFToken': csrf, 'Cookie': f'csrftoken={csrf}; sessionid={session}'}).text)
|
||||
threadme = lambda num: threading.Thread(target=timer, args=(me, num)).start()
|
||||
|
||||
if burst:
|
||||
[threadme(num) for num in range(0,100)]
|
||||
else:
|
||||
num = 1
|
||||
while True:
|
||||
threadme(num)
|
||||
num += 1
|
||||
time.sleep(sleep)
|
||||
23
helm/.helmignore
Normal file
23
helm/.helmignore
Normal file
@@ -0,0 +1,23 @@
|
||||
# Patterns to ignore when building packages.
|
||||
# This supports shell glob matching, relative path matching, and
|
||||
# negation (prefixed with !). Only one pattern per line.
|
||||
.DS_Store
|
||||
# Common VCS dirs
|
||||
.git/
|
||||
.gitignore
|
||||
.bzr/
|
||||
.bzrignore
|
||||
.hg/
|
||||
.hgignore
|
||||
.svn/
|
||||
# Common backup files
|
||||
*.swp
|
||||
*.bak
|
||||
*.tmp
|
||||
*.orig
|
||||
*~
|
||||
# Various IDEs
|
||||
.project
|
||||
.idea/
|
||||
*.tmproj
|
||||
.vscode/
|
||||
23
helm/Chart.yaml
Normal file
23
helm/Chart.yaml
Normal file
@@ -0,0 +1,23 @@
|
||||
apiVersion: v2
|
||||
name: helm
|
||||
description: A Helm chart for Kubernetes
|
||||
|
||||
# A chart can be either an 'application' or a 'library' chart.
|
||||
#
|
||||
# Application charts are a collection of templates that can be packaged into versioned archives
|
||||
# to be deployed.
|
||||
#
|
||||
# Library charts provide useful utilities or functions for the chart developer. They're included as
|
||||
# a dependency of application charts to inject those utilities and functions into the rendering
|
||||
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
|
||||
type: application
|
||||
|
||||
# This is the chart version. This version number should be incremented each time you make changes
|
||||
# to the chart and its templates, including the app version.
|
||||
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
||||
version: 0.1.0
|
||||
|
||||
# This is the version number of the application being deployed. This version number should be
|
||||
# incremented each time you make changes to the application. Versions are not expected to
|
||||
# follow Semantic Versioning. They should reflect the version the application is using.
|
||||
appVersion: 1.16.0
|
||||
8
helm/templates/configmap.yaml
Normal file
8
helm/templates/configmap.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: {{ .Release.Name }}
|
||||
labels:
|
||||
app: {{ .Release.Name }}
|
||||
data:
|
||||
ALLOWED_HOSTS: {{ .Release.Name }}.ducoterra.net
|
||||
33
helm/templates/deploy.yaml
Normal file
33
helm/templates/deploy.yaml
Normal file
@@ -0,0 +1,33 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ .Release.Name }}
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: {{ .Release.Name }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: {{ .Release.Name }}
|
||||
spec:
|
||||
containers:
|
||||
- image: {{ required "A valid .Values.image entry required!" .Values.image }}:{{ required "A valid .Values.tag entry required!" .Values.tag }}
|
||||
name: {{ .Release.Name }}
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: {{ .Release.Name }}
|
||||
- secretRef:
|
||||
name: {{ .Release.Name }}
|
||||
- secretRef:
|
||||
name: postgres
|
||||
resources:
|
||||
limits:
|
||||
memory: "500Mi"
|
||||
cpu: "250m"
|
||||
requests:
|
||||
memory: "1Mi"
|
||||
cpu: "100m"
|
||||
18
helm/templates/hpa.yaml
Normal file
18
helm/templates/hpa.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
apiVersion: autoscaling/v2beta2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: {{ .Release.Name }}
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: {{ .Release.Name }}
|
||||
minReplicas: 1
|
||||
maxReplicas: 4
|
||||
metrics:
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: 50
|
||||
78
helm/templates/ingress.yaml
Executable file
78
helm/templates/ingress.yaml
Executable file
@@ -0,0 +1,78 @@
|
||||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: {{ .Release.Name }}-internal-tls
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: traefik-internal
|
||||
spec:
|
||||
entryPoints:
|
||||
- websecure
|
||||
tls:
|
||||
certResolver: myresolver
|
||||
domains:
|
||||
- main: "*.ducoterra.net"
|
||||
routes:
|
||||
- match: Host(`{{ .Release.Name }}.ducoterra.net`)
|
||||
kind: Rule
|
||||
services:
|
||||
- name: {{ .Release.Name }}
|
||||
port: 8000
|
||||
|
||||
---
|
||||
|
||||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: {{ .Release.Name }}-internal-web
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: traefik-internal
|
||||
spec:
|
||||
entryPoints:
|
||||
- web
|
||||
routes:
|
||||
- match: Host(`{{ .Release.Name }}.ducoterra.net`)
|
||||
kind: Rule
|
||||
services:
|
||||
- name: {{ .Release.Name }}
|
||||
port: 8000
|
||||
middlewares:
|
||||
- name: httpsredirect
|
||||
|
||||
---
|
||||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: {{ .Release.Name }}-external-tls
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: traefik-external
|
||||
spec:
|
||||
entryPoints:
|
||||
- websecure
|
||||
tls:
|
||||
certResolver: myresolver
|
||||
routes:
|
||||
- match: Host(`{{ .Release.Name }}.ducoterra.net`)
|
||||
kind: Rule
|
||||
services:
|
||||
- name: {{ .Release.Name }}
|
||||
port: 8000
|
||||
|
||||
---
|
||||
|
||||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: {{ .Release.Name }}-external-web
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: traefik-external
|
||||
spec:
|
||||
entryPoints:
|
||||
- web
|
||||
routes:
|
||||
- match: Host(`{{ .Release.Name }}.ducoterra.net`)
|
||||
kind: Rule
|
||||
services:
|
||||
- name: {{ .Release.Name }}
|
||||
port: 8000
|
||||
middlewares:
|
||||
- name: httpsredirect
|
||||
10
helm/templates/secret.yaml
Normal file
10
helm/templates/secret.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
{{ if and .Values.secret .Release.IsInstall }}
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: {{ .Release.Name }}
|
||||
type: generic
|
||||
data:
|
||||
SECRET_KEY: {{ randAlphaNum 64 | b64enc | quote }}
|
||||
DJANGO_SUPERUSER_PASSWORD: {{ randAlphaNum 64 | b64enc | quote }}
|
||||
{{ end }}
|
||||
15
helm/templates/service.yaml
Normal file
15
helm/templates/service.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app: {{ .Release.Name }}
|
||||
name: {{ .Release.Name }}
|
||||
spec:
|
||||
ports:
|
||||
- port: 8000
|
||||
protocol: TCP
|
||||
name: {{ .Release.Name }}-web
|
||||
targetPort: 8000
|
||||
selector:
|
||||
app: {{ .Release.Name }} # This selects the pod(s) that match the selector
|
||||
type: ClusterIP
|
||||
2
helm/values.yaml
Normal file
2
helm/values.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
image: hub.ducoterra.net/ducoterra/button
|
||||
tag: 1.0.2
|
||||
@@ -1,21 +1,42 @@
|
||||
apiVersion: networking.k8s.io/v1beta1
|
||||
kind: Ingress
|
||||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: $DEPLOY-internal-tls
|
||||
annotations:
|
||||
ingress.kubernetes.io/ssl-redirect: "true"
|
||||
name: $DEPLOY
|
||||
kubernetes.io/ingress.class: traefik-internal
|
||||
spec:
|
||||
entryPoints:
|
||||
- websecure
|
||||
tls:
|
||||
- hosts:
|
||||
- $DEPLOY.ducoterra.net
|
||||
secretName: letsencrypt
|
||||
rules:
|
||||
- host: $DEPLOY.ducoterra.net
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
serviceName: $DEPLOY
|
||||
servicePort: 8000
|
||||
certResolver: myresolver
|
||||
domains:
|
||||
- main: "*.ducoterra.net"
|
||||
routes:
|
||||
- match: Host(`$DEPLOY.ducoterra.net`)
|
||||
kind: Rule
|
||||
services:
|
||||
- name: $DEPLOY
|
||||
port: 8000
|
||||
|
||||
---
|
||||
|
||||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: $DEPLOY-internal-web
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: traefik-internal
|
||||
spec:
|
||||
entryPoints:
|
||||
- web
|
||||
routes:
|
||||
- match: Host(`$DEPLOY.ducoterra.net`)
|
||||
kind: Rule
|
||||
services:
|
||||
- name: $DEPLOY
|
||||
port: 8000
|
||||
middlewares:
|
||||
- name: httpsredirect
|
||||
|
||||
---
|
||||
|
||||
@@ -23,11 +44,13 @@ apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: $DEPLOY-external-tls
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: traefik-external
|
||||
spec:
|
||||
entryPoints:
|
||||
- websecure
|
||||
tls:
|
||||
secretName: letsencrypt
|
||||
certResolver: myresolver
|
||||
routes:
|
||||
- match: Host(`$DEPLOY.ducoterra.net`)
|
||||
kind: Rule
|
||||
@@ -41,6 +64,8 @@ apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: $DEPLOY-external-web
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: traefik-external
|
||||
spec:
|
||||
entryPoints:
|
||||
- web
|
||||
|
||||
@@ -1,18 +1,39 @@
|
||||
apiVersion: networking.k8s.io/v1beta1
|
||||
kind: Ingress
|
||||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: $DEPLOY-internal-tls
|
||||
annotations:
|
||||
ingress.kubernetes.io/ssl-redirect: "true"
|
||||
name: $DEPLOY
|
||||
kubernetes.io/ingress.class: traefik-internal
|
||||
spec:
|
||||
entryPoints:
|
||||
- websecure
|
||||
tls:
|
||||
- hosts:
|
||||
- $DEPLOY.ducoterra.net
|
||||
secretName: letsencrypt
|
||||
rules:
|
||||
- host: $DEPLOY.ducoterra.net
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
serviceName: $DEPLOY
|
||||
servicePort: 8000
|
||||
certResolver: myresolver
|
||||
domains:
|
||||
- main: "*.ducoterra.net"
|
||||
routes:
|
||||
- match: Host(`$DEPLOY.ducoterra.net`)
|
||||
kind: Rule
|
||||
services:
|
||||
- name: $DEPLOY
|
||||
port: 8000
|
||||
|
||||
---
|
||||
|
||||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: $DEPLOY-internal-web
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: traefik-internal
|
||||
spec:
|
||||
entryPoints:
|
||||
- web
|
||||
routes:
|
||||
- match: Host(`$DEPLOY.ducoterra.net`)
|
||||
kind: Rule
|
||||
services:
|
||||
- name: $DEPLOY
|
||||
port: 8000
|
||||
middlewares:
|
||||
- name: httpsredirect
|
||||
@@ -2,4 +2,5 @@ django
|
||||
djangorestframework
|
||||
pygments
|
||||
gunicorn
|
||||
whitenoise
|
||||
whitenoise
|
||||
psycopg2-binary
|
||||
@@ -25,7 +25,7 @@ function add_achievement(text) {
|
||||
button.addEventListener("click", event => {
|
||||
button.disabled = true;
|
||||
button.classList.add("is-loading");
|
||||
fetch('/button/', {
|
||||
fetch(button.dataset.action, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<h1 class="title">
|
||||
The Button
|
||||
</h1>
|
||||
<button class="button is-danger" id="BUTTON">Press</button>
|
||||
<button class="button is-danger" id="BUTTON" data-action = "{% url 'button' %}">Press</button>
|
||||
</div>
|
||||
<div><br></div>
|
||||
<div>
|
||||
|
||||
10
ui/tests.py
10
ui/tests.py
@@ -13,28 +13,26 @@ class SimpleTest(TestCase):
|
||||
def test_button(self):
|
||||
# Test initial load
|
||||
c = Client()
|
||||
response = c.get('/button')
|
||||
self.assertEqual(response.status_code, 301)
|
||||
response = c.get('/button/')
|
||||
response = c.get('/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.context.get("achievement"), {})
|
||||
|
||||
# Test first achievement
|
||||
response = c.post('/button/', {})
|
||||
response = c.post('/', {})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json().get("pressed"), 1)
|
||||
self.assertEqual(response.json().get("achievement"), "Clicked!")
|
||||
self.assertEqual(c.session.get('pressed'), 1)
|
||||
|
||||
# Test second achievement
|
||||
response = c.post('/button/', {})
|
||||
response = c.post('/', {})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json().get("pressed"), 2)
|
||||
self.assertEqual(response.json().get("achievement"), "Clicked Twice!")
|
||||
self.assertEqual(c.session.get('pressed'), 2)
|
||||
|
||||
# Test no achievement
|
||||
response = c.post('/button/', {})
|
||||
response = c.post('/', {})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json().get("pressed"), 3)
|
||||
self.assertEqual(response.json().get("achievement"), None)
|
||||
|
||||
@@ -2,5 +2,5 @@ from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('button/', views.button, name = 'button'),
|
||||
path('', views.button, name = 'button'),
|
||||
]
|
||||
16
ui/views.py
16
ui/views.py
@@ -10,7 +10,6 @@ achievements = {
|
||||
24: "I'm that old",
|
||||
32: "2^5",
|
||||
64: "2^6",
|
||||
69: "Nice",
|
||||
100: "one hundred",
|
||||
128: "2^7",
|
||||
200: "two hundred",
|
||||
@@ -18,7 +17,6 @@ achievements = {
|
||||
256: "2^8",
|
||||
300: "three hundred",
|
||||
400: "four hundred",
|
||||
420: "Blaze it",
|
||||
500: "half thousand",
|
||||
512: "2^9",
|
||||
600: "six hundred",
|
||||
@@ -55,21 +53,17 @@ achievements = {
|
||||
def button(request):
|
||||
PRESSED = 'pressed'
|
||||
ACHIEVE = 'achievement'
|
||||
|
||||
try:
|
||||
request.session[PRESSED]
|
||||
except KeyError:
|
||||
request.session[PRESSED] = 0
|
||||
pressed = request.session.get(PRESSED, 0)
|
||||
|
||||
if request.method == "POST":
|
||||
request.session[PRESSED] += 1
|
||||
pressed = pressed + 1
|
||||
request.session[PRESSED] = pressed
|
||||
response = {
|
||||
PRESSED: request.session[PRESSED],
|
||||
ACHIEVE: achievements.get(request.session[PRESSED])
|
||||
PRESSED: pressed,
|
||||
ACHIEVE: achievements.get(pressed)
|
||||
}
|
||||
return JsonResponse(response)
|
||||
|
||||
pressed = request.session[PRESSED]
|
||||
response = {PRESSED: pressed}
|
||||
achieved = {k:v for k,v in achievements.items() if k <= pressed}
|
||||
response.update({ACHIEVE: achieved})
|
||||
|
||||
Reference in New Issue
Block a user