Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c80ef7441d | ||
|
|
a2e7a92280 | ||
|
|
b4ef050e1f | ||
|
|
c09558c0ff | ||
|
|
c3666783e4 | ||
|
|
54c6336e22 | ||
|
|
7da888aa09 | ||
|
|
07d98bf11d | ||
|
|
4584ba0143 | ||
|
|
6feac7ef2e | ||
|
|
5efb93ea68 | ||
|
|
1ee6b890ef | ||
|
|
18aab648c6 | ||
|
|
57328a7fc8 | ||
|
|
948569a659 | ||
|
|
50cdfd8180 |
@@ -1,7 +1,6 @@
|
||||
variables:
|
||||
CI_PROJECT_DIR: "."
|
||||
CI_REGISTRY_IMAGE: hub.ducoterra.net/ducoterra/mysite
|
||||
DEPLOY: test
|
||||
|
||||
stages:
|
||||
- build
|
||||
@@ -17,24 +16,27 @@ 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
|
||||
only:
|
||||
variables:
|
||||
- $CI_COMMIT_TAG
|
||||
stage: test
|
||||
image:
|
||||
name: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
|
||||
entrypoint: [""]
|
||||
script:
|
||||
- python manage.py test
|
||||
|
||||
deploy:
|
||||
deploy_to_test:
|
||||
variables:
|
||||
DEPLOY: test
|
||||
stage: deploy
|
||||
only:
|
||||
variables:
|
||||
- $CI_COMMIT_TAG
|
||||
stage: deploy
|
||||
image:
|
||||
name: debian:10
|
||||
entrypoint: [""]
|
||||
@@ -44,6 +46,31 @@ deploy:
|
||||
- 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
|
||||
- ./kubectl exec $(./kubectl get pods --selector=app=$DEPLOY --output=jsonpath='{.items[*].metadata.name}') -- python manage.py migrate
|
||||
- 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
|
||||
- POD=$(./kubectl get pods --selector=app=$DEPLOY --output=jsonpath='{.items[*].metadata.name}')
|
||||
- ./kubectl exec $POD -- python manage.py migrate
|
||||
13
.vscode/launch.json
vendored
13
.vscode/launch.json
vendored
@@ -5,7 +5,7 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: Django",
|
||||
"name": "Test",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/manage.py",
|
||||
@@ -13,6 +13,17 @@
|
||||
"test",
|
||||
],
|
||||
"django": true
|
||||
},
|
||||
{
|
||||
"name": "Run Server",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/manage.py",
|
||||
"args": [
|
||||
"runserver",
|
||||
"--noreload"
|
||||
],
|
||||
"django": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -18,7 +18,7 @@ from django.urls import path, include
|
||||
from django.http import JsonResponse
|
||||
|
||||
urlpatterns = [
|
||||
path('', include('api.urls')),
|
||||
# path('api/', include('api.urls')),
|
||||
path('', include('ui.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
# path('admin/', admin.site.urls),
|
||||
]
|
||||
|
||||
@@ -3,4 +3,4 @@ kind: ConfigMap
|
||||
metadata:
|
||||
name: $DEPLOY
|
||||
data:
|
||||
ALLOWED_HOSTS: localhost,test.ducoterra.net
|
||||
ALLOWED_HOSTS: localhost,$DEPLOY.ducoterra.net
|
||||
@@ -16,7 +16,9 @@ spec:
|
||||
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: gitlab
|
||||
name: $DEPLOY
|
||||
- secretRef:
|
||||
name: django-secrets
|
||||
volumeMounts:
|
||||
- mountPath: /app/db
|
||||
name: $DEPLOY
|
||||
|
||||
@@ -7,10 +7,10 @@ metadata:
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- test.ducoterra.net
|
||||
- $DEPLOY.ducoterra.net
|
||||
secretName: letsencrypt
|
||||
rules:
|
||||
- host: test.ducoterra.net
|
||||
- host: $DEPLOY.ducoterra.net
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
@@ -29,7 +29,7 @@ spec:
|
||||
tls:
|
||||
secretName: letsencrypt
|
||||
routes:
|
||||
- match: Host(`test.ducoterra.net`)
|
||||
- match: Host(`$DEPLOY.ducoterra.net`)
|
||||
kind: Rule
|
||||
services:
|
||||
- name: $DEPLOY
|
||||
@@ -45,7 +45,7 @@ spec:
|
||||
entryPoints:
|
||||
- web
|
||||
routes:
|
||||
- match: Host(`test.ducoterra.net`)
|
||||
- match: Host(`$DEPLOY.ducoterra.net`)
|
||||
kind: Rule
|
||||
services:
|
||||
- name: $DEPLOY
|
||||
18
k8s/test/ingress.yaml
Normal file
18
k8s/test/ingress.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
apiVersion: networking.k8s.io/v1beta1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
annotations:
|
||||
ingress.kubernetes.io/ssl-redirect: "true"
|
||||
name: $DEPLOY
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- $DEPLOY.ducoterra.net
|
||||
secretName: letsencrypt
|
||||
rules:
|
||||
- host: $DEPLOY.ducoterra.net
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
serviceName: $DEPLOY
|
||||
servicePort: 8000
|
||||
@@ -1,8 +1,17 @@
|
||||
html, body {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
.section, .container {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
@@ -1,26 +1,12 @@
|
||||
function getCookie(name) {
|
||||
var cookieValue = null;
|
||||
if (document.cookie && document.cookie !== '') {
|
||||
var cookies = document.cookie.split(';');
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
var cookie = cookies[i].trim();
|
||||
// Does this cookie string begin with the name we want?
|
||||
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
|
||||
var csrftoken = getCookie('csrftoken');
|
||||
var button = document.getElementById("BUTTON");
|
||||
var count = document.getElementById("COUNT");
|
||||
const csrftoken = getCookie('csrftoken');
|
||||
const button = document.getElementById("BUTTON");
|
||||
const count = document.getElementById("COUNT");
|
||||
|
||||
// when button is clicked submit an empty post request
|
||||
button.addEventListener("click", event => {
|
||||
button.disabled = true;
|
||||
fetch('/button', {
|
||||
button.classList.add("is-loading");
|
||||
fetch('/button/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -34,7 +20,9 @@ button.addEventListener("click", event => {
|
||||
count.innerText = data.pressed;
|
||||
}).finally(() => {
|
||||
button.disabled = false;
|
||||
button.classList.remove("is-loading");
|
||||
});
|
||||
});
|
||||
|
||||
// when the page is loaded automatically select the button
|
||||
button.focus();
|
||||
16
ui/static/ui/helper.js
Normal file
16
ui/static/ui/helper.js
Normal file
@@ -0,0 +1,16 @@
|
||||
// get cookies when fetching with django
|
||||
function getCookie(name) {
|
||||
var cookieValue = null;
|
||||
if (document.cookie && document.cookie !== '') {
|
||||
var cookies = document.cookie.split(';');
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
var cookie = cookies[i].trim();
|
||||
// Does this cookie string begin with the name we want?
|
||||
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="viewport" content= "width=device-width, user-scalable=no">
|
||||
<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>
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script src="{% static 'ui/helper.js' %}"></script>
|
||||
<script src="{% static 'ui/button.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block body %}
|
||||
<section class="section">
|
||||
<div class="container">
|
||||
|
||||
@@ -2,5 +2,5 @@ from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('button', views.button, name = 'button'),
|
||||
path('button/', views.button, name = 'button'),
|
||||
]
|
||||
Reference in New Issue
Block a user