How to obfuscate Python code with buildpacks? - python-3.x

I am using pack cli to build docker image for my python flask app running with gunicorn.
Inside docker image, my whole code is exposed in workspace folder.
What shall i do to restrict user to access folder or obfuscate my code?
I am using Google Buildpack
pack set-default-builder gcr.io/buildpacks/builder:v1

I'm assuming you're using the Heroku Python Buildpack (and the heroku/buildpacks:18 builder).
You can create a bin/post_compile and use it to run compileall, and then run rm **/*.py

Related

Equivalent of Google's JIB for Node.JS?

Is there one equivalent of Google's JIB or BuildPacks for Node.JS ?
It is my understanding that JIB allows to build OCI container images from within the project's build tool like Gradle or Maven, as a developer we only have to include a plugin into the build and are able to package up the application into a container and having JIB implement all the best practices of packing up a Java application into container with no questions asked.
I have search around but have not found something equivalent for the Node.JS ecosystem.
It should be possible just into a node developer time dependency and it take care on packaging up my javascript/typescript Express.js for example app into a docker container or OCI image.
Thank you, Oscar
For posterity, I'll list some NodeJS-native Docker image creation packages (these usually can be added to your project's package.json). In no particular order:
nodejs-container-image-builder - container registry client and image builder with no dependency on docker (by Google)
Dockta - A Docker image builder for researchers
EZDocker - build docker images in Javascript
I did try Dockta and it has SUPER simple one-liner docker file/image build (either a simple package.json script or direct command line), it works nicely.
Yes, Heroku has a Node.js Buildpack. You can run it using the Pack CLI like this:
$ pack build myimage --builder heroku/buildpacks:18 --buildpack heroku/nodejs
If you are using GitLab, you can simply use Kaniko as well.

How to deploy pytesseract to Heroku

I have a Python app which words great via Localhost on my machine.
I am trying to deploy it to Heroku. However it does not seem possible to accomplish this (I have spent approx 30 hours trying now).
The problem is Tesseract OCR. I am using the pytesseract wrapper, and my code utilises this. However, no matter what I try, it does not seem to be possible to use pytesseract when it is uploaded to Heroku.
Could anyone either suggest how to go about deploying a Hello World Tesseract OCR Python app via pytesseract to Heroku, or if Heroku is not capable of this, suggest an alternative to Heroku?
For anyone else looking to deploy pytesseract on heroku, here are the steps:
Add apt buildpack to heroku
heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt
Create a file named Aptfile in the same directory as your app and these lines to it (for english)
tesseract-ocr
tesseract-ocr-eng
Set heroku config variable TESSDATA_PREFIX to the path of tessdata folder (it was /app/.apt/usr/share/tesseract-ocr/4.00/tessdata for me) which can be found out by running heroku shell using heroku run bash and run this command in the shell
find -iname tessdata
Set the config variable using
heroku config:set TESSDATA_PREFIX=/app/.apt/usr/share/tesseract-ocr/4.00/tessdata
replace the path with the path you got from the previous command
Tesseract should be installed in the heroku app when you build it. Make sure you have pytesseract in your requirements.txt file. Now you should be able import and use pytesseract on heroku
The Python buildpack likely doesn't have the tesseract binaries installed by default. Here’s a third-party buildpack that creates the appropriate environment. Follow the instructions there to make the binary available to your application.

How to download Node.js project deployed on Google Cloud

I have deployed the Node.js code on Google Cloud using following command:-
gcloud app deploy
So, How to download Node.js project deployed on Google Cloud.
I'm not sure but if you need Tomcat server then set and deploy node.js application inside by creating a folder and add the dist folder files in it.
npm install --save #google-cloud/storage
At this point in time it is only possible to download your app's source code for Java, Python, PHP and Golang. The instructions are similar for Python, Golang and PHP:
appcfg.py -A [YOUR_PROJECT_ID] -V [YOUR_VERSION_ID] download_app [OUTPUT_DIR]
where:
[YOUR_PROJECT_ID] is your GCP project ID.
[YOUR_VERSION_ID] is the version ID of your application that you want to download.
[OUTPUT_DIR] is the full directory path to where you want your files downloaded.
In Java you use appcfg.sh:
appcfg.sh -A [YOUR_PROJECT_ID] -V [YOUR_VERSION_ID] download_app [OUTPUT_DIR]
See the link above and also the reference for Java and Python, PHP, Golang

Can I directly use imagemagick in Heroku on node.js

I'm going to deploy my web app soon on Heroku (standard). So can I simply start using Imagemagick right off the bat or not? I already have it installed locally on my computer and obviously have the module required as well in my app.
So will it work exactly as it's working on my machine? like resizing images and getting the src path of images from specific folders like I have on my computer (I'm a newbie at deployment sorry).
You have to add the imagemagick buildpack on heroku:
heroku buildpacks:add --index 1 https://github.com/ello/heroku-buildpack-imagemagick.git
And then you can use a library to call imagemagick

Docker development workflow with node.js

I'm trying to use docker with a node.js web app i'm working on.
I have familiarized myself with the docker concepts and gotten up and running with the example here: https://docs.docker.com/examples/nodejs_web_app/
I get the general process...write a Dockerfile -> Build a docker image -> run it in a VM.
However, it seems impractical to rebuild the image and restart the container every time I change a file.
I currently have a gulp / live-reload setup that works great for development so I was wondering if there was any recommended way of accomplishing something like this with docker.
Thanks!
You can mount the source directory in the container as a volume and use the same gulp/livereload setup that you currently use now. Here's an example project with this setup. If you run into port issues with livereload see here.

Resources