Skip to content

Commit

Permalink
fix: Minimal app to toy with nerdctl
Browse files Browse the repository at this point in the history
  • Loading branch information
adityahase committed Sep 9, 2024
1 parent 4482a1e commit f107c70
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies = [
"cdktf==0.20.8",
"cdktf-cdktf-provider-digitalocean==11.5.2",
"containerd==1.5.3",
"Flask==3.0.3",
]

[build-system]
Expand Down
5 changes: 5 additions & 0 deletions worker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Run with

```sh
flask --app app run --debug
```
Empty file added worker/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions worker/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from flask import Flask, jsonify
from flask.views import MethodView

from .container import Container

application = Flask(__name__)


class ContainerAPI(MethodView):
init_every_request = False

def get(self):
return jsonify(Container.list())

def post(self):
return jsonify(Container.create())


application.add_url_rule("/containers/", view_func=ContainerAPI.as_view("containers"))
15 changes: 15 additions & 0 deletions worker/container.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import json
import shlex
from subprocess import check_output


class Container:
@staticmethod
def list():
command = shlex.split("nerdctl container ls --no-trunc --format '{{json .}}'")
return [json.loads(line) for line in check_output(command).splitlines()]

@staticmethod
def create():
command = shlex.split("nerdctl container run --detach redis:alpine")
return {"name": check_output(command).decode()}

0 comments on commit f107c70

Please sign in to comment.