diff --git a/.k8s/base/api/deployment.yaml b/.k8s/base/api/deployment.yaml new file mode 100644 index 000000000..f40529865 --- /dev/null +++ b/.k8s/base/api/deployment.yaml @@ -0,0 +1,56 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: api +spec: + replicas: 1 + template: + spec: + initContainers: + - name: migrations + image: learninglocker + args: [migrations] + envFrom: + - configMapRef: + name: learninglocker-config + - secretRef: + name: learninglocker-secret + env: + - name: MONGO_HOST + value: $(LEARNINGLOCKER_MONGO_SERVICE) + + - name: seeds + image: learninglocker + args: [seeds] + envFrom: + - configMapRef: + name: learninglocker-config + - secretRef: + name: learninglocker-secret + env: + - name: MONGO_HOST + value: $(LEARNINGLOCKER_MONGO_SERVICE) + + containers: + - name: api + image: learninglocker + args: [api] + envFrom: + - configMapRef: + name: learninglocker-config + - secretRef: + name: learninglocker-secret + env: + - name: PATH_PREFIX + value: "/api" + - name: REDIS_HOST + value: $(LEARNINGLOCKER_REDIS_SERVICE) + - name: MONGO_HOST + value: $(LEARNINGLOCKER_MONGO_SERVICE) + ports: + - containerPort: 8080 + protocol: TCP + livenessProbe: + httpGet: + path: /api/ + port: 8080 diff --git a/.k8s/base/api/kustomization.yaml b/.k8s/base/api/kustomization.yaml new file mode 100644 index 000000000..44fd42f97 --- /dev/null +++ b/.k8s/base/api/kustomization.yaml @@ -0,0 +1,12 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +labels: +- pairs: + app.kubernetes.io/component: api + includeSelectors: true + includeTemplates: true + +resources: +- deployment.yaml +- service.yaml diff --git a/.k8s/base/api/service.yaml b/.k8s/base/api/service.yaml new file mode 100644 index 000000000..e3002db95 --- /dev/null +++ b/.k8s/base/api/service.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Service +metadata: + name: api +spec: + ports: + - name: http + port: 80 + targetPort: 8080 diff --git a/.k8s/base/ingress.yaml b/.k8s/base/ingress.yaml new file mode 100644 index 000000000..209f59036 --- /dev/null +++ b/.k8s/base/ingress.yaml @@ -0,0 +1,38 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: learninglocker + annotations: + kubernetes.io/tls-acme: "true" + cert-manager.io/cluster-issuer: letsencrypt-prod + traefik.ingress.kubernetes.io/redirect-entry-point: https +spec: + rules: + - host: $(LEARNINGLOCKER_FQDN) + http: + paths: + - pathType: Prefix + path: /api + backend: + service: + name: api + port: + name: http + - pathType: Prefix + path: /data + backend: + service: + name: xapi-service + port: + name: http + - pathType: Prefix + path: / + backend: + service: + name: ui + port: + name: http + tls: + - hosts: + - $(LEARNINGLOCKER_FQDN) + secretName: learninglocker-tls-crt diff --git a/.k8s/base/kustomization.yaml b/.k8s/base/kustomization.yaml new file mode 100644 index 000000000..92fa1d959 --- /dev/null +++ b/.k8s/base/kustomization.yaml @@ -0,0 +1,68 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namePrefix: learninglocker- +labels: +- pairs: + app.kubernetes.io/name: learninglocker + includeSelectors: true + includeTemplates: true + +resources: +- api +- mongo +- redis +- ui +- worker +- xapi-service +- ingress.yaml + +configMapGenerator: +- name: learninglocker-ingress + literals: + - host=example.org + +- name: learninglocker-config + literals: + - LOG_MIN_LEVEL=warning + - QUEUE_PROVIDER=REDIS + - MONGO_DATABASE=learninglocker_v2 + - UI_HOST=ui + - UI_PORT=3000 + - API_HOST=api + - API_PORT=8080 + # - SITE_URL=http://example.org + # - SMTP_HOST="" + # - SMTP_PORT="" + # - SMTP_SECURED="" + # - SMTP_USER="" + +secretGenerator: +- name: learninglocker-secret + literals: [] + # - APP_SECRET="i-am-not-secure-please-change-me" + # - SMTP_PASS="" + # - LL_ADMIN_EMAIL="" + # - LL_ADMIN_ORG="" + # - LL_ADMIN_PASSWORD="" + +vars: +- name: LEARNINGLOCKER_FQDN + objref: + apiVersion: v1 + kind: ConfigMap + name: learninglocker-ingress + fieldref: + fieldpath: data.host + +images: +- name: learninglocker + newName: ghcr.io/ude-soco/learninglocker + newTag: master +- name: redis + newTag: '7' +- name: mongo + newTag: '4.4' +- name: xapi-service + newName: learninglocker/xapi-service + diff --git a/.k8s/base/mongo/deployment.yaml b/.k8s/base/mongo/deployment.yaml new file mode 100644 index 000000000..210586d90 --- /dev/null +++ b/.k8s/base/mongo/deployment.yaml @@ -0,0 +1,36 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mongo +spec: + replicas: 1 + strategy: + type: Recreate + template: + spec: + containers: + - name: mongo + image: mongo + args: + - --bind_ip + - "0.0.0.0" + - --wiredTigerCacheSizeGB + - "0.25" + - --quiet + ports: + - containerPort: 27017 + protocol: TCP + volumeMounts: + - mountPath: /data/db + name: mongo + livenessProbe: + exec: + command: + - mongo + - --disableImplicitSessions + - --eval + - "db.adminCommand('ping')" + volumes: + - name: mongo + persistentVolumeClaim: + claimName: mongo diff --git a/.k8s/base/mongo/kustomization.yaml b/.k8s/base/mongo/kustomization.yaml new file mode 100644 index 000000000..7bf93592b --- /dev/null +++ b/.k8s/base/mongo/kustomization.yaml @@ -0,0 +1,20 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +labels: +- pairs: + service: mongo + includeSelectors: true + includeTemplates: true + +resources: +- deployment.yaml +- pvc.yaml +- service.yaml + +vars: +- name: LEARNINGLOCKER_MONGO_SERVICE + objref: + apiVersion: v1 + kind: Service + name: mongo diff --git a/.k8s/base/mongo/pvc.yaml b/.k8s/base/mongo/pvc.yaml new file mode 100644 index 000000000..b9e17fed7 --- /dev/null +++ b/.k8s/base/mongo/pvc.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: mongo +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Mi diff --git a/.k8s/base/mongo/service.yaml b/.k8s/base/mongo/service.yaml new file mode 100644 index 000000000..a12f484d6 --- /dev/null +++ b/.k8s/base/mongo/service.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Service +metadata: + name: mongo +spec: + ports: + - name: mongo + port: 27017 + targetPort: 27017 diff --git a/.k8s/base/redis/deployment.yaml b/.k8s/base/redis/deployment.yaml new file mode 100644 index 000000000..bcf709c45 --- /dev/null +++ b/.k8s/base/redis/deployment.yaml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redis +spec: + replicas: 1 + template: + spec: + containers: + - name: redis + image: redis + args: + - --loglevel + - warning + livenessProbe: + exec: + command: + - redis-cli + - ping + initialDelaySeconds: 2 + periodSeconds: 10 + ports: + - containerPort: 6379 + protocol: TCP + volumeMounts: + - mountPath: /data + name: redis + volumes: + - name: redis + persistentVolumeClaim: + claimName: redis diff --git a/.k8s/base/redis/kustomization.yaml b/.k8s/base/redis/kustomization.yaml new file mode 100644 index 000000000..a8251d926 --- /dev/null +++ b/.k8s/base/redis/kustomization.yaml @@ -0,0 +1,20 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +labels: +- pairs: + service: redis + includeSelectors: true + includeTemplates: true + +resources: +- deployment.yaml +- pvc.yaml +- service.yaml + +vars: +- name: LEARNINGLOCKER_REDIS_SERVICE + objref: + apiVersion: v1 + kind: Service + name: redis diff --git a/.k8s/base/redis/pvc.yaml b/.k8s/base/redis/pvc.yaml new file mode 100644 index 000000000..db3fa0d11 --- /dev/null +++ b/.k8s/base/redis/pvc.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: redis +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Mi diff --git a/.k8s/base/redis/service.yaml b/.k8s/base/redis/service.yaml new file mode 100644 index 000000000..82376d8d9 --- /dev/null +++ b/.k8s/base/redis/service.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Service +metadata: + name: redis +spec: + ports: + - name: redis + port: 6379 + targetPort: 6379 diff --git a/.k8s/base/ui/deployment.yaml b/.k8s/base/ui/deployment.yaml new file mode 100644 index 000000000..dd6633c32 --- /dev/null +++ b/.k8s/base/ui/deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ui +spec: + replicas: 1 + template: + spec: + containers: + - name: ui + image: learninglocker + args: + - ui + envFrom: + - configMapRef: + name: learninglocker-config + - secretRef: + name: learninglocker-secret + env: + - name: REDIS_HOST + value: $(LEARNINGLOCKER_REDIS_SERVICE) + - name: MONGO_HOST + value: $(LEARNINGLOCKER_MONGO_SERVICE) + ports: + - containerPort: 3000 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: 3000 + initialDelaySeconds: 15 + periodSeconds: 30 \ No newline at end of file diff --git a/.k8s/base/ui/kustomization.yaml b/.k8s/base/ui/kustomization.yaml new file mode 100644 index 000000000..0644ba44d --- /dev/null +++ b/.k8s/base/ui/kustomization.yaml @@ -0,0 +1,12 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +labels: +- pairs: + app.kubernetes.io/component: ui + includeSelectors: true + includeTemplates: true + +resources: +- deployment.yaml +- service.yaml diff --git a/.k8s/base/ui/service.yaml b/.k8s/base/ui/service.yaml new file mode 100644 index 000000000..7b3369595 --- /dev/null +++ b/.k8s/base/ui/service.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Service +metadata: + name: ui +spec: + ports: + - name: http + port: 80 + targetPort: 3000 diff --git a/.k8s/base/worker/deployment.yaml b/.k8s/base/worker/deployment.yaml new file mode 100644 index 000000000..641e9b92f --- /dev/null +++ b/.k8s/base/worker/deployment.yaml @@ -0,0 +1,23 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: worker +spec: + replicas: 1 + template: + spec: + containers: + - name: worker + image: learninglocker + args: + - worker + envFrom: + - configMapRef: + name: learninglocker-config + - secretRef: + name: learninglocker-secret + env: + - name: REDIS_HOST + value: $(LEARNINGLOCKER_REDIS_SERVICE) + - name: MONGO_HOST + value: $(LEARNINGLOCKER_MONGO_SERVICE) diff --git a/.k8s/base/worker/kustomization.yaml b/.k8s/base/worker/kustomization.yaml new file mode 100644 index 000000000..07133b6ab --- /dev/null +++ b/.k8s/base/worker/kustomization.yaml @@ -0,0 +1,11 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +labels: +- pairs: + app.kubernetes.io/name: worker + includeSelectors: true + includeTemplates: true + +resources: +- deployment.yaml diff --git a/.k8s/base/xapi-service/deployment.yaml b/.k8s/base/xapi-service/deployment.yaml new file mode 100644 index 000000000..89977d8e4 --- /dev/null +++ b/.k8s/base/xapi-service/deployment.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: xapi-service +spec: + replicas: 1 + template: + spec: + containers: + - name: xapi-service + image: xapi-service + env: + - name: MODELS_REPO + value: mongo + - name: MONGO_URL + value: mongodb://$(LEARNINGLOCKER_MONGO_SERVICE):27017/learninglocker_v2 + - name: REDIS_URL + value: redis://$(LEARNINGLOCKER_REDIS_SERVICE):6379/0 + - name: EXPRESS_PORT + value: "8081" + - name: FS_LOCAL_STORAGE_DIR + value: /var/xapi-service + - name: WINSTON_CONSOLE_LEVEL + value: error + - name: XAPI_PREFIX + value: /data + ports: + - containerPort: 8081 + protocol: TCP + livenessProbe: + httpGet: + path: /data/xAPI/about + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 30 + volumeMounts: + - mountPath: /var/xapi-service + name: xapi-service + volumes: + - name: xapi-service + persistentVolumeClaim: + claimName: xapi-service diff --git a/.k8s/base/xapi-service/kustomization.yaml b/.k8s/base/xapi-service/kustomization.yaml new file mode 100644 index 000000000..6beca1687 --- /dev/null +++ b/.k8s/base/xapi-service/kustomization.yaml @@ -0,0 +1,13 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +labels: +- pairs: + app.kubernetes.io/component: xapi-service + includeSelectors: true + includeTemplates: true + +resources: +- deployment.yaml +- pvc.yaml +- service.yaml diff --git a/.k8s/base/xapi-service/pvc.yaml b/.k8s/base/xapi-service/pvc.yaml new file mode 100644 index 000000000..4f8feae82 --- /dev/null +++ b/.k8s/base/xapi-service/pvc.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: xapi-service +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Mi diff --git a/.k8s/base/xapi-service/service.yaml b/.k8s/base/xapi-service/service.yaml new file mode 100644 index 000000000..41f84a368 --- /dev/null +++ b/.k8s/base/xapi-service/service.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Service +metadata: + name: xapi-service +spec: + ports: + - name: http + port: 80 + targetPort: 8081 diff --git a/bin/entrypoint b/bin/entrypoint index 81d1682fc..ef08990be 100755 --- a/bin/entrypoint +++ b/bin/entrypoint @@ -1,10 +1,14 @@ #!/usr/bin/env sh set -eu -MONGO_HOST="${MONGO_HOST:-localhost}" -MONGO_PORT="${MONGO_PORT:-27017}" -MONGO_DATABASE="${MONGO_DATABASE:-learninglocker_v2}" -export MONGODB_PATH="mongodb://${MONGO_HOST}:${MONGO_PORT}/${MONGO_DATABASE}" +if [ -n "${MONGO_URL:-}" ]; then + export MONGODB_PATH="${MONGO_URL}" +else + MONGO_HOST="${MONGO_HOST:?MONGO_HOST missing}" + MONGO_PORT="${MONGO_PORT:-27017}" + MONGO_DATABASE="${MONGO_DATABASE:?MONGO_DATABASE missing}" + export MONGODB_PATH="mongodb://${MONGO_HOST}:${MONGO_PORT}/${MONGO_DATABASE}" +fi export PATH=./bin:$PATH exec "$@"