Install wkhtmltopdf on heroku using a java application - spring

I manged to get my spring boot website online on Heroku. But I also use wkhtmltopdf to create a pdf. This works locally but now I have some problems.
Offline it works as follow :
ProcessBuilder pb = new ProcessBuilder
("cmd.exe",
"/c",
" cd C:\\Program Files\\wkhtmltopdf\\bin && wkhtmltopdf.exe "
+ "http://google.com C:\\MainWebApps\\TestApp\\src\\main\\resources\\userstorage\\Google2.pdf");
But how do I install this on Heroku?
Where do I store the temporarily html page so I can create a pdf from it ?
And where is wkhtmltopdf installed on Heroku ?
Can I call the wkhtmltopdf with a processbuilder on heroku?
EDIT
So after the comment of ceejayoz I googled a bit more and did find some interesting stuff.
So for Compile the binaries on Heroku I used this:
heroku run /bin/bash
Then I did a curl of wkhtmltopdf like this:
curl -O http://download.gna.org/wkhtmltopdf/0.12/0.12.0/wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz
Then I tried to extract it on the server but without success:
$ tar -xjvf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz
tar (child): wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
EDIT2
I also found this https://github.com/dscout/wkhtmltopdf-buildpack on github.
So I did following :
heroku buildpacks:set 'https://github.com/heroku/heroku-buildpack-multi.git'
echo 'https://github.com/dscout/wkhtmltopdf-buildpack.git' >> .buildpacks
This created a file named .buildpacks but how do I proceed from there on ?
I also found this post but vulcan is deprecated and uses ruby
Using Wkhtmltopdf with Nodejs on Heroku
Can somebody provide me with good information because I am completely stuck with this?

You actually have two problems that you need to solve -
How to install/invoke the executable
How to handle the generated .pdf
Assuming you have the basics of Heroku deployment (push to the Heroku git remote), for #1, #ceejayoz is right - check the binary into your git repository. For example, under a ./bin directory. The root of your project (where the Procfile is) will be your working directory, and you should be able to invoke the program with ProcessBuilder using relative paths.
Caveat - since it looks like you are developing on Windows, you will need to pay attention to ensuring both platform-specific binaries are available, and add some logic to know which one to invoke (for example, by setting/checking a specific environment variable).
I recommend against trying to build with a custom build pack - you will spend a lot of energy for little to no benefit. Aside from the platform issue, you don't need to rebuild a third party tool when your code changes...
The second problem is that you can't leave the generated PDF in place. It will go away when the dyno is restarted (see https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem). Thus, the first thing you should do when the process completes is move the generated file to an external storage service (Amazon S3 is a good starting point).
Hope this helps.

You might want to use wkhtmltopdf-binary. With that solution, you do not need to put wkhtmltopdf executable into your VCS. You can use it for example with Maven or Gradle.

Related

poetry on heroku: can't find (any!) modules after many tries

I'm trying to move to poetry as a system for python virtual environments, but I've never deployed it to heroku before, and am having no luck at all.
I've tried this now with two different fresh poetry projects, and two different fresh git repositories. I:
create a fresh poetry project
initialize it as a git repo
add all the relevant libraries (poetry add flask gunicorn etc)
add the SINGLE file that holds the entire app, and push it to heroku, which is configured with the poetry buildpack from https://elements.heroku.com/buildpacks/moneymeets/python-poetry-buildpack
When I try to run the file directly, my Procfile is "web: python project/website.py", I get "ModuleNotFoundError: No module named 'flask'" (which is imported in the first line of the file)
When I try to run the file indirectly (because maybe it makes a difference?) my Procfile is "web: gunicorn wsgi:app", I get "bash: gunicorn: command not found"
I am absolutely certain that the pyproject.toml is up to date, and have manually verified that the requirements.txt file it produces contains both flask, and gunicorn, by looking at the build files on the heroku server with "heroku run bash"
I have tried resetting the heroku cache, manually creating requirements.txt before build, emptying, and then re-filling requirements.txt, and other things I'm sure too. I get one of these two errors, every time. ALL of the questions I see about this issue just ask if the libraries are in the requirements files. Mine are. They are not being seen, or found, or noticed, or used, or something.
I have absolutely no idea what else to do. After this many tries the only sane thing would seem to be to just use pipenv, but the error seems so flagrant, and presumably simple, that it's driving me completely nuts.
EDITS (in response to comment): My file tree has changed through different attempts to make things work, so I've tried a number of configurations. Sometimes the Procfile and app file are in the same, top-level directory -- I've also tried having a runserver script at the top level, and putting the app script inside another directory.
I have also tried having, and not having, local requirements.txt files, in case poetry wasn't successfully creating them as it's supposed to, but the poetry build-back does appear to successfully build its own when launched on heroku. I examined that one, on the heroku machine, and it contained lines for both flask, and gunicorn (among others, but these are the specific two the system says are missing)
Test to run locally "poetry run flask run".

GO API installation fails "evq/chromaticity"

I am trying to install chromaticity on my own machine for testing, and no matter what i do i will always hit the error seen in this picture installation error
I dont know why it happened i tried searching but i found nothing online. my question is does anyone know why it happens? or can point me to the right direction? i have checked the folders and yes there are no GO files in there but i dont see why that is a problem
The api could be found here: https://github.com/evq/chromaticity
This is not an issue (as in bug) on the project, rather an issue due to lack of documentation on how to build the project itself.
If you look at the Makefile file on the root directory, you'll notice that static/static.go is a generated file as part of the build process. Such file is usually not committed to the repo so you'll need to build it yourself. To do so, you'll need to have go-bindata installed.
Here's what you need to do in order to build the project successfully:
Get the go-bindata package
go get -u github.com/jteeuwen/go-bindata/...
Get the project
go get github.com/evq/chromaticity
Go the project root directory
cd [...the chromaticity project root..]
Run make to generate the static/static.go file
make
Build/ install the project
go install
Update:
Noticed from your screenshot that you're using Windows, in that case you may need to workaround the issue of running Makefile in Windows. See here for possible solution: How to run a makefile in Windows?
I've run into the same issue when trying to "get" and then install this project. I looked into the code and there is no trace of Asset() function in github.com/evq/chromaticity/static. Moreover git history does not show any .go files in static/ directory. Personally, I would create issue in the project and/or look for different repo containing desired functionality.

Git bundled into Cocoa app cannot find helpers in bundle

Context:
I have a Mac app. I want to include Git in this app because some functions of my app use Git and I don't want the user to have to install it on his machine.
I have downloaded Git from source. I edited the Makefile to declare these two lines:
NO_GETTEXT="yesPlease"
CURLDIR=/usr/local
The first line tells the build process to skip localizing and just use English.
The second line declares the path to where libcurl is installed. I downloaded libcurl_devel and built it from source. This is required to enable Git to pull/push from http and https repos.
Git builds successfully. I then copy all of the resulting files into my app's bundle. I'm using NSTask to run Git and attempt to pull an https://-based repo.
The Problem:
The error I get is:
fatal: Unable to find remote helper for 'https'
I googled this, and everyone said that as long as I had libcurl installed when I built Git, Git would work with HTTP and HTTPS addresses. And, in fact, if I run the installed Git from the command line, it does!
What I Need:
So, I must be missing a path setting or an environment variable or SOMETHING that tells Git where to find those remote helpers. They ARE in my app bundle; the screenshot below shows them:
So: what the hell do I need to set in order to resolve this problem when I run Git from within my application bundle?
Unbelievable. I've been trying to fix this for 8+ hours and five minutes after I finally break down and post this question, I figure it out:
Git has an option called --exec-path. I had been passing this argument to the NSTask like this (Where APP BUNDLE is replaced by the path to the application bundle on the user's machine):
--exec-path=[APP BUNDLE]/git/bin
Since bin was the folder where the Git binary was located, I figured that was the appropriate path. However, if I do this:
--exec-path=[APP BUNDLE]/git/libexec/git-core
It works.

Heroku NodeJS + CouchBase Custom Buildpack

I'm trying to put together a custom buildpack with NodeJS and the CouchBase module/libraries
I've gotten as far as using Vulcan to build libcouchbase and libvbucket and getting the buildpack to retrieve and unpack the tgz files for both.
Everything looks ok there, but I receive errors when npm tries to install the couchbase module:
I get a bunch of errors, but this line:
"../src/couchbase_impl.h:52:36: warning: libcouchbase/couchbase.h: No such file or directory"
leads me to think that it can't find the libcouchbase libraries (which is possible since they aren't in the usual place).
I've tried to add the correct path using CPPFLAGS="-I/app/vendor/couchbase/include/libcouchbase" in both the Config Vars and just exporting that as part of the compile phase, but still no luck.
Here is the gist with the Heroku deploy output and the compile/release buildpack files:
https://gist.github.com/ahamidi/5620503
Any help would be greatly appreciated.
Thanks,
Ali
[Update 1]
I've made some progress and I can now get the slug to compile when deploying to Heroku.
The key was figuring out the ENV Variables that CouchNode looks for when adding custom directories to include.
In this case, the Env Variables were EXTRA_CPPFLAGS and EXTRA_LDFLAGS.
So I updated the compile file to include the following:
export EXTRA_CPPFLAGS="-I$BUILD_DIR/vendor/couchbase/include"
export EXTRA_LDFLAGS="-L$BUILD_DIR/vendor/couchbase/lib -Wl,-rpath,$BUILD_DIR/vendor/couchbase/lib"
The slug compiles and the app is deployed, but I now get a different error in the logs:
Error: libcouchbase.so.2: cannot open shared object file: No such file or directory
So it looks like Node can't see the libcouchbase libraries directory.
For anyone who is curious or experiencing a similar issue, here's what worked for me.
In order to get the couchbase npm module to install I had to tell it where to find the libcouchbase libraries (in compile file):
export EXTRA_CPPFLAGS="-I$BUILD_DIR/vendor/couchbase/include"
export EXTRA_LDFLAGS="-L$BUILD_DIR/vendor/couchbase/lib -Wl,-rpath,$BUILD_DIR/vendor/couchbase/lib"
Then in order to require couchbase in my app I had to set the following Env Variable:
LD_LIBRARY_PATH="/app/vendor/couchbase/lib:$LD_LIBRARY_PATH"
With the command:
heroku config:add LD_LIBRARY_PATH="/app/vendor/couchbase/lib:$LD_LIBRARY_PATH"
You should set CPPFLAGS="-I/app/vendor/couchbase/include" LDFLAGS="-L/app/vendor/couchbase/include -lcouchbase"
from your script it seems like you just unpacking libcouchbase without any further work. you should also build it and install. typical magic spell for node.js client will be ./configure --disable-plugins --disable-examples && make && sudo make install. I'm not sure if sudo part needed on heroku, probably just make install

an error in plone theming

I installed Plone 4.1.3 and I am trying to make a theme. I saw this link talk about this issue:
http://www.treebrolly.com/blog/turbo-plone-theming-with-xdv-diazo
and I followed the commands. When I run this command
$ ./bin/instance fg
it says
Error: error opening file /home/hosam/plone413/zinstance/parts/instance/etc/zope.conf: [Errno 2] No such file or directory: '/home/hosam/plone413/zinstance/parts/instance/etc/zope.conf'
For help, use ./bin/instance -h
hosam#hosam-desktop:~/plone413/zinstance$
I noticed that when I run this command
$ ./bin/buildout -c demo.cfg
this directory and its contents are deleted /home/hosam/plone413/zinstance/parts/instance/
and so this error appears to me, Any can help??
When you run :
$ ./bin/buildout -c demo.cfg
the parts folder is supposed to be deleted and rebuilt (that's fine).
The error you are facing says that this command doesn't end correctly. Try to add the -v parameter
$ ./bin/buildout -v -c demo.cfg
so you will have a more verbose output and you can provide here a complete error traceback
Set up your demo.cfg in a different buildout directory. Looking at the blog entry you mentioned, it's meant to standalone, not share the same buildout directory with a zope/plone instance.
You might want to consider using plone.app.theming instead of XDV. The big difference is that plone.app.theming runs inside Plone and doesn't require any separate build. That really simplifies things if you don't need to mix in content from non-Plone sources.

Resources