Docker

Docker is a convenient and efficient method to run the Babel Licensing Service for testing purposes. Docker provides a lightweight and isolated environment called a container, which encapsulates the Babel Licensing Service and all its dependencies, making it easy to deploy and test the service on various systems without worrying about compatibility issues or conflicts with the host environment.

Prerequisites

  1. Babel Licensing Service ZIP package (babel_service_net80_10.x.y.zip)

  2. Babel Obfuscator Company License file (babel.licenses)

Before proceeding, it is important to ensure that Docker is installed on your system. Visit the official Docker website and follow the provided installation instructions specific to your operating system. Complete the installation process to have Docker up and running.

Setting up the Babel Licensing Service on Docker is a straightforward process. In this comprehensive guide, we will walk you through the step-by-step instructions to ensure a successful installation.

Create the Dockerfile

To prepare the environment for building the Babel Licensing Service image using Docker, please follow the steps below.

  1. Begin by establishing a folder on your local machine specifically designated for working with the Babel Licensing Service files. We will refer to this folder as "working folder".

  2. Copy the Babel Licensing Service ZIP archive and the babel.licenses file into the working folder created in the previous step.

  3. Extract the contents of the Babel Licensing Service ZIP archive into a subfolder titled "babel" within the working folder.

  4. Within the working folder, create a new file named "Dockerfile." You may utilize a text editor or integrated development environment (IDE) of your preference to generate this file.

  5. Copy the content provided for the Dockerfile below and save it into the newly generated "Dockerfile" file.

FROM mcr.microsoft.com/dotnet/aspnet:8.0 as runtime

# Expose service ports
EXPOSE 5005

# Set working directory
WORKDIR /var/www/babel-lic

# Copy babel licensing service files to working directory
COPY /babel .

# Copy licene file to working directory
COPY /babel.licenses .

# Set entrypoint
ENTRYPOINT [ "dotnet", "Babel.Licensing.Service.dll" ]

Let's break down its contents:

FROM mcr.microsoft.com/dotnet/aspnet:8.0 as runtime

This line specifies the base image for the Docker container. In this case, it is using the ASP.NET runtime image from Microsoft's Container Registry.

EXPOSE 5005

The EXPOSE instruction specifies that the container exposes this port to the host machine, allowing external access.

WORKDIR /var/www/svc/babel

The WORKDIR instruction sets the working directory inside the container to /var/www/svc/babel. This is the location where subsequent commands will be executed.

COPY /babel .

This line copies the contents of the babel directory (containing the Babel Licensing Service files) from the babel working folder directory into the container's working directory /var/www/svc/babel.

COPY /babel.licenses .

Similarly, this line copies the babel.licenses file from the build context into the container's working directory.

ENTRYPOINT [ "dotnet", "Babel.Licensing.Service.dll" ]

The ENTRYPOINT instruction specifies the command that will be executed when the container starts. In this case, it is running the dotnet command with the Babel.Licensing.Service.dll as the entry point for the Babel Licensing Service.

This Dockerfile sets up the necessary environment, exposes the required port, copies the service files and license file, and defines the entry point for the Babel Licensing Service.

Once built using Docker, this image can be used in conjunction with Docker Compose to deploy the Babel Licensing Service.

Docker Compose

So far, we have instructed Docker to build the image that runs the Babel Licensing Service, but we have not instructed the configuration to actually startup any database.

To configure the complete setup for the Babel Licensing Service, including the necessary database, we will create a new file named docker-compose.yml in the working folder. Add the following content to the docker-compose.yml file:

version: '3.7'

services:
  # Database
  db:
    image: mysql:latest
    volumes:
      - type: volume
        source: dbdata
        target: /var/lib/mysql
    restart: always 
    ports:
      - '6610:3306'
    environment:
      MYSQL_ROOT_PASSWORD: eWk4fSTa45PGpJ
      MYSQL_DATABASE: licenses
      MYSQL_USER: babel
      MYSQL_PASSWORD: babel
    networks:
      - babellic
  # Babel Licensing
  licensing:
    depends_on:
      - db
    container_name: babel-licensing
    restart: always
    build:
      dockerfile: Dockerfile
      context: .
    image: babel/licensing:latest
    ports:
      - '5005:5005'
    environment:
      DOTNET_CLI_HOME: /tmp

      # Environment
      ASPNETCORE_ENVIRONMENT: Production

      # Service Address
      KESTREL__ENDPOINTS__GRPC__URL: http://*:5005

      # Available database providers: SQLServer, MySQL, SQLite
      BABEL_SERVICE_DATABASE__PROVIDER: MySQL

      # Connection strings environment variables
      # SQL Server: BABEL_SERVICE_CONNECTIONSTRINGS__SQLSERVER
      # MySQL: BABEL_SERVICE_CONNECTIONSTRINGS__MYSQL
      # SQLite: BABEL_SERVICE_CONNECTIONSTRINGS__SQLITE
      BABEL_SERVICE_CONNECTIONSTRINGS__MYSQL: Server=db;User=babel;Password=babel;Database=licenses

      # Authentication token variables
      BABEL_SERVICE_APPLICATION__SIGNINGKEY: q9F0nLFRuphIHUdrlphe
      BABEL_SERVICE_APPLICATION__TOKENEXPIRATION: 00:30:00

      # Licensing variables
      BABEL_SERVICE_LICENSING__HEARTBEATINTERVAL: 00:05:00

      # Reporting variables
      BABEL_SERVICE_REPORTING__ENCRYPTIONKEY: p5UwIWaqaChLxe3eJA9o
      
    networks:
      - babellic
networks:
  babellic:
volumes:
  dbdata:
  licensing:

The docker-compose.yml file defines an application with two services: licensing and db. The image for the licensing service is built using the specified Dockerfile.

When deploying the application using Docker Compose, the container port 5005 is mapped to the host port 5005, as indicated in the file. Please ensure that the port 5005 on the host machine is not being used by another container. If it is, you can modify the port to an available one.

Remember to replace the MySQL root and user passwords with strong and secure passwords (you don't need to remember them) under the db service and inside the Babel Service Connection string. The user password is used to set up the connection with the MySQL database.

The docker-compose.yml file is responsible for defining how the Docker images interact with each other at runtime. It specifies the necessary configurations, environment variables, and network setup for the services. By using Docker Compose with this file, you can easily deploy and manage the Babel Licensing Service along with the associated database.

Starting the Service

After setting up the docker-compose.yml file as described in the previous paragraph, you can proceed to run the command:

docker-compose up -d

This command will start the Babel Licensing Service and the associated database in detached mode. Wait for the containers to start: Docker Compose will start pulling the required images (if not already present) and create the containers based on the configurations specified in the docker-compose.yml file. It may take a few moments for the containers to be fully up and running.

After running the command, you can use the docker ps command to verify that the containers are running. It will display a list of running containers along with their details, including the Babel Licensing Service and the associated database container.

$ docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS          PORTS                               NAMES
5d2d3fc62f0a   babel/licensing:latest   "dotnet Babel.Licens…"   25 seconds ago   Up 23 seconds   0.0.0.0:5005->5005/tcp              babel-licensing
0e4245f683cf   mysql:latest             "docker-entrypoint.s…"   25 seconds ago   Up 24 seconds   33060/tcp, 0.0.0.0:6610->3306/tcp   babel-licesing-db-1

Stopping the Service

To stop and remove the containers, as well as delete the associated volumes, you can use the following commands:

  1. Stop and Remove Containers: To stop and remove the containers that were created using Docker Compose, execute the following command:

$ docker compose down

The down command halts and removes the containers defined in the docker-compose.yml file. It stops the running containers and removes their associated resources, such as networks and volumes while preserving the images.

  1. Stop and Delete Volumes: If you also want to delete the volumes associated with the containers, you can use the -v flag with the down command. Run the following command:

$ docker compose down -v

Adding the -v flag instructs Docker Compose not only to stop and remove the containers but also to delete the volumes that were created during the container lifecycle. This ensures the clean removal of all resources related to the containers including the database data files.

Please note that when executing these commands, it is important to be in the same directory where the docker-compose.yml file is located. Additionally, make sure you have Docker Compose installed and available in your command-line environment.

By running docker compose down or docker compose down -v, you will effectively stop and remove the containers, as well as delete the associated volumes, cleaning up the resources used by the Babel Licensing Service.

Configure Babel Licensing Service

The docker-compose.yml file allows you to configure the environment for the babel-licensing service container by specifying several environment variables. These variables override the default configuration settings of the Babel Licensing Service, which are stored in the appsettings.json file. Here is an expanded description of the available configuration variables:

  1. DOTNET_CLI_HOME: Specifies the location of the CLI (Command Line Interface) temporary directory for .NET. In this case, it is set to /tmp.

  2. ASPNETCORE_ENVIRONMENT: Sets the environment for the Babel Licensing Service to run in. The value Production indicates that the service is running in a production environment.

  3. KESTREL__ENDPOINTS__GRPC__URL: Defines the URL for the GRPC endpoint of the Babel Licensing Service. In this case, it is set to http://*:5005, indicating that the service listens on all available network interfaces on port 5005.

  4. BABEL_SERVICE_DATABASE__PROVIDER: Specifies the database provider to be used by the Babel Licensing Service. The value MySQL indicates that MySQL will be used as the database provider.

  5. BABEL_SERVICE_CONNECTIONSTRINGS__MYSQL: Sets the connection string for the MySQL database. It specifies the server, user, password, and database name to be used by the Babel Licensing Service.

  6. BABEL_SERVICE_APPLICATION__SIGNINGKEY: Defines the signing key used for generating and validating authentication tokens for the Babel Licensing Service.

  7. BABEL_SERVICE_APPLICATION__TOKENEXPIRATION: Sets the expiration time for authentication tokens issued by the Babel Licensing Service.

  8. BABEL_SERVICE_LICENSING__HEARTBEATINTERVAL: Specifies the maximum interval at which the clients must send heartbeats to the Babel Licensing Service. The format is hh:mm:ss, indicating the time interval between each heartbeat.

  9. BABEL_SERVICE_REPORTING__ENCRYPTIONKEY: Defines the encryption key used for encrypting data in the reporting functionality of the Babel Licensing Service.

These environment variables allow you to customize and configure various aspects of the Babel Licensing Service according to your specific requirements. By overriding these variables in the docker-compose.yml file, you can modify the service's behaviour without modifying the original appsettings.json file, providing flexibility and ease of configuration.

MSSQL Server Docker Image

To configure Babel Licensing with MSSQL in Docker, the setup utilizes the latest Azure SQL Edge image, which is compatible with Linux Ubuntu. The YAML configuration provided outlines key environment variables essential for database access, authentication tokens, and licensing parameters. This approach streamlines the deployment and integration of Babel Licensing with an MSSQL database within a Docker environment.

version: '3.7'

services:
  # Database
  ms-sql-server:
    image: mcr.microsoft.com/azure-sql-edge:latest
    volumes:
      - events_mssql:/var/opt/mssql
    restart: always 
    ports:
      - '1433:1433'
    environment:
      MSSQL_SA_PASSWORD: eWk4fSTa45PGpJ
      ACCEPT_EULA: Y
      DATABASE: licenses
    networks:
      - babellic
  # Babel Licensing
  licensing:
    depends_on:
      - ms-sql-server
    container_name: babel-licensing-mssql
    restart: always
    build:
      dockerfile: Dockerfile
      context: .
    image: babel/licensing:latest
    ports:
      - '5005:5005'
    volumes: 
      - type: bind
        source: ./babel
        target: /var/www/babel-lic
    environment:
      DOTNET_CLI_HOME: /tmp

      # Environment
      ASPNETCORE_ENVIRONMENT: Production

      # Service Address
      KESTREL__ENDPOINTS__GRPC__URL: http://*:5005

      # Available database providers: SQLServer, MySQL, SQLite
      BABEL_SERVICE_DATABASE__PROVIDER: SQLServer

      # Connection strings environment variables
      # SQL Server: BABEL_SERVICE_CONNECTIONSTRINGS__SQLSERVER
      # MySQL: BABEL_SERVICE_CONNECTIONSTRINGS__MYSQL
      # SQLite: BABEL_SERVICE_CONNECTIONSTRINGS__SQLITE
      BABEL_SERVICE_CONNECTIONSTRINGS__SQLSERVER: data source=ms-sql-server;user id=sa;password=eWk4fSTa45PGpJ;initial catalog=licenses;trusted_connection=false;encrypt=false

      # Authentication token variables
      BABEL_SERVICE_APPLICATION__LOGTODATABASE: true
      BABEL_SERVICE_APPLICATION__SIGNINGKEY: q9F0nLFRuphIHUdrlphe
      BABEL_SERVICE_APPLICATION__TOKENEXPIRATION: 00:30:00

      # Licensing variables
      BABEL_SERVICE_LICENSING__HEARTBEATINTERVAL: 00:05:00

      # Reporting variables
      BABEL_SERVICE_REPORTING__ENCRYPTIONKEY: p5UwIWaqaChLxe3eJA9o
      
    networks:
      - babellic
networks:
  babellic:
volumes:
  events_mssql:
  licensing:
  

By using Docker, you can quickly set up an instance of the Babel Licensing Service without having to manually configure and install all the required dependencies on your local machine or server. This means you can avoid potential conflicts with existing software versions or dependencies, streamlining the setup process and saving time.

Last updated