Docker basado en un sh en vez de en compose
This commit is contained in:
parent
57becb5577
commit
28671888e1
10 changed files with 109 additions and 20 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,5 +1,6 @@
|
||||||
# https://dart.dev/guides/libraries/private-files
|
# https://dart.dev/guides/libraries/private-files
|
||||||
# Created by `dart pub`
|
# Created by `dart pub`
|
||||||
|
.flutter-plugins-dependencies
|
||||||
.dart_tool/
|
.dart_tool/
|
||||||
.dart-tool/
|
.dart-tool/
|
||||||
.dartServer/
|
.dartServer/
|
||||||
|
|
@ -12,7 +13,7 @@
|
||||||
.zcompdump
|
.zcompdump
|
||||||
.zshrc
|
.zshrc
|
||||||
.idea
|
.idea
|
||||||
/d4rt-formulas.iml
|
|
||||||
/build/
|
/build/
|
||||||
/d4rt_formulas.iml
|
/d4rt_formulas.iml
|
||||||
.aider*
|
.aider*
|
||||||
|
.build-container-cache
|
||||||
|
|
|
||||||
12
Makefile
12
Makefile
|
|
@ -1,22 +1,20 @@
|
||||||
|
|
||||||
flutter-container-exec = podman-compose run --entrypoint "$(1)" flutter
|
|
||||||
|
|
||||||
all: clean-podman build-linux-debug-podman build-linux-debug-podman
|
all: clean-podman build-linux-debug-podman build-linux-debug-podman
|
||||||
|
|
||||||
build-podman:
|
build-podman:
|
||||||
podman-compose build
|
./docker-exec.sh build
|
||||||
|
|
||||||
clean-podman: build-podman
|
clean-podman: build-podman
|
||||||
$(call flutter-container-exec, flutter clean)
|
./docker-exec.sh exec flutter clean
|
||||||
|
|
||||||
pub-get-podman: build-podman
|
pub-get-podman: build-podman
|
||||||
$(call flutter-container-exec, flutter pub get)
|
./docker-exec.sh exec flutter pub get
|
||||||
|
|
||||||
build-android-release-podman: pub-get-podman
|
build-android-release-podman: pub-get-podman
|
||||||
$(call flutter-container-exec, flutter build apk --release)
|
./docker-exec.sh exec flutter build apk --release
|
||||||
|
|
||||||
build-linux-debug-podman: pub-get-podman
|
build-linux-debug-podman: pub-get-podman
|
||||||
$(call flutter-container-exec, flutter build linux --debug)
|
./docker-exec.sh exec flutter build linux --debug
|
||||||
|
|
||||||
run-linux-debug: build-linux-debug-podman
|
run-linux-debug: build-linux-debug-podman
|
||||||
build/linux/x64/debug/bundle/d4rt_formulas
|
build/linux/x64/debug/bundle/d4rt_formulas
|
||||||
|
|
|
||||||
2
aider.sh
2
aider.sh
|
|
@ -1,2 +0,0 @@
|
||||||
aider --git --watch-files --read CLAUDE.md --notifications --no-auto-commits
|
|
||||||
|
|
||||||
|
|
@ -149,4 +149,28 @@ Where:
|
||||||
""",
|
""",
|
||||||
"tags": ["medical", "pediatrics", "assessment"]
|
"tags": ["medical", "pediatrics", "assessment"]
|
||||||
}
|
}
|
||||||
|
,
|
||||||
|
{
|
||||||
|
"name": "Compare price per mass",
|
||||||
|
"description": "Compares two products by their price per mass and returns which is cheaper.",
|
||||||
|
"input": [
|
||||||
|
{"name": "price1", "unit": "scalar"},
|
||||||
|
{"name": "mass1", "unit": "kilogram"},
|
||||||
|
{"name": "price2", "unit": "scalar"},
|
||||||
|
{"name": "mass2", "unit": "kilogram"}
|
||||||
|
],
|
||||||
|
"output": {"name": "Result", "unit": "scalar"},
|
||||||
|
"d4rtCode": """
|
||||||
|
var p1 = price1 / mass1;
|
||||||
|
var p2 = price2 / mass2;
|
||||||
|
if (p1 < p2) {
|
||||||
|
Result = 'first product is cheaper';
|
||||||
|
} else if (p2 < p1) {
|
||||||
|
Result = 'second product is cheaper';
|
||||||
|
} else {
|
||||||
|
Result = 'both products have the same price per mass';
|
||||||
|
}
|
||||||
|
""",
|
||||||
|
"tags": ["comparison", "shopping", "economics"]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
40
docker-exec.sh
Executable file
40
docker-exec.sh
Executable file
|
|
@ -0,0 +1,40 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DOCKER=podman
|
||||||
|
|
||||||
|
|
||||||
|
build_image(){
|
||||||
|
$DOCKER build -t d4rt-formulas-builder -f Dockerfile .
|
||||||
|
}
|
||||||
|
|
||||||
|
exec_in_container(){
|
||||||
|
|
||||||
|
local XOPTIONS="--env DISPLAY=$DISPLAY --volume /tmp/.X11-unix:/tmp/.X11-unix --security-opt=label=disable"
|
||||||
|
local WOPTIONS="--env=XDG_RUNTIME_DIR=/run/user/$(id -u) --volume=/run/user/$(id -u)/wayland:/run/user/$(id -u)/wayland --group-add=video"
|
||||||
|
local SPIOPTIONS="--env AT_SPI_BUS=/run/user/$(id -u)/at-spi/bus_0 --volume=/run/user/$(id -u)/at-spi:/run/user/$(id -u)/at-spi --device=/dev/dri"
|
||||||
|
|
||||||
|
$DOCKER run \
|
||||||
|
--rm \
|
||||||
|
$XOPTIONS \
|
||||||
|
$SPIOPTIONS \
|
||||||
|
-v ./.build-container-cache:/cache:z \
|
||||||
|
-v .:/app:z \
|
||||||
|
-e FLUTTER_FLAVOR=prod \
|
||||||
|
d4rt-formulas-builder \
|
||||||
|
"$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$1" = "build" ]; then
|
||||||
|
build_image
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "exec" ]; then
|
||||||
|
exec_in_container ${@:2}
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Usage: $0 {build|exec <command>}"
|
||||||
|
exit 1
|
||||||
|
|
@ -27,6 +27,9 @@ class D4rtEditingController extends TextEditingController {
|
||||||
bool validate() {
|
bool validate() {
|
||||||
try {
|
try {
|
||||||
_lastValue = null;
|
_lastValue = null;
|
||||||
|
if( text.trim().isEmpty ){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
_lastValue = FormulaEvaluator.evaluateExpression(text);
|
_lastValue = FormulaEvaluator.evaluateExpression(text);
|
||||||
_lastError = null;
|
_lastError = null;
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -141,7 +144,7 @@ class _FormulaScreenState extends State<FormulaScreen> {
|
||||||
|
|
||||||
// Convert output to selected unit if needed
|
// Convert output to selected unit if needed
|
||||||
String? unit = widget.formula.output.unit;
|
String? unit = widget.formula.output.unit;
|
||||||
if (unit != null) {
|
if (unit != null && unit is Number) {
|
||||||
final converted = widget.corpus.convert(result, unit, _selectedOutputUnit!);
|
final converted = widget.corpus.convert(result, unit, _selectedOutputUnit!);
|
||||||
if (converted is num) {
|
if (converted is num) {
|
||||||
_result = converted.toStringAsFixed(2);
|
_result = converted.toStringAsFixed(2);
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class Corpus{
|
||||||
if( checkUnits ){
|
if( checkUnits ){
|
||||||
for( final inputVar in formula.input + [formula.output] ){
|
for( final inputVar in formula.input + [formula.output] ){
|
||||||
if( inputVar.unit != null && !_allUnits.containsKey(inputVar.unit) ){
|
if( inputVar.unit != null && !_allUnits.containsKey(inputVar.unit) ){
|
||||||
throw ArgumentError( "Unit not found: ${inputVar.unit}");
|
throw ArgumentError( "Unit not found in formula ${formula.name}: ${inputVar.unit}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -168,13 +168,38 @@ class FormulaEvaluator {
|
||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Build a Map<String, List<String>> named `variableValues` that exposes allowed values
|
||||||
|
// for each VariableSpec (inputs and output) to the interpreted code. Values are
|
||||||
|
// converted to strings and quoted in the produced d4rt source.
|
||||||
|
final variableValuesMap = <String, List<String>>{};
|
||||||
|
|
||||||
|
// Include input VariableSpecs when they have allowed values
|
||||||
|
for (final vs in formula.input) {
|
||||||
|
final values = vs.values;
|
||||||
|
if (values != null && values.isNotEmpty) {
|
||||||
|
variableValuesMap[vs.name] = values.map((v) => v.toString()).toList(growable: false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Explicitly include the output VariableSpec if it has allowed values
|
||||||
|
final outValues = formula.output.values;
|
||||||
|
if (outValues != null && outValues.isNotEmpty) {
|
||||||
|
variableValuesMap[formula.output.name] = outValues.map((v) => v.toString()).toList(growable: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the variableValues map into the generated source without escaping names/values
|
||||||
|
buffer.writeln("final variableValues = {");
|
||||||
|
variableValuesMap.forEach((name, list) {
|
||||||
|
final listLiteral = list.map((s) => '"' + s + '"').join(', ');
|
||||||
|
buffer.writeln(' "' + name + '": [' + listLiteral + '],');
|
||||||
|
});
|
||||||
|
buffer.writeln('};');
|
||||||
|
|
||||||
buffer.writeln("""
|
buffer.writeln("""
|
||||||
late var ${formula.output.name};
|
late var ${formula.output.name};
|
||||||
${formula.d4rtCode}
|
${formula.d4rtCode}
|
||||||
return ${formula.output.name};
|
return ${formula.output.name};
|
||||||
}
|
}
|
||||||
"""
|
""");
|
||||||
);
|
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -702,5 +702,5 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.3"
|
version: "3.1.3"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=3.10.7 <4.0.0"
|
dart: ">=3.10.4 <4.0.0"
|
||||||
flutter: ">=3.38.0"
|
flutter: ">=3.38.0"
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||||
version: 1.0.0+1
|
version: 1.0.0+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.10.7
|
sdk: ^3.10.4
|
||||||
|
|
||||||
# Dependencies specify other packages that your package needs in order to work.
|
# Dependencies specify other packages that your package needs in order to work.
|
||||||
# To automatically upgrade your package dependencies to the latest versions
|
# To automatically upgrade your package dependencies to the latest versions
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue