Jenkins-autojobs: create jenkins jobs from git/svn/hg branches
gvalkov.github.com4 pointsby gvalkov1 comments
if not (API_KEY := os.getenv("API_KEY")):
...
For internal tools I just let os.environ["API_KEY"] raise a KeyError. It's descriptive enough. import wsgiref.handlers, flask
app = flask.Flask(__name__)
wsgiref.handlers.CGIHandler().run(app)
The way we run the scripts is with uwsgi and its cgi plugin[1]. I find it simpler and more flexible than running apache or lighttpd just for mod_cgi. Since uwsgi runs as a systemd unit, we also have all of systemd's hardening and sandboxing capabilities at our disposal. Something very convenient in uwsgi's cgi handling that's missing from mod_cgi, is the ability to set the interpreter for a given file type: cgi = /cgi-bin=/webapps/cgi-bin/src
cgi-allowed-ext = .py
cgi-helper = .py=/webapps/cgi-bin/venv/bin/python3 # all dependencies go here
Time to first byte is 250-350ms, which is acceptable for our use case. [1]: https://docs.python.org/3/whatsnew/3.11.html#whatsnew311-faster-cpython git clone https://github.com/pyenv/pyenv.git
cd pyenv/plugins/python-build/bin
./python-build --definitions
./python-build 3.10.8 /opt/python/3.10.8
PYTHON_CONFIGURE_OPTS="--enable-shared" ./python-build 3.10.8 /opt/python/3.10.8 cat id_rsa.pub | ssh $host 'dd of=.ssh/authorized_keys oflag=append conv=notrunc' # /etc/cni/net.d/testnet.conflist
{
"cniVersion": "0.4.0",
"name": "testnet",
"plugins": [
{
"type": "bridge",
"bridge": "br0", # main host interface is part of this bridge
"ipam": {
"type": "host-local",
"subnet": "10.0.0.0/16",
"gateway": "10.0.0.1",
"routes": [{ "dst": "0.0.0.0/0"}]
}
}
]
}
You can then start a container and operate on its network namespace for added flexibility: podman run -it --net testnet --ip 10.0.0.2 ...
ns=$(basename $(podman inspect $id | jq -r '.[0] .NetworkSettings .SandboxKey'))
ip netns exec $ns ip route add ...
[1]: https://github.com/containernetworking/cni > Use it. Talk about it. Write about it.
I have a project that converts basic setup.py files to setup.cfg files [1].