Experimental

This commit is contained in:
Jack Hadrill 2022-08-24 23:56:49 +00:00
parent f0fa88a71b
commit b64082f626
11 changed files with 141 additions and 1 deletions

48
.drone.yml Normal file
View File

@ -0,0 +1,48 @@
kind: pipeline
type: docker
name: lint
steps:
- name: lint
image: python:3-slim
commands:
- echo "Installing lint dependencies..."
- pip install --no-cache-dir .[lint] > /dev/null
- echo "Running flake8..."
- flake8 src
- echo "Running pylint..."
- pylint src
---
kind: pipeline
type: docker
name: test
- name: test
image: python:3-slim
commands:
- echo "Installing test dependencies..."
- pip install --no-cache-dir .[test] > /dev/null
- echo "Running tests..."
- pytest
---
kind: pipeline
type: docker
name: build-deploy
depends_on:
- lint
- test
steps:
- name: build
image: python:3-slim
commands:
- pip install --no-cache-dir build
- python -m build --wheel
- name: publish
image: plugins/pypi
when:
branch:
- master
settings:
username: jackhadrill
password:
from_secret: password
repository: https://git.jacknet.io/api/packages/jackhadrill/pypi
skip_build: true

2
.flake8 Normal file
View File

@ -0,0 +1,2 @@
[flake8]
max-line-length = 120

2
.pylintrc Normal file
View File

@ -0,0 +1,2 @@
[FORMAT]
max-line-length=120

10
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,10 @@
{
// The following will hide Python's build cache directories.
"files.exclude": {
"**/__pycache__": true,
"**/*.egg-info": true,
"**/.pytest_cache": true
},
"python.linting.enabled": true,
"python.linting.pylintEnabled": true
}

View File

@ -1,2 +1,44 @@
# code-spawner # Code Spawner
[![Build Status](https://drone.jacknet.io/api/badges/jackhadrill/container-spawner/status.svg)](https://drone.jacknet.io/jackhadrill/container-spawner)
A tool for spawning a bespoke container upon receiving an HTTP request.
## Usage
More details coming soon.
An example `docker-compose.yml` config is show below:
```yml
version: '3'
services:
...
container-spawner:
image: git.jacknet.io/jackhadrill/container-spawner:latest
restart: always
environment:
CONTAINER_IMAGE: "codercom/code-server:latest"
CONTAINER_PREFIX: "vscode"
CONTAINER_NETWORK: "vscode_backend"
CONTAINER_PERSIST: "/home/coder"
...
```
## Process description
Upon receiving any HTTP request, **Code Spawner** will launch a bespoke container on behalf of the user (if not already existing), equivalent to having used the command below. The user's name is derived from the `X-Forwarded-Preferred-User` header, original sent by [**OAuth2 Proxy**](https://github.com/oauth2-proxy/oauth2-proxy).
```bash
$ docker run -d --rm --name ${CONTAINER_PREFIX}-${X-Forwarded-Preferred-User} -v ${CONTAINER_PREFIX}-${X-Forwarded-Preferred-User}:${CONTAINER_PERSIST} --network ${CONTAINER_NETWORK} ${IMAGE_NAME}
```
For example, assuming `X-Forwarded-Preferred-User` is `jack`:
```bash
$ export CONTAINER_IMAGE="codercom/code-server:latest"
$ export CONTAINER_PREFIX="vscode"
$ export CONTAINER_NETWORK="vscode_backend"
$ export CONTAINER_PERSIST="/home/coder"
$ docker run -d --rm --name vscode-jack -v vscode-jack:/home/coder --network vscode_backend codercom/code-server:latest
```

21
pyproject.toml Normal file
View File

@ -0,0 +1,21 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "containerspawner"
description = "A tool for spawning containers."
readme = "README.md"
requires-python = ">=3.9"
license = {text = "MIT License"}
dependencies = []
dynamic = ["version"]
[project.optional-dependencies]
lint = [
"pylint>=2.14.5",
"flake8>=5.0.4"
]
test = [
"pytest>=7.1.2"
]

3
setup.cfg Normal file
View File

@ -0,0 +1,3 @@
[metadata]
name = containerspawner
version = 0.0.0

10
setup.py Normal file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env python3
# N.B. This is here for legacy support in order to support editable installs. Please see:
# https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#pep660-status
# https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#setupcfg-caveats
from setuptools import setup
setup()

View File

View File

2
test/test_main.py Normal file
View File

@ -0,0 +1,2 @@
def test_main():
assert True