forked from Botanical/BotanJS
Deprecating old approach
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
FROM alpine:3.15.3
|
||||
WORKDIR /app
|
||||
|
||||
RUN mkdir -p /opt/utils
|
||||
|
||||
RUN apk add --update bash python3 uwsgi uwsgi-python openjdk11-jre-headless; python3 -m ensurepip
|
||||
|
||||
RUN echo "www-data:x:1001:1001:www-data:/var/www:/usr/sbin/nologin" >> /etc/passwd; echo "www-data:x:1001:" >> /etc/group
|
||||
|
||||
RUN pip3 install Flask redis compressinja Celery
|
||||
|
||||
ADD [ "https://github.com/tgckpg/BotanJS/releases/download/compressors/closure.jar" \
|
||||
, "https://github.com/tgckpg/BotanJS/releases/download/compressors/yuicompressor.jar" \
|
||||
, "/opt/utils/" ]
|
||||
|
||||
COPY . /app/
|
||||
|
||||
RUN chmod 644 /opt/utils/*.jar; \
|
||||
chown www-data:www-data . -R
|
||||
|
||||
USER www-data
|
||||
|
||||
EXPOSE 5000
|
||||
ENTRYPOINT ["setup/docker.start"]
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
import os, sys
|
||||
sys.path.append( os.path.abspath( "." ) )
|
||||
|
||||
from botanjs.service.jwork import app, JWork
|
||||
from botanjs.config import Config as config
|
||||
|
||||
SiteRoot = os.path.abspath( "." )
|
||||
|
||||
# Setting the SiteRoot for config
|
||||
config["Paths"]["SiteRoot"] = SiteRoot
|
||||
|
||||
bmap = os.path.join( config["Paths"]["Cache"], "botanjs", "bmap.xml" )
|
||||
|
||||
app.conf.update( broker_url = config["BotanJS"]["CeleryBroker"] )
|
||||
|
||||
JWork.buildClassMap.delay( config["BotanJS"]["SrcDir"], bmap )
|
||||
Vendored
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
```
|
||||
Please initialize your virtualenv here
|
||||
```
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#!env/bin/python
|
||||
|
||||
import os
|
||||
from botanjs.config import Config as config, DEBUG
|
||||
from subprocess import Popen
|
||||
from botanjs.service.webapi import WebAPI
|
||||
|
||||
SiteRoot = os.path.abspath( "." )
|
||||
|
||||
# Setting the SiteRoot for config
|
||||
config["Paths"]["SiteRoot"] = SiteRoot
|
||||
|
||||
service = WebAPI(
|
||||
jsCache = config["Paths"]["Cache"]
|
||||
, jsRoot = config["BotanJS"]["SrcDir"]
|
||||
, brokerURL = config["BotanJS"]["CeleryBroker"]
|
||||
)
|
||||
|
||||
application = service.app
|
||||
|
||||
if __name__ == "__main__":
|
||||
application.config["DEBUG"] = DEBUG
|
||||
application.run( host = config["Service"]["BindAddress"], port = config["Service"]["Port"] )
|
||||
@@ -0,0 +1,22 @@
|
||||
[Service]
|
||||
BindAddress = 0.0.0.0
|
||||
Port = 5000
|
||||
|
||||
[Env]
|
||||
Debug = False
|
||||
|
||||
[Redis]
|
||||
ConnStr = redis://:@localhost:6379/9
|
||||
|
||||
[Paths]
|
||||
Runtime = ${SiteRoot}
|
||||
Log = ${SiteRoot}/logs
|
||||
Cache = ${SiteRoot}/cache
|
||||
|
||||
[BotanJS]
|
||||
SrcDir = ${Paths:Runtime}/botanjs/src
|
||||
|
||||
CeleryBroker = ${Redis:ConnStr}
|
||||
|
||||
ClosureCompiler = /opt/utils/closure.jar
|
||||
YuiCompressor = /opt/utils/yuicompressor.jar
|
||||
@@ -0,0 +1,15 @@
|
||||
# Absolute or relative path to the 'celery' command:
|
||||
CELERY_BIN="BIN_ROOT/celery"
|
||||
|
||||
CELERYD_NODES="w1 w2"
|
||||
CELERY_APP="botanjs.service.jwork"
|
||||
|
||||
# How to call manage.py
|
||||
CELERYD_MULTI="multi"
|
||||
|
||||
# - %n will be replaced with the first part of the nodename.
|
||||
# # - %I will be replaced with the current child process index
|
||||
# # and is important when using the prefork pool to avoid race conditions.
|
||||
CELERYD_PID_FILE="RUN_ROOT/tasks-%n.pid"
|
||||
CELERYD_LOG_FILE="PROJ_ROOT/logs/tasks-%n.log"
|
||||
CELERYD_LOG_LEVEL="INFO"
|
||||
@@ -0,0 +1,19 @@
|
||||
[Unit]
|
||||
Description=BotanJS Compiler Tasks
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
EnvironmentFile=-ETC_ROOT/celery.conf
|
||||
WorkingDirectory=PROJ_ROOT
|
||||
ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} \
|
||||
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
|
||||
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
|
||||
ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait ${CELERYD_NODES} \
|
||||
--pidfile=${CELERYD_PID_FILE}'
|
||||
ExecReload=/bin/sh -c '${CELERY_BIN} multi restart ${CELERYD_NODES} \
|
||||
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
|
||||
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
[[ $CONFIG ]] && return
|
||||
CONFIG=1
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
SCRIPT_DIR="$( realpath "$SCRIPT_DIR" )"
|
||||
PROJ_ROOT="$( cd "$SCRIPT_DIR/../" && pwd )"
|
||||
ENV_ROOT="$PROJ_ROOT/env"
|
||||
BIN_ROOT="$ENV_ROOT/bin"
|
||||
ETC_ROOT="$ENV_ROOT/etc"
|
||||
RUN_ROOT="$ENV_ROOT/run"
|
||||
PYTHON="$BIN_ROOT/python3"
|
||||
Executable
+32
@@ -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
|
||||
uwsgi \
|
||||
--plugins-dir /usr/lib/uwsgi/ --need-plugin python \
|
||||
--http-socket :5000 \
|
||||
--wsgi-file main.py \
|
||||
--callable application --master \
|
||||
--listen 4096 \
|
||||
--processes 1 --threads 2
|
||||
;;
|
||||
"tasks")
|
||||
source "$INST_DIR/celery.conf"
|
||||
|
||||
celery -A ${CELERY_APP} worker -n worker1@%h \
|
||||
--loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} \
|
||||
& celery -A ${CELERY_APP} worker -n worker1@%h \
|
||||
--loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}
|
||||
;;
|
||||
*)
|
||||
echo "RUN_MODE is missing"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
INST_DIR=$( dirname "${BASH_SOURCE[0]}" )
|
||||
source "$INST_DIR/config"
|
||||
|
||||
mkdir -p "$RUN_ROOT"
|
||||
mkdir -p "$ETC_ROOT"
|
||||
|
||||
sed -e "s|PROJ_ROOT|$PROJ_ROOT|g" \
|
||||
-e "s|BIN_ROOT|$BIN_ROOT|g" \
|
||||
-e "s|RUN_ROOT|$RUN_ROOT|g" \
|
||||
"$INST_DIR/celery.conf" > "$ETC_ROOT/celery.conf"
|
||||
|
||||
sed -e "s|PROJ_ROOT|$PROJ_ROOT|g" \
|
||||
-e "s|ETC_ROOT|$ETC_ROOT|g" \
|
||||
-e "s|RUN_AS|$RUN_AS|g" \
|
||||
"$INST_DIR/compiler-tasks.service" > $HOME/.config/systemd/user/botanjs-tasks.service
|
||||
|
||||
systemctl --user enable botanjs-tasks.service
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user start botanjs-tasks.service
|
||||
@@ -0,0 +1,59 @@
|
||||
#!env/bin/python
|
||||
import os, sys
|
||||
sys.path.append( os.path.abspath( "." ) )
|
||||
|
||||
from botanjs.service.jwork import app, JWork
|
||||
from botanjs.config import Config as config
|
||||
|
||||
SiteRoot = os.path.abspath( "." )
|
||||
|
||||
# Setting the SiteRoot for config
|
||||
config["Paths"]["SiteRoot"] = SiteRoot
|
||||
|
||||
jsCache = config["Paths"]["Cache"]
|
||||
jsRoot = config["BotanJS"]["SrcDir"]
|
||||
|
||||
bmap = os.path.join( jsCache, "botanjs", "bmap.xml" )
|
||||
|
||||
app.conf.update( broker_url = config["BotanJS"]["CeleryBroker"] )
|
||||
|
||||
JWork.buildClassMap.delay( jsRoot, bmap )
|
||||
|
||||
from botanjs.service.jclassresv import BotanClassResolver as JCResv
|
||||
|
||||
import unittest
|
||||
|
||||
class TestStringMethods( unittest.TestCase ):
|
||||
|
||||
# Run each twice to test the cache capabilities
|
||||
def test_ojscall( self ):
|
||||
srv = JCResv( JWork, jsRoot, bmap, jsCache )
|
||||
for _ in range(0,2):
|
||||
s = srv.getAPI( "System", mode = "rjs" )
|
||||
if not ( "BotanJS.define( \"System\" );" in s ):
|
||||
print( "A---------------------" )
|
||||
print( s )
|
||||
print( "B---------------------" )
|
||||
self.assertTrue( False)
|
||||
|
||||
def test_import( self ):
|
||||
srv = JCResv( JWork, jsRoot, bmap, jsCache )
|
||||
for _ in range(0,2):
|
||||
s = srv.getAPI( "System.Policy", mode = "rjs" )
|
||||
self.assertTrue( "BotanJS.define( \"System.Policy\" );" in s )
|
||||
self.assertTrue( "BotanJS.define( \"System.Global\" );" in s )
|
||||
|
||||
def test_cssInheritance( self ):
|
||||
srv = JCResv( JWork, jsRoot, bmap, jsCache )
|
||||
for _ in range(0,2):
|
||||
s = srv.getAPI( "System", mode = "rcss" )
|
||||
self.assertTrue( "/* @ */" in s )
|
||||
|
||||
# def test_jsZCalls( self ):
|
||||
# srv = JCResv( JWork, jsRoot, bmap, jsCache )
|
||||
# for _ in range(0,2):
|
||||
# s = srv.getAPI( "eJx1zsEKgzAQBNAfKvsPaaj0YE/6A4tuJbDJlM2K9O/rpcUKOQ6PYSZUN9DgbE9WpZtKluJ0F57FLuFfe35jdXpwKp1xlrN/2x3gv/ZVsVBEfqHsVmmQyRNKQ6Nhm0dejtyYPVowT5PKHl2qN36PGyJ0zeUDs1BbKA==", mode = "css" )
|
||||
# print( s )
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,14 @@
|
||||
FROM astrojs/jre-nanoserver-20h2:latest
|
||||
|
||||
RUN pip3 install Flask redis compressinja celery
|
||||
|
||||
RUN New-Item -ItemType Directory -Path /opt/utils; \
|
||||
New-Item -ItemType Directory -Path /app/cache -Force; \
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; \
|
||||
Invoke-WebRequest -UseBasicParsing -Uri 'https://github.com/tgckpg/BotanJS/releases/download/compressors/closure.jar' -OutFile '/opt/utils/closure.jar' ; \
|
||||
Invoke-WebRequest -UseBasicParsing -Uri 'https://github.com/tgckpg/BotanJS/releases/download/compressors/yuicompressor.jar' -OutFile '/opt/utils/yuicompressor.jar' ;
|
||||
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
|
||||
EXPOSE 5000
|
||||
@@ -0,0 +1,9 @@
|
||||
version: '3.9'
|
||||
|
||||
services:
|
||||
python:
|
||||
build: pyrt
|
||||
image: astrojs/pyrt-nanoserver-20h2
|
||||
jre:
|
||||
build: jre
|
||||
image: astrojs/jre-nanoserver-20h2
|
||||
@@ -0,0 +1,36 @@
|
||||
version: '3.9'
|
||||
|
||||
services:
|
||||
redis:
|
||||
container_name: astrojsdev_redis
|
||||
build: redis
|
||||
web:
|
||||
container_name: astrojsdev_app
|
||||
image: astrojs/app
|
||||
hostname: astrojs.default
|
||||
build:
|
||||
context: ../
|
||||
dockerfile: windows/app/Dockerfile
|
||||
environment:
|
||||
DEBUG: "1"
|
||||
REDIS_CONN: redis://:@redis:6379/9
|
||||
command: [ "python", "main.py" ] # [ "ping", "127.0.0.1", "-n", "9999" ]
|
||||
depends_on:
|
||||
- redis
|
||||
ports:
|
||||
- 5000:5000
|
||||
volumes:
|
||||
- cache:C:/app/cache
|
||||
tasks:
|
||||
container_name: astrojsdev_compiler
|
||||
image: astrojs/app
|
||||
environment:
|
||||
REDIS_CONN: redis://:@redis:6379/9
|
||||
command: [ "celery", "-A", "botanjs.service.jwork", "worker", "-l", "info", "--pool=solo" ]
|
||||
depends_on:
|
||||
- redis
|
||||
- web
|
||||
volumes:
|
||||
- cache:C:/app/cache
|
||||
volumes:
|
||||
cache:
|
||||
@@ -0,0 +1,9 @@
|
||||
FROM astrojs/pyrt-nanoserver-20h2:latest as base
|
||||
|
||||
ENV JAVA_HOME=C:\\openjdk-11
|
||||
ENV JAVA_VERSION=11.0.12
|
||||
|
||||
RUN setx PATH "$Env:JAVA_HOME\bin`;$Env:Path" /M
|
||||
|
||||
COPY --from=openjdk:11-jre-nanoserver /openjdk-11 /openjdk-11
|
||||
RUN echo Verifying install ... && echo java --version && java --version && echo Complete.
|
||||
@@ -0,0 +1,54 @@
|
||||
FROM mcr.microsoft.com/powershell:nanoserver-20h2
|
||||
|
||||
SHELL [ "pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';" ]
|
||||
|
||||
RUN $url = 'https://www.python.org/ftp/python/3.7.6/python-3.7.6-embed-amd64.zip'; \
|
||||
Write-host "downloading: $url"; \
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; \
|
||||
New-Item -ItemType Directory /installer > $null ; \
|
||||
Invoke-WebRequest -Uri $url -outfile /installer/Python.zip -verbose; \
|
||||
Expand-Archive /installer/Python.zip -DestinationPath /Python; \
|
||||
Move-Item /Python/python37._pth /Python/python37._pth.save
|
||||
|
||||
### Begin workaround ###
|
||||
# Note that changing user on nanoserver is not recommended
|
||||
# See, https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/container-base-images#base-image-differences
|
||||
# But we are working around a bug introduced in the nanoserver image introduced in 20h2
|
||||
USER ContainerAdministrator
|
||||
|
||||
# This is basically the correct code except for the /M
|
||||
RUN setx PATH "$Env:Path`C:\Python`;C:\Python\Scripts`;" /M
|
||||
|
||||
# We can't
|
||||
# USER ContainerUser
|
||||
### End workaround ###
|
||||
|
||||
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
|
||||
ENV PYTHON_PIP_VERSION 21.2.4
|
||||
# https://github.com/pypa/get-pip
|
||||
ENV PYTHON_GET_PIP_URL https://github.com/pypa/get-pip/raw/4b85d3add912c861aea4a9feaae737a5b7b9cb1c/public/get-pip.py
|
||||
ENV PYTHON_GET_PIP_SHA256 ced8c71489cd46c511677bfe423f37eb88f08f29e9af36ef2679091ec7122d4f
|
||||
|
||||
RUN Write-Host ('Downloading get-pip.py ({0}) ...' -f $env:PYTHON_GET_PIP_URL); \
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
|
||||
Invoke-WebRequest -Uri $env:PYTHON_GET_PIP_URL -OutFile 'get-pip.py'; \
|
||||
Write-Host ('Verifying sha256 ({0}) ...' -f $env:PYTHON_GET_PIP_SHA256); \
|
||||
if ((Get-FileHash 'get-pip.py' -Algorithm sha256).Hash -ne $env:PYTHON_GET_PIP_SHA256) { \
|
||||
Write-Host 'FAILED!'; \
|
||||
exit 1; \
|
||||
}; \
|
||||
\
|
||||
Write-Host ('Installing pip=={0} ...' -f $env:PYTHON_PIP_VERSION); \
|
||||
python get-pip.py \
|
||||
--disable-pip-version-check \
|
||||
--no-cache-dir \
|
||||
('pip=={0}' -f $env:PYTHON_PIP_VERSION) \
|
||||
; \
|
||||
Remove-Item get-pip.py -Force; \
|
||||
\
|
||||
Write-Host 'Verifying pip install ...'; \
|
||||
pip --version; \
|
||||
\
|
||||
Write-Host 'Complete.'
|
||||
|
||||
CMD [ "python.exe" ]
|
||||
@@ -0,0 +1,27 @@
|
||||
FROM mcr.microsoft.com/powershell:nanoserver-20h2
|
||||
|
||||
SHELL [ "pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';" ]
|
||||
|
||||
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; \
|
||||
Invoke-WebRequest -UseBasicParsing -Uri 'https://github.com/tporadowski/redis/releases/download/v5.0.10/Redis-x64-5.0.10.zip' -OutFile 'Redis-x64-5.0.10.zip' ; \
|
||||
Expand-Archive Redis-x64-5.0.10.zip -dest 'C:\\Program Files\\Redis\\' ; \
|
||||
Remove-Item Redis-x64-5.0.10.zip -Force
|
||||
|
||||
User ContainerAdministrator
|
||||
RUN setx Path "C:\Program` Files\Redis`;$Env:Path" /M;
|
||||
User ContainerUser
|
||||
|
||||
WORKDIR 'C:\\Program Files\\Redis'
|
||||
|
||||
RUN Get-Content redis.windows.conf | Where { $_ -notmatch 'bind 127.0.0.1' } | Set-Content redis.openport.conf ; \
|
||||
Get-Content redis.openport.conf | Where { $_ -notmatch 'protected-mode yes' } | Set-Content redis.unprotected.conf ; \
|
||||
Add-Content redis.unprotected.conf 'protected-mode no' ; \
|
||||
Add-Content redis.unprotected.conf 'bind 0.0.0.0' ; \
|
||||
Get-Content redis.unprotected.conf
|
||||
|
||||
EXPOSE 6379
|
||||
|
||||
# Define our command to be run when launching the container
|
||||
CMD .\\redis-server.exe .\\redis.unprotected.conf --port 6379 ; \
|
||||
Write-Host Redis Started... ; \
|
||||
while ($true) { Start-Sleep -Seconds 3600 }
|
||||
Reference in New Issue
Block a user