tpack

Difference between version 17 and 20 - Previous - Next
<<toc>>

----

**Name**
''tpack'' - - [tar] file based deployment system for Tcl applications, supports Tcl 8.4, 8.5, 8.6, 8.7 without requirements of any additional libraries on all platforms

**Usage**

Singe file applications:

======
$ tpack wrap APPNAME.tapp 
======
Creates `APPNAME.tapp`, the single file application, containing some tar-loader code, the application code from APPNAME.tcl and the library code out of APPNAME.vfs. Sinve version 0.3.0 Optional compression can be enabled if an lz4 executable is available in the path. The created application itself contains lz4 decompression in pure Tcl code based on this wiki code [LZ4]. The decompression code needs at least Tcl 8.5.

======
$ tpack wrap APPNAME.tapp --lz4
======

Two file applications:

======
$ tpack wrap APPNAME.tcl APPNAME.vfs
======

Creates `APPNAME.ttcl`, the application, and `APPNAME.ttar` containing your library(ies).

**Description**

''tpack''  is a Tcl script which can be used to deploy your Tcl application to other computers and users. It is not a virtual file system approach. During the first application run files will be installed in a temporary directly and used from there. Unpacking of files will be redone automatically if the files in the program folder are newer than those files in the temporary folder. As input you give your application file `app.tcl` and a folder containing your libraries `app.vfs`. The folder structure is the same as for the [starkit] approach, by careful design of the file `app.vfs/main.tcl` the same folder can be as well used to for building [starkit]s and tarkits. The script `tpack.tcl` can create standalone applications containing some tar-file loader, the application code from `app.tcl` and and the library code from `app.vfs`. Installation: Just rename `app.ttap` to `app.bin` or just `app`, make it executable and move it to your PATH.

Alternatively two file applications can be created. In this case it creates from the file `app.tcl` a file `app.ttcl` containing the required parts from the tar library of [tcllib] to untar tar files and at the end your application code. From the folder `app.vfs` a tar archive with the extension `.ttar` is created: `app.ttar`. To deploy your application those two files has to be copied to the other computer, the file `app.ttcl` can be as well renamed to let's say `app.bin` or even `app` as long as `app.ttar` is in the same folder like the ttcl file.

**Comparison**

Here a comparison table between three deployment strategies:

%|Deployment|files|Compression|Tclkit 8.4|Tclkit 8.5|Tclkit 8.6|Tclkit 8.7|Tcl 8.4|Tcl 8.5|Tcl 8.6|Tcl 8.7|%
&|starkit|1|yes|yes|yes|yes|yes|no|no|no|no|&
&|zipkit|1|yes|no|no|no|yes|no|no|no|yes|&
&|tpack|1,2|yes*|yes|yes|yes|yes|yes|yes|yes|yes|&
*Before  you deliver the tpack application files you can obviously compress them yourself using gzip, zip or other tools, lz4 expression requires an lz4 executable during file creation and  at least Tcl 8.5 at runtime.

**Links**
    * Homepage: https://github.com/mittelmark/DGTtpaclk
    * Download: https://dorawngit.github.io/#/home?userl=hcontentps://github.com/mittelmark/DGTtpaclk/tree/masterin/apps/tpack.tcl
    * Manual: http://htmlpreview.github.io/?https://github.com/mittelmark/DGTtpaclk/blob/master/apps/tpadock/tpack.html
    * Version: 0.3.01 - 20224-023-164
    * License: MITBSD

**Example**

Here is an example for a minimal application consisting of some application file `mini.tcl` and a folder `mini.vfs` with some small library test:

======
## FILE mini.tcl
#!/usr/bin/env tclsh
package require test
puts mini
puts [test::hello]

## FILE mini.vfs/main.tcl
lappend auto_path [file join [file dirname [info script]] lib]

## FILE mini.vfs/lib/test/pkgIndex.tcl
package ifneeded test 0.1 [list source [file join $dir test.tcl]]

## FILE mini.vfs/lib/test/test.tcl
package require Tcl
package provide test 0.1
namespace eval ::test { }
proc ::test::hello { } { puts "Hello World!" }
======

Such a sample application can be downloaded here: https://github.com/mittelmark/DGTcl/blob/master/apps/tpack/tpack-sample.zip

You can then create your two files using the following command line:

======
tpack wrap mini
======

This will create the files `mini.ttcl` and `mini.ttar` which are the files you need to deploy on your computer which should only have an existing Tcl installation as prerequisite. 

Alternatively you can create a single file application:

======
tpack wrap mini.tapp
======

For more details consult the manual at http://htmlpreview.github.io/?https://github.com/mittelmark/DGTcl/blob/master/apps/tpack/tpack.html  

----

**See also**

   * [starkit] - standard Tclkit approach since Tcl 8.4
   * [zipkit] - the new zip file based approach since Tcl 8.7
   * [tarpack] - for deploying multi-file libraries as single file Tcl-modules.
   * [LZ4] - for a Tcl only compression possibility, needs at least Tcl 8.5
   * [Another Tcl module maker] - code used to attach the tar archive at the end of the file
   * [tcllib tar] - code to untar the application code at runtime

----

**Discussion**

[DDG] - 2021-09-13: My motivation was that Tcl 8.7 is not yet released and Tclkit based deployment to Windows requires often ignoring Virus-scan messages by the users. So I gave this purely Tcl only Tar file based approach a trial. With 8.7 certainly the [zipkit] way would be the certainly the better one as it offers compression and other more sophisticated possibilities.

[DDG] - 2021-11-09: With version 0.2.0 as well single file applications (tapp-files) can be created. Furthermore it is possible to use existing starkit layouts as the tpack application attaches as dummy starkit package to your application which updates the auto_path at starkit::startup. There is still no compression as this would limit the require Tcl versions to Tcl 8.6 and beyond. You can simply use gzip to reduce the size of the application before deploying it. The advantage of not using zipped archive is that currently Tapp-files can be run as well with Tcl 8.4 and 8.5

[DDG] - 2021-11-26: bugfix in version 0.2.1 to enable `package require tar` by the user itself

[DDG] - 2022-02-26: Version 0.3.0 brings lz4 compression but is limited to Tcl 8.5 and 8.6
[DDG] - 2024-03-14: Version 0.3.1 has a new homepage, its own Github page, and adds a few documentation fixes

<<categories>> Package | Deployment