• ANNOUNCE: cookfs 1.8.0

    From Konstantin Kushnir@chpock@gmail.com to comp.lang.tcl on Sat Jul 27 04:10:19 2024
    From Newsgroup: comp.lang.tcl

    Hi Everyone!

    I am pleased to announce version 1.8.0 of cookfs.
    Homepage and downloads are on github: https://github.com/chpock/cookfs

    Please fill free to check/build/use it. Any feedback is welcome!

    =====================================================================

    Cookfs is a Tcl virtual filesystem using a compressed archive format to
    allow embedding multiple files in an archive that Tcl scripts can
    access directly.

    It is optimized for storing Tcl packages (allowing around 10%-20%
    smaller sizes ratio than mk4vfs while still using zlib compression),
    small, fast and integrated with Tcl.

    Major changes since the last public release:

    1. Added support for strong AES-256-CBC encryption with
    PBKDF2-HMAC-SHA256 key derivation. Cookfs supports 2 modes in which
    either individual files or the encryption key can be encrypted. The
    second mode will be very useful when the same archive needs to be
    shared with different passwords. More details about these modes and how
    to work with them is described in the documentation. (http://cookfs.chpock.tk/cookfs.html#section10)

    2. Added a C header file (tclCookfs.h) that is installed with the
    package and contains a mount function and functions for configuring
    mount parameters. These functions make it easier to integrate cookfs as
    a file store for tclkit.
    --
    Best regards,
    Konstantin Kushnir
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From neophytos@neophytos@gmail.com (neophytos) to comp.lang.tcl on Sat Jul 27 17:47:21 2024
    From Newsgroup: comp.lang.tcl

    Hi Konstantin,

    I haven't had the chance to try this out yet but it sounds great.

    Not sure if this is a stupid question but have you tried to prepare a
    single executable file that can run on AWS Lambda? If you get that
    working (and it seems to me that you have what it takes already to make
    it happen), I would be very interested.

    All the best,
    Neophytos
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From neophytos@neophytos@gmail.com (neophytos) to comp.lang.tcl on Sat Jul 27 23:30:16 2024
    From Newsgroup: comp.lang.tcl

    To answer my own question it is not possible with cookfs (if I
    understood well what Konstantin trying to explain) but it can be done
    with zipfs in TCL9. So, I took a stub at it and here all it takes to run
    TCL scripts using AWS Lambda:

    == aws-lambda-runtime ==

    $ git clone https://github.com/awslabs/aws-lambda-cpp.git
    $ cd aws-lambda-cpp
    $ mkdir build
    $ cd build
    $ cmake .. -DCMAKE_BUILD_TYPE=Release
    -DCMAKE_INSTALL_PREFIX=~/lambda-install
    $ make && make install

    == bootstrap.cpp ==

    #include <tcl.h>
    #include <aws/lambda-runtime/runtime.h>

    using namespace aws::lambda_runtime;

    static Tcl_Interp *interp = NULL;

    static invocation_response my_handler(invocation_request const& req)
    {
    if (req.payload.length() > 42) {
    return invocation_response::failure("error message here"/*error_message*/,
    "error type here"
    /*error_type*/);
    }

    Tcl_EvalFile(interp, "//zipfs:/app/main.tcl");

    return invocation_response::success(Tcl_GetStringResult(interp) /*payload*/,
    "application/json" /*MIME
    type*/);
    }

    int main(int argc, char *argv[]) {

    TclZipfs_AppHook(&argc, &argv);
    interp = Tcl_CreateInterp();
    Tcl_Init(interp);

    run_handler(my_handler);

    Tcl_DeleteInterp(interp);
    return 0;
    }


    == mkimg.tcl ==

    set source_dir [file dirname [file normalize [info script]]]
    set script_dir [file join $source_dir scripts]

    for { set i 0 } { $i < $argc } { incr i } {
    set arg [lindex $argv $i]
    switch -exact -- $arg {
    -o {
    set output_file [lindex $argv [incr i]]
    }
    default {
    puts stderr "Unknown argument: \"$arg\""
    exit 1
    }
    }
    }

    if { ![info exists output_file] } {
    puts stderr "No output file specified"
    exit 1
    }

    if { [file exists bootstrap.vfs] } {
    file delete -force bootstrap.vfs
    }
    if { [file exists $output_file] } {
    file delete -force $output_file
    }

    file mkdir bootstrap.vfs
    file copy [file join [zipfs root] app tcl_library] bootstrap.vfs
    file copy [file join $script_dir main.tcl] bootstrap.vfs
    file copy [file join [file dirname [info script]] bootstrap] bootstrap.vfs/bootstrap

    zipfs mkzip $output_file bootstrap.vfs bootstrap.vfs
    file attributes $output_file -permissions 0o0644

    puts "Created: $output_file"

    == Makefile ==

    all:
    g++ -std=c++11 -o bootstrap bootstrap.cpp -L/path/to/static/lib -ltcl9.0 -lz -lm -laws-lambda-runtime -lcurl -lssl -lcrypto -I/path/to/static/include -static
    /path/to/static/bin/tclsh9.0 mkimg.tcl -o bootstrap.img
    cat bootstrap.img >> bootstrap
    zip bootstrap.zip bootstrap

    == Trying it out with localstack ==

    awslocal iam create-role --role-name myhellorole
    --assume-role-policy-document {}
    awslocal lambda create-function --function-name MyHelloFunction --role "arn:aws:iam::000000000000:role/myhellorole" --zip-file
    fileb://bootstrap.zip --runtime provided.al2 --timeout 5 --memory-size
    2048 --handler bootstrap
    sleep 3
    awslocal lambda invoke --function-name MyHelloFunction --log-type Tail /tmp/outfile

    == Epilogue ==

    I hope it helped. Took me a while to figure out the details.
    --- Synchronet 3.20a-Linux NewsLink 1.114