-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Minimal app to toy with nerdctl
- Loading branch information
1 parent
4482a1e
commit f107c70
Showing
5 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Run with | ||
|
||
```sh | ||
flask --app app run --debug | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()} |