Compare commits

...

6 Commits

Author SHA1 Message Date
ducoterra
4e66f3e2d2 Greatly simplify docker-compose.yaml
Remove pgadmin and specific version for compose
2021-03-24 09:16:36 -06:00
ducoterra
b43927c384 Perfect the entrypoint
Previously unexplored entrypoint technology has been explored. Now we
can run commands after the entrypoint completes with the magical "$@"
variable.
2021-03-24 09:15:29 -06:00
ducoterra
11dc31660d fix https issue with pipeline tag 2020-10-13 12:27:03 -04:00
ducoterra
438ae0fa93 don't overwrite deploy name 2020-10-12 17:23:07 -04:00
ducoterra
f9017ad302 sleep for pod to spin up 2020-10-12 16:55:24 -04:00
ducoterra
7bd7bde188 add secret true to values 2020-10-12 16:46:51 -04:00
13 changed files with 43 additions and 206 deletions

View File

@@ -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

View File

@@ -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"]

View File

@@ -2,4 +2,4 @@
My CI testing pipeline for a django project. My CI testing pipeline for a django project.
[![pipeline status](http://gitlab.ducoterra.net/ducoterra/ci_builder/badges/master/pipeline.svg)](http://gitlab.ducoterra.net/ducoterra/ci_builder/-/commits/master) [![pipeline status](https://gitlab.ducoterra.net/ducoterra/ci_builder/badges/master/pipeline.svg)](https://gitlab.ducoterra.net/ducoterra/ci_builder/-/commits/master)

View File

@@ -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:

View File

@@ -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

View File

@@ -1,6 +0,0 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: $DEPLOY
data:
ALLOWED_HOSTS: localhost,$DEPLOY.ducoterra.net

View File

@@ -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

View File

@@ -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

View File

@@ -1,11 +0,0 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: $DEPLOY
spec:
storageClassName: nfs-encrypted
accessModes:
- ReadWriteMany
resources:
requests:
storage: 8Gi

View File

@@ -1,10 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: $DEPLOY
spec:
selector:
app: $DEPLOY
ports:
- port: 8000
targetPort: 8000

View File

@@ -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
View File

@@ -0,0 +1,3 @@
#!/bin/bash
gunicorn -b :8000 -w 4 config.wsgi

22
scripts/entrypoint.sh Executable file
View 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
$@