Added settings for k8s

This commit is contained in:
斟酌 鵬兄 2020-09-23 01:37:10 +08:00
parent c6c7d5dddc
commit 39ade9abe9
7 changed files with 138 additions and 4 deletions

12
.dockerignore Normal file
View File

@ -0,0 +1,12 @@
.dockerignore
.git
.gitignore
*~
*.swp
*.pyc
Dockerfile
k8s.yaml
__pycache__
cache/*
logs/*
env/*

22
Dockerfile Normal file
View File

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

View File

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

68
k8s.yaml Normal file
View File

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

View File

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

View File

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

32
setup/docker.start Normal file
View File

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