Repository navigation
journal 2020 10 02: Wrapping a Stack build into Rake
After much silence, I'm doing some small tasks on this project again.
Today is just a tiny piece: write some quick-and-dirty Ruby scripts, filled with embedded shell commands, so that the steps in the README (bundle exec rake) produces a tarball containing an executable build of the backend server. See this commit: 583622bf.
This is for preparing for deploys.
eason@eason-air ‹ master › (2020-10-03 01:27:44 NZDT) ~/pg/twitanalysis
[0] % ls
Gemfile LICENSE Rakefile activate.sh docs ignore
Gemfile.lock README.md _site backend-app frontend-app wiki-repo
eason@eason-air ‹ master › (2020-10-03 01:27:44 NZDT) ~/pg/twitanalysis
[0] % ./activate.sh
Activating new shell with VIRTUAL_GEM_ENV=activated and GEM_HOME=.gems
Deactivate by exiting the shell, e.g. by typing 'exit' or ^D
(.gems) eason@eason-air ‹ master › (2020-10-03 01:28:03 NZDT) ~/pg/twitanalysis
[0] % bundle exec rake 2> /dev/null
/Users/eason/.local/bin/stack
Your system already has Haskell Stack
Hello, Rake is running: build_backend
The cabal package is in version: 0.1.0.0
Naming the binary package: twitanalysis-backend-0.1.0.0-583622bf.bdist.tar.gz
Backend app built; please look at this file: twitanalysis-backend.bdist.tar.gz
(.gems) eason@eason-air ‹ master › (2020-10-03 01:29:10 NZDT) ~/pg/twitanalysis
[0] % ls -lh
total 9008
-rw-r--r-- 1 eason staff 200B 21 Sep 09:57 Gemfile
-rw-r--r-- 1 eason staff 6.9K 21 Sep 09:57 Gemfile.lock
-rw------- 1 eason staff 0B 17 Aug 00:31 LICENSE
-rw-r--r-- 1 eason staff 1.0K 21 Sep 10:05 README.md
-rw-r--r-- 1 eason staff 1.5K 3 Oct 01:19 Rakefile
drwxr-xr-x 7 eason staff 224B 20 Sep 00:47 _site
-rwxr-xr-x 1 eason staff 708B 21 Sep 10:14 activate.sh
drwxr-xr-x 14 eason staff 448B 3 Oct 01:28 backend-app
drwxr-xr-x 7 eason staff 224B 20 Sep 00:53 docs
drwxr-xr-x 19 eason staff 608B 12 Sep 16:23 frontend-app
drwxr-xr-x 7 eason staff 224B 8 Sep 23:51 ignore
-rw-r--r-- 1 eason staff 4.4M 3 Oct 01:28 twitanalysis-backend-0.1.0.0-583622bf.bdist.tar.gz
lrwxr-xr-x 1 eason staff 50B 3 Oct 01:28 twitanalysis-backend.bdist.tar.gz -> twitanalysis-backend-0.1.0.0-583622bf.bdist.tar.gz
drwxr-xr-x 21 eason staff 672B 19 Sep 23:04 wiki-repo
And we can witness that the bdist tarball does actually contain executable stuff:
(.gems) eason@eason-air ‹ master › (2020-10-03 01:31:07 NZDT) ~/pg/twitanalysis
[0] % mkdir -p tmp-backend
(.gems) eason@eason-air ‹ master › (2020-10-03 01:31:19 NZDT) ~/pg/twitanalysis
[0] % tar -C tmp-backend -xzf twitanalysis-backend.bdist.tar.gz
(.gems) eason@eason-air ‹ master ● › (2020-10-03 01:32:02 NZDT) ~/pg/twitanalysis
[0] % ./tmp-backend/bin/twitanalysis-exe
Using client credentials: Cred "*************************" "**************************************************"
Setting phasers to stun... (port 5000) (ctrl-c to quit)
As it stands, the packaged Haskell binary executable cannot actually find the static files to serve, and as such, /index.html is a 404.
I tried to ask Cabal nicely to include some files in a way that the executable can find, but things got really messy and still wasn't working. Either no files got included, or the static files (as Cabal data-files) got nested somewhere really deep that isn't where my executable is expecting to find them.
So I just manually copied the static/ directory into where the bdist tarball will be packed.
Related reading:
- Reference for
data-files:in a Cabal file: https://cabal.readthedocs.io/en/3.4/cabal-package.html#pkg-field-data-files - Discussion about
data-files: https://github.com/haskell/cabal/issues/6096 - More discussion about
data-files: https://github.com/haskell/cabal/issues/1542 - hpack reference: https://github.com/sol/hpack