commit 39ade9abe97f57f94366d91c246f81d96002c0fd
| author | 斟酌 鵬兄 <tgckpg@gmail.com> |
| date | 2020-09-22T17:37:10Z |
| subject | Added settings for k8s |
commit 39ade9abe97f57f94366d91c246f81d96002c0fd
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date: 2020-09-22T17:37:10Z
Added settings for k8s
---
.dockerignore | 12 ++++++++++
Dockerfile | 22 ++++++++++++++++++
botan-rebuild.py | 2 +-
k8s.yaml | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
main.py | 3 ++-
settings.ini | 3 +--
setup/docker.start | 32 +++++++++++++++++++++++++
7 files changed, 138 insertions(+), 4 deletions(-)
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..6c805ee
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,12 @@
+.dockerignore
+.git
+.gitignore
+*~
+*.swp
+*.pyc
+Dockerfile
+k8s.yaml
+__pycache__
+cache/*
+logs/*
+env/*
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..a941f4d
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,22 @@
+FROM python:latest
+WORKDIR /app
+
+RUN apt-get update
+RUN apt-get install -y openjdk-11-jre
+
+RUN mkdir -p /opt/utils
+RUN wget -O /opt/utils/closure.jar "https://repo1.maven.org/maven2/com/google/javascript/closure-compiler/v20200830/closure-compiler-v20200830.jar"
+RUN wget -O /opt/utils/yuicompressor.jar "https://github.com/yui/yuicompressor/releases/download/v2.4.8/yuicompressor-2.4.8.jar"
+
+RUN pip install virtualenv
+RUN chown www-data:www-data . -R
+
+USER www-data
+
+RUN virtualenv env
+RUN env/bin/pip install Flask redis compressinja Celery uwsgi
+
+EXPOSE 5000
+ENTRYPOINT ["setup/docker.start"]
+
+COPY . /app/
diff --git a/botan-rebuild.py b/botan-rebuild.py
index 4ea03c8..e106c13 100755
--- a/botan-rebuild.py
+++ b/botan-rebuild.py
@@ -8,7 +8,7 @@ from botanjs.config import Config as config
SiteRoot = os.path.abspath( "." )
# Setting the SiteRoot for config
-config["Paths"]["SiteRoot"] = SiteRoot;
+config["Paths"]["SiteRoot"] = SiteRoot
bmap = os.path.join( config["Paths"]["Cache"], "botanjs", "bmap.xml" )
diff --git a/k8s.yaml b/k8s.yaml
new file mode 100644
index 0000000..14756a5
--- /dev/null
+++ b/k8s.yaml
@@ -0,0 +1,68 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: astrojs
+spec:
+ selector:
+ matchLabels:
+ app: astrojs
+ replicas: 1
+ template:
+ metadata:
+ labels:
+ app: astrojs
+ spec:
+ volumes:
+ - name: astrojs-cache
+ nfs:
+ server: astrofile.astrohost
+ path: /srv/astrostorage
+ containers:
+ - name: web
+ image: 192.168.80.4:32000/sites/astrojs:b00017
+ volumeMounts:
+ - mountPath: "/app/cache"
+ name: astrojs-cache
+ env:
+ - name: FLASK_DEBUG
+ value: "0"
+ - name: FLASK_ENV
+ value: "production"
+ - name: RUN_MODE
+ value: "web"
+ - name: compiler
+ image: 192.168.80.4:32000/sites/astrojs:b00017
+ volumeMounts:
+ - mountPath: "/app/cache"
+ name: astrojs-cache
+ env:
+ - name: RUN_MODE
+ value: "tasks"
+
+---
+
+apiVersion: v1
+kind: Service
+metadata:
+ name: astrojs
+spec:
+ selector:
+ app: astrojs
+ ports:
+ - port: 5000
+ targetPort: 5000
+
+---
+
+apiVersion: networking.k8s.io/v1beta1
+kind: Ingress
+metadata:
+ name: name-virtual-host-ingress
+spec:
+ rules:
+ - host: botanjs.botanical.astropenguin.net
+ http:
+ paths:
+ - backend:
+ serviceName: astrojs
+ servicePort: 5000
diff --git a/main.py b/main.py
index d3ade1d..984813f 100644
--- a/main.py
+++ b/main.py
@@ -19,4 +19,5 @@ service = WebAPI(
application = service.app
if __name__ == "__main__":
- service.run( debug = DEBUG )
+ application.config["DEBUG"] = DEBUG
+ application.run( host = config["Service"]["BindAddress"], port = config["Service"]["Port"] )
diff --git a/settings.ini b/settings.ini
index f38da7b..c1883dc 100644
--- a/settings.ini
+++ b/settings.ini
@@ -12,9 +12,8 @@ Cache = ${SiteRoot}/cache
[BotanJS]
SrcDir = ${Paths:Runtime}/botanjs/src
-REDIS_PASS = RJszCzFoeZaULKyY3w5W0kMVF4Ei5ZsqMVexk8wxFzQEYnRuLsdGOkHIAXYe4XNuByZHfbee7GxLsuo9xvEIKdYVpvVRYMUbcf25cuOIWV1sLgxhRv0q9KtH7cLpBroa1BIiqHtbzkd3erenel6siIqyHQxV0jPVFfm0ayCvYmdHiVL1VphBpTSnAX8JNvR2Iim5Q7aGiDpLxQD0nnnc1uQuJjwBNA3jkjddMMvHgN8iYleq4SA2xycqNNFzejlT
-CeleryBroker = redis://:${REDIS_PASS}@192.168.80.100:6379/9
+CeleryBroker = redis://:@astrop-redis.default:6379/9
ClosureCompiler = /opt/utils/closure.jar
YuiCompressor = /opt/utils/yuicompressor.jar
diff --git a/setup/docker.start b/setup/docker.start
new file mode 100644
index 0000000..ee0092a
--- /dev/null
+++ b/setup/docker.start
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+INST_DIR=$( dirname "${BASH_SOURCE[0]}" )
+source "$INST_DIR/config"
+cd $PROJ_ROOT
+
+mkdir -p cache/botanjs
+
+case "$RUN_MODE" in
+ "web")
+ ./botan-rebuild.py
+ ./env/bin/uwsgi \
+ --http-socket :5000 \
+ --wsgi-file main.py \
+ --callable application --master \
+ --processes 1 --threads 2
+ ;;
+ "tasks")
+ source "$INST_DIR/celery.conf"
+
+ "$BIN_ROOT/celery" worker -n worker1@%h \
+ -A ${CELERY_APP} \
+ --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} \
+ & "$BIN_ROOT/celery" worker -n worker1@%h \
+ -A ${CELERY_APP} \
+ --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}
+ ;;
+ *)
+ echo "RUN_MODE is missing"
+ exit 1
+ ;;
+esac