Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
477ddfe165 | ||
|
|
6bc472f7fe | ||
|
|
41f4549ffd | ||
|
|
7dd45cc2e8 | ||
|
|
8ec174b2c3 | ||
|
|
7868867908 | ||
|
|
d2bf889e1f | ||
|
|
a70aa8840f | ||
|
|
8404d43222 | ||
|
|
f31106dd29 | ||
|
|
fbd8b0e2a7 | ||
|
|
b04ef5a579 | ||
|
|
e01bf28646 | ||
|
|
f362194c5e | ||
|
|
bdc4c90705 | ||
|
|
b309e5fa4a | ||
|
|
a6127703e9 | ||
|
|
6be7034f9b | ||
|
|
1adaf20f61 | ||
|
|
c32ed88713 |
@@ -36,15 +36,14 @@ deploy:
|
||||
- $CI_COMMIT_TAG
|
||||
stage: deploy
|
||||
image:
|
||||
name: debian:latest
|
||||
name: debian:10
|
||||
entrypoint: [""]
|
||||
script:
|
||||
- echo $CI_REGISTRY_IMAGE
|
||||
- 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
|
||||
- envsubst < k8s/deploy.yaml > out.yaml
|
||||
- mv out.yaml k8s/deploy.yaml
|
||||
- ./kubectl apply -f k8s
|
||||
- mkdir /deploy
|
||||
- for f in $(find k8s -regex '.*\\.ya*ml'); do envsubst < $f > "/deploy/$(basename $f)"; done'
|
||||
- ./kubectl apply -f /deploy
|
||||
- ./kubectl rollout status deploy $DEPLOY
|
||||
- ./kubectl exec $(./kubectl get pods --selector=app=$DEPLOY --output=jsonpath='{.items[*].metadata.name}') -- python manage.py migrate
|
||||
@@ -8,4 +8,10 @@ COPY manage.py manage.py
|
||||
COPY requirements.txt requirements.txt
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
RUN useradd -ms /bin/bash django
|
||||
RUN chown -R django .
|
||||
|
||||
USER django
|
||||
RUN python manage.py collectstatic
|
||||
|
||||
CMD ["gunicorn","-b",":8000", "-w", "4", "config.wsgi"]
|
||||
24
README.md
Normal file
24
README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# CI Builder
|
||||
|
||||
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
|
||||
```
|
||||
@@ -20,13 +20,12 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'b8fi9=f-qj=@-#1iru34-f@a6pzfysgrf(1n_&d=ur%!1w$q*w'
|
||||
SECRET_KEY = os.getenv("SECRET_KEY")
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ["localhost", "test.ducoterra.net"]
|
||||
DEBUG = True if os.getenv("DEBUG") == "True" else False
|
||||
|
||||
ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS", "localhost").split(",")
|
||||
|
||||
# Application definition
|
||||
|
||||
@@ -122,3 +121,4 @@ USE_TZ = True
|
||||
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||
6
k8s/configmap.yaml
Normal file
6
k8s/configmap.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: $DEPLOY
|
||||
data:
|
||||
ALLOWED_HOSTS: localhost,test.ducoterra.net
|
||||
@@ -1,22 +1,25 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: test
|
||||
name: $DEPLOY
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: test
|
||||
app: $DEPLOY
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: test
|
||||
app: $DEPLOY
|
||||
spec:
|
||||
containers:
|
||||
- name: test
|
||||
- name: $DEPLOY
|
||||
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: gitlab
|
||||
volumeMounts:
|
||||
- mountPath: /app/db
|
||||
name: test
|
||||
name: $DEPLOY
|
||||
resources:
|
||||
limits:
|
||||
memory: "256Mi"
|
||||
@@ -27,6 +30,6 @@ spec:
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
volumes:
|
||||
- name: test
|
||||
- name: $DEPLOY
|
||||
persistentVolumeClaim:
|
||||
claimName: test
|
||||
claimName: $DEPLOY
|
||||
@@ -3,7 +3,7 @@ kind: Ingress
|
||||
metadata:
|
||||
annotations:
|
||||
ingress.kubernetes.io/ssl-redirect: "true"
|
||||
name: test
|
||||
name: $DEPLOY
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
@@ -14,5 +14,41 @@ spec:
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
serviceName: test
|
||||
servicePort: 8000
|
||||
serviceName: $DEPLOY
|
||||
servicePort: 8000
|
||||
|
||||
---
|
||||
|
||||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: $DEPLOY-external-tls
|
||||
spec:
|
||||
entryPoints:
|
||||
- websecure
|
||||
tls:
|
||||
secretName: letsencrypt
|
||||
routes:
|
||||
- match: Host(`test.ducoterra.net`)
|
||||
kind: Rule
|
||||
services:
|
||||
- name: $DEPLOY
|
||||
port: 8000
|
||||
|
||||
---
|
||||
|
||||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: $DEPLOY-external-web
|
||||
spec:
|
||||
entryPoints:
|
||||
- web
|
||||
routes:
|
||||
- match: Host(`test.ducoterra.net`)
|
||||
kind: Rule
|
||||
services:
|
||||
- name: $DEPLOY
|
||||
port: 8000
|
||||
middlewares:
|
||||
- name: httpsredirect
|
||||
@@ -1,7 +1,7 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: test
|
||||
name: $DEPLOY
|
||||
spec:
|
||||
storageClassName: nfs-encrypted
|
||||
accessModes:
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: test
|
||||
name: $DEPLOY
|
||||
spec:
|
||||
selector:
|
||||
app: test
|
||||
app: $DEPLOY
|
||||
ports:
|
||||
- port: 8000
|
||||
targetPort: 8000
|
||||
@@ -5,6 +5,8 @@ import sys
|
||||
|
||||
|
||||
def main():
|
||||
os.environ.setdefault('DEBUG', 'True')
|
||||
os.environ.setdefault('SECRET_KEY', 'SeVOOxOHISQZv82RfCPds0B2l8M6jGju4G8F-GcuSrc')
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
0
ui/static/ui/button.css
Normal file
0
ui/static/ui/button.css
Normal file
@@ -19,6 +19,7 @@ var button = document.getElementById("BUTTON");
|
||||
var count = document.getElementById("COUNT");
|
||||
|
||||
button.addEventListener("click", event => {
|
||||
button.disabled = true;
|
||||
fetch('/button', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -31,6 +32,8 @@ button.addEventListener("click", event => {
|
||||
})
|
||||
.then((data) => {
|
||||
count.innerText = data.pressed;
|
||||
}).finally(() => {
|
||||
button.disabled = false;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
24
ui/templates/ui/base.html
Normal file
24
ui/templates/ui/base.html
Normal file
@@ -0,0 +1,24 @@
|
||||
{% load static %}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>The Button</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.8.2/css/bulma.min.css">
|
||||
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
|
||||
{% block css %}
|
||||
{% endblock %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% csrf_token %}
|
||||
|
||||
{% block body %}
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
@@ -1,33 +1,29 @@
|
||||
{% extends 'ui/base.html' %}
|
||||
|
||||
{% load static %}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{% static 'ui/button.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Hello Bulma!</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.8.2/css/bulma.min.css">
|
||||
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
|
||||
</head>
|
||||
{% block js %}
|
||||
<script src="{% static 'ui/button.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
<body>
|
||||
{% csrf_token %}
|
||||
<section class="section">
|
||||
<div class="container">
|
||||
<div>
|
||||
<h1 class="title">
|
||||
The Button
|
||||
</h1>
|
||||
<button class="button" id="BUTTON">Press</button>
|
||||
</div>
|
||||
<div><br></div>
|
||||
<div>
|
||||
<h1 class="title" id="COUNT">{{ pressed }}</h1>
|
||||
</div>
|
||||
|
||||
{% block body %}
|
||||
<section class="section">
|
||||
<div class="container">
|
||||
<div>
|
||||
<h1 class="title">
|
||||
The Button
|
||||
</h1>
|
||||
<button class="button is-primary" id="BUTTON">Press</button>
|
||||
</div>
|
||||
</section>
|
||||
<script src="{% static 'ui/button.js' %}"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<div><br></div>
|
||||
<div>
|
||||
<h1 class="title" id="COUNT">{{ pressed }}</h1>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
@@ -9,6 +9,6 @@ def button(request):
|
||||
request.session[PRESSED] = 0
|
||||
|
||||
if request.method == "POST":
|
||||
request.session[PRESSED] += 2
|
||||
request.session[PRESSED] += 1
|
||||
return JsonResponse({PRESSED: request.session[PRESSED]})
|
||||
return render(request, "ui/button.html", {PRESSED: request.session[PRESSED]})
|
||||
Reference in New Issue
Block a user