Dockerize PreEmptive’s Products Using Floating License

Categories
Support Corner

Published on September 23, 2020 by Matt Insko

Reading Time: 2 minutes

Customers occasionally ask us about adding DashODotfuscator, or JSDefender to their Docker-based build processes. We do not provide pre-built Docker containers for our products, but it is relatively straightforward to create your own containers with the distributions we do provide. Historically, setting up licensing for these containers could be a challenge, but with the recent addition of Floating license support to DashODotfuscator, and JSDefender, even the licensing part is straightforward.

This blog provides example Dockerfiles for each product, as a starting point for building your own containers. You will need to replace {x.y[.z]} with the appropriate major.minor[.patch] version.

Note: Floating licenses require network access. If you need your containers to work offline, contact us for special instructions.

DashO

Here is a sample Dockerfile for DashO:

FROM adoptopenjdk:11.0.8_10-jdk-hotspot

ARG DASHO_BASE="/opt/PreEmptive_Protection_DashO_{x.y}"

ENV DASHO_HOME="${DASHO_BASE}/app"\
    JDK_HOME="/opt/java/openjdk"

# Extract the installer
ADD PreEmptive_Protection_DashO_{x.y.z}.tar.gz $DASHO_BASE

# Link the extracted directory to the standard installation location.
RUN ln -s $DASHO_BASE/PreEmptive\ Protection\ DashO\ {x.y} $DASHO_HOME

# Set up to run the command line interface
ENTRYPOINT ["/opt/PreEmptive_Protection_DashO_{x.y}/app/dashocmd"]

Note: The image has DashO installed to a standard location and also sets DASHO_HOME in the environment. This is helpful if the container will be using the Gradle or Ant integration.

To build this image:

  1. Download the PreEmptive_Protection_DashO_{x.y.z}.tar.gz archive from PreEmptive.
  2. Place PreEmptive_Protection_DashO_{x.y.z}.tar.gz in the same directory as Dockerfile (listed above).
  3. Run docker build -t preemptive/dasho:{x.y.z} {path to the directory containing 'Dockerfile'}.

Running the DashO container is simple, you just need to pass the license information. This can either be mirrored from the current environment:

docker run --rm -e DASHO_LICENSE -v {projectPath}:/code preemptive/dasho:{x.y.z} /code/project.dox

set in the container’s environment:

docker run --rm -e DASHO_LICENSE={LicenseString} -v {projectPath}:/code preemptive/dasho:{x.y.z} /code/project.dox

or passed via the command line:

docker run --rm -v {projectPath}:/code preemptive/dasho:{x.y.z} --license {LicenseString} /code/project.dox

Additional arguments can be found here.

Note: The {projectPath}, provided to the Docker container as a volume, is the path which contains all the files (input, output, etc.) referenced in the DashO configuration file, project.dox.

Dotfuscator

Here is a sample Dockerfile for Dotfuscator:

FROM mcr.microsoft.com/dotnet/core/sdk:2.1

# Copy Dotfuscator to the image

COPY PreEmptive.Protection.Dotfuscator.Pro.{x.y.z}.nupkg .

# Install zip and extract Dotfuscator
RUN apt-get update \
    && apt-get install -y zip \
    && mkdir -p /opt/local/PreEmptive.Protection.Dotfuscator.Pro \
    && unzip PreEmptive.Protection.Dotfuscator.Pro.{x.y.z}.nupkg -d /opt/local/PreEmptive.Protection.Dotfuscator.Pro

# Set up to run the command line interface
ENTRYPOINT ["dotnet", "/opt/local/PreEmptive.Protection.Dotfuscator.Pro/tools/programdir/netcore/dotfuscator.dll"]

To build this image:

  1. Download the PreEmptive.Protection.Dotfuscator.Pro.{x.y.z}.nupkg package from PreEmptive.
  2. Place PreEmptive.Protection.Dotfuscator.Pro.{x.y.z}.nupkg in the same directory as Dockerfile (listed above).
  3. Run docker build -t preemptive/dotfuscator:{x.y.z} {path to the directory containing 'Dockerfile'}.

The Dotfuscator container is run in a similar fashion to DashO except the environment variable is DOTFUSCATOR_LICENSE and the command line argument is /license:<license-string>. Additional arguments can be found here.

JSDefender

Here is a sample Dockerfile for JSDefender:

FROM node:12.16.1

# Copy and install JSDefender
COPY preemptive-jsdefender-*-{x.y.z}.tgz ./
RUN npm install -g preemptive-jsdefender-*-{x.y.z}.tgz --save-dev

# Set up to run the command line interface
ENTRYPOINT ["jsdefender"]

To build this image:

  1. Download the JSDefender packages (e.g. preemptive-jsdefender-core-{x.y.z}.tgzpreemptive-jsdefender-cli-{x.y.z}.tgz, etc) from PreEmptive.
  2. Place them in the same directory as Dockerfile (listed above).
  3. Run docker build -t preemptive/jsdefender:{x.y.z} {path to the directory containing 'Dockerfile'}.

The JSDefender container is run in a similar fashion to DashO except the environment variable is JSDEFENDER_LICENSE. Additional arguments can be found here.

Please Provide Feedback

Containerization is an essential part of modern software development practices, and as part of our ongoing efforts to lower the costs of protecting your code, we’ve made it easy for you to use our products in these scenarios. Please let us know how it works for you!