Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e66f3e2d2 | ||
|
|
b43927c384 | ||
|
|
11dc31660d | ||
|
|
438ae0fa93 | ||
|
|
f9017ad302 | ||
|
|
7bd7bde188 |
@@ -36,8 +36,6 @@ test:
|
|||||||
- python manage.py test
|
- python manage.py test
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
variables:
|
|
||||||
DEPLOY: test
|
|
||||||
stage: deploy
|
stage: deploy
|
||||||
only:
|
only:
|
||||||
variables:
|
variables:
|
||||||
@@ -51,5 +49,6 @@ deploy:
|
|||||||
- chmod +x /usr/bin/kubectl
|
- chmod +x /usr/bin/kubectl
|
||||||
- curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
|
- 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
|
- helm upgrade --install $DEPLOY ./helm --set image=$CI_REGISTRY_IMAGE --set tag=$CI_COMMIT_TAG
|
||||||
|
- sleep 10
|
||||||
- POD=$(kubectl get pods --selector=app=$DEPLOY --output=jsonpath='{.items[*].metadata.name}')
|
- POD=$(kubectl get pods --selector=app=$DEPLOY --output=jsonpath='{.items[*].metadata.name}')
|
||||||
- kubectl exec $POD -- python manage.py migrate
|
- kubectl exec $POD -- python manage.py migrate
|
||||||
13
Dockerfile
13
Dockerfile
@@ -1,4 +1,6 @@
|
|||||||
FROM python:3.8.2
|
FROM python:3
|
||||||
|
|
||||||
|
USER root
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY config config
|
COPY config config
|
||||||
@@ -8,10 +10,13 @@ COPY manage.py manage.py
|
|||||||
COPY requirements.txt requirements.txt
|
COPY requirements.txt requirements.txt
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
|
COPY scripts scripts
|
||||||
|
RUN chmod +x scripts/*
|
||||||
|
ENTRYPOINT ["scripts/entrypoint.sh"]
|
||||||
|
|
||||||
RUN useradd -ms /bin/bash django
|
RUN useradd -ms /bin/bash django
|
||||||
RUN chown -R django .
|
RUN chown -R django .
|
||||||
|
|
||||||
USER django
|
USER django
|
||||||
RUN python manage.py collectstatic
|
RUN python manage.py collectstatic --no-input
|
||||||
|
|
||||||
CMD ["gunicorn","-b",":8000", "-w", "4", "config.wsgi"]
|
CMD ["scripts/cmd.sh"]
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
My CI testing pipeline for a django project.
|
My CI testing pipeline for a django project.
|
||||||
|
|
||||||
[](http://gitlab.ducoterra.net/ducoterra/ci_builder/-/commits/master)
|
[](https://gitlab.ducoterra.net/ducoterra/ci_builder/-/commits/master)
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
version: '3.5'
|
version: '3'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
button:
|
button:
|
||||||
build: .
|
build: .
|
||||||
|
image: site:local
|
||||||
labels:
|
labels:
|
||||||
- "traefik.http.routers.button.rule=Host(`button.localhost`)"
|
- "traefik.http.routers.button.rule=Host(`button.localhost`)"
|
||||||
- "traefik.http.services.button-service.loadbalancer.server.port=8000"
|
- "traefik.http.services.button-service.loadbalancer.server.port=8000"
|
||||||
@@ -18,9 +19,9 @@ services:
|
|||||||
- SECRET_KEY=secret
|
- SECRET_KEY=secret
|
||||||
- ALLOWED_HOSTS=button.localhost
|
- ALLOWED_HOSTS=button.localhost
|
||||||
- DJANGO_SUPERUSER_PASSWORD=django
|
- DJANGO_SUPERUSER_PASSWORD=django
|
||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:12
|
image: postgres:13
|
||||||
volumes:
|
volumes:
|
||||||
- data:/var/lib/postgresql/data
|
- data:/var/lib/postgresql/data
|
||||||
environment:
|
environment:
|
||||||
@@ -29,19 +30,8 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- 5432:5432
|
- 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:
|
traefik:
|
||||||
image: traefik:v2.2
|
image: traefik:v2.4
|
||||||
labels:
|
labels:
|
||||||
- "traefik.http.routers.traefik.rule=Host(`traefik.localhost`)"
|
- "traefik.http.routers.traefik.rule=Host(`traefik.localhost`)"
|
||||||
- "traefik.http.services.traefik-service.loadbalancer.server.port=8080"
|
- "traefik.http.services.traefik-service.loadbalancer.server.port=8080"
|
||||||
@@ -53,4 +43,3 @@ services:
|
|||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
data:
|
data:
|
||||||
pgadmin:
|
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
image: hub.ducoterra.net/ducoterra/button
|
image: hub.ducoterra.net/ducoterra/button
|
||||||
tag: 1.0.2
|
tag: 1.0.2
|
||||||
|
secret: true
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: ConfigMap
|
|
||||||
metadata:
|
|
||||||
name: $DEPLOY
|
|
||||||
data:
|
|
||||||
ALLOWED_HOSTS: localhost,$DEPLOY.ducoterra.net
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: $DEPLOY
|
|
||||||
spec:
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: $DEPLOY
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: $DEPLOY
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: $DEPLOY
|
|
||||||
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
|
|
||||||
envFrom:
|
|
||||||
- configMapRef:
|
|
||||||
name: $DEPLOY
|
|
||||||
- secretRef:
|
|
||||||
name: django-secrets
|
|
||||||
volumeMounts:
|
|
||||||
- mountPath: /app/db
|
|
||||||
name: $DEPLOY
|
|
||||||
resources:
|
|
||||||
limits:
|
|
||||||
memory: "256Mi"
|
|
||||||
cpu: "250m"
|
|
||||||
requests:
|
|
||||||
memory: "1Mi"
|
|
||||||
cpu: "1m"
|
|
||||||
ports:
|
|
||||||
- containerPort: 8000
|
|
||||||
volumes:
|
|
||||||
- name: $DEPLOY
|
|
||||||
persistentVolumeClaim:
|
|
||||||
claimName: $DEPLOY
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
apiVersion: traefik.containo.us/v1alpha1
|
|
||||||
kind: IngressRoute
|
|
||||||
metadata:
|
|
||||||
name: $DEPLOY-internal-tls
|
|
||||||
annotations:
|
|
||||||
kubernetes.io/ingress.class: traefik-internal
|
|
||||||
spec:
|
|
||||||
entryPoints:
|
|
||||||
- websecure
|
|
||||||
tls:
|
|
||||||
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
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
apiVersion: traefik.containo.us/v1alpha1
|
|
||||||
kind: IngressRoute
|
|
||||||
metadata:
|
|
||||||
name: $DEPLOY-external-tls
|
|
||||||
annotations:
|
|
||||||
kubernetes.io/ingress.class: traefik-external
|
|
||||||
spec:
|
|
||||||
entryPoints:
|
|
||||||
- websecure
|
|
||||||
tls:
|
|
||||||
certResolver: myresolver
|
|
||||||
routes:
|
|
||||||
- match: Host(`$DEPLOY.ducoterra.net`)
|
|
||||||
kind: Rule
|
|
||||||
services:
|
|
||||||
- name: $DEPLOY
|
|
||||||
port: 8000
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
apiVersion: traefik.containo.us/v1alpha1
|
|
||||||
kind: IngressRoute
|
|
||||||
metadata:
|
|
||||||
name: $DEPLOY-external-web
|
|
||||||
annotations:
|
|
||||||
kubernetes.io/ingress.class: traefik-external
|
|
||||||
spec:
|
|
||||||
entryPoints:
|
|
||||||
- web
|
|
||||||
routes:
|
|
||||||
- match: Host(`$DEPLOY.ducoterra.net`)
|
|
||||||
kind: Rule
|
|
||||||
services:
|
|
||||||
- name: $DEPLOY
|
|
||||||
port: 8000
|
|
||||||
middlewares:
|
|
||||||
- name: httpsredirect
|
|
||||||
11
k8s/pvc.yaml
11
k8s/pvc.yaml
@@ -1,11 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolumeClaim
|
|
||||||
metadata:
|
|
||||||
name: $DEPLOY
|
|
||||||
spec:
|
|
||||||
storageClassName: nfs-encrypted
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 8Gi
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
name: $DEPLOY
|
|
||||||
spec:
|
|
||||||
selector:
|
|
||||||
app: $DEPLOY
|
|
||||||
ports:
|
|
||||||
- port: 8000
|
|
||||||
targetPort: 8000
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
apiVersion: traefik.containo.us/v1alpha1
|
|
||||||
kind: IngressRoute
|
|
||||||
metadata:
|
|
||||||
name: $DEPLOY-internal-tls
|
|
||||||
annotations:
|
|
||||||
kubernetes.io/ingress.class: traefik-internal
|
|
||||||
spec:
|
|
||||||
entryPoints:
|
|
||||||
- websecure
|
|
||||||
tls:
|
|
||||||
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
|
|
||||||
3
scripts/cmd.sh
Normal file
3
scripts/cmd.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
gunicorn -b :8000 -w 4 config.wsgi
|
||||||
22
scripts/entrypoint.sh
Executable file
22
scripts/entrypoint.sh
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if ! $SKIP_ENTRYPOINT || [ -z $SKIP_ENTRYPOINT ]; then
|
||||||
|
|
||||||
|
MIGRATED=false
|
||||||
|
|
||||||
|
while ! $MIGRATED; do
|
||||||
|
echo "Migrating..."
|
||||||
|
python manage.py migrate 2> /dev/null
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
MIGRATED=true
|
||||||
|
else
|
||||||
|
echo "ERROR - $(date) - Migrate failed."
|
||||||
|
sleep 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
$@
|
||||||
Reference in New Issue
Block a user