Feature Studio: Setting up the Feature Adapter

Created by Peter Norwood, Modified on Thu, 18 May, 2023 at 1:34 PM by Peter Norwood


Note: The steps to set up the Feature Adapter are required if you want to use your own repository and CICD pipeline to develop a new feature. They are not required if you follow the steps outlined in the article on "Feature Studio: How to add a Feature", because these steps are embedded in the scripts in that workflow.


Introduction 

The Pratexo Feature DevTools is a collection of artifacts aimed at helping custom feature developers initialize their feature project and synchronizing their features with the Pratexo Design Studio (PDS). This document will guide custom feature developers through the necessary steps to setup their local environments to run the Pratexo Feature Adapter (PFA). 


Obtaining DevTools 

The DevTools are available from the following public GitHub repository: 

https://github.com/pratexo/feature-devtools 

Using your favorite Git client, clone this repository to your local system and then checkout the latest branch. 

Note that for the remainder of this document, the location on your local system where you cloned DevTools will be referred to as <DEV_TOOLS_INST_DIR> 


Obtaining GCP Data 

The PDS is a hosted SaaS in Google Cloud Platform. In order to properly setup your local development environment for feature development and synchronization with PDS, a few data items will be required. These include: 

  • A GCP project id 
  • A GCP service account application_default_credentials.json file 
  • The name of the GCP bucket that services as the sync inbox for custom features All of this information can be obtained from your Pratexo support personal. 


Setting up Local Environment 

In order to locally run the PFA, your development environment will will require a few tools. The next section covers these requirements. 


Install Docker 

The PFA process is executed as a Docker container, using Docker Compose to start the container. As such, your local development environment will require valid installations of Docker and Docker 

1

Compose. As there are several online installation guides available, it is recommended that, based on your local OS, you search for the appropriate installation guide and follow those steps. 


Install GCloud SDK 

The locally running PFA interacts with Pratexo services that are hosted in Google’s Cloud Platform (GCP). In order to execute the PFA on your local system, the local development environment requires the GCloud SDK. 

As with the previous section on Docker installation, there are many online resources that detail the steps necessary to install GCloud SDK on specific operating systems. Find a suitable guide for your OS and follow those steps. 

Once you have installed GCloud SDK, you will need to enable interaction between GCloud SDK and Docker. In order to facilitate this, execute the following commands on your local development environment: 


gcloud auth login ① 

gcloud auth configure-docker 

① This command will initiate an OAuth flow where you will be required to grant access to GCP resources 


Setting up GCloud SDK will create a ~/.config/gcloud directory on your system. At this point, copy the application_default_credentials.json to ~/.config/gcloud


Create a Features Project Directory 

You should create a directory that will hold all custom developed features. This step is particularly important, as it will be required info to properly start the PFA. 

While the specific directory is not necessarily important, it is recommended that you avoid spaces in the directory name (usually only a concern on Windows systems). Examples of a suitable project directory include: 

/home/svai/pratexocustomfeatures 

/projects/dev/pratexo/custom-features 

Take note of the directory name, as it will be required in the next section. This directory name will also be required during custom feature development, which is covered in a separate document. 


Checkpoint 

The following table will help determine if the prerequisites to execute the PF have been met. 2


Prerequisite 

Have you installed Docker and Docker Compose and verified installation

Completed

Have you install GCloud SDK and verified installation


Have you copied 

application_default_credentials.json to ~/.config/gcloud


Have you created a directory for custom features


If you have answered yes to each of these prerequisites, you can continue onto the next section. 

Start Pratexo Feature Adapter 

The docker-compose-fa.yml file that’s included in the DevTools can be used to startup the PFA on your local development environment. The PFA is a liaison process that serves as a bridge between your local feature files and the PDS. You will interact with the PFA via web calls (curl, wget, Postman, etc) to synchronize your local feature project with the PDS. The PFA will validate your custom feature and ensure that it can be properly integrated into the PDS. 

In order to property start the PFA, you must create an environment file that contains settings that are specific to your local system and your GCP project. Using your favorite editor, create a file with the following information: 


LOCAL_FEATURES_DIRECTORY=your_local_features_directory ① 

ORG_NAME=your_organization_name 

INBOX_BUCKET_NAME=your_inbox_bucket_name ② 

① this should be the directory you created in the previous section 

② should be provided by your Pratexo Support Team 


After you have saved the env file, perform the following commands on your local system to start the PFA 


cd <DEV_TOOLS_INST_DIR> 

gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://gcr.io 

gcloud auth configure-docker 

docker-compose -f docker-compose-fa.yml --env-file <your-env-file> up 

This should output similar to the following: 

3

[+] Running 1/1 

⠿ Container pratexo_adapter Recreated 

0.5s 

Attaching to pratexo_adapter 

pratexo_adapter | 20230127-02:44:27 - INFO - Api starting... 

pratexo_adapter | 20230127-02:44:27 - DEBUG - Loaded config 'GCS_HYBRID' from ENV as: [True] 

pratexo_adapter | 20230127-02:44:27 - INFO - Staring in hybrid mode pratexo_adapter | 20230127-02:44:27 - DEBUG - Loaded config 

'FEATURE_ADAPTER_INBOX_BUCKET' from ENV as: [gman-fa-experiments] 

pratexo_adapter | 20230127-02:44:27 - DEBUG - Checking 

/tmp/.config/gcloud/application_default_credentials.json for explicit credentials as part of auth process... 

pratexo_adapter | 20230127-02:44:27 - DEBUG - Loaded config 

'CORE_FEATURE_LIBRARY_PATH' from ENV as: [/features] 

pratexo_adapter | 20230127-02:44:27 - WARNING - Using GCS Mock 

pratexo_adapter | 20230127-02:44:27 - DEBUG - Mock root path is /features pratexo_adapter | 20230127-02:44:27 - DEBUG - Loaded config 'HOSTNAME' from ENV as: [6aa1df493370] 

pratexo_adapter | 20230127-02:44:27 - DEBUG - Loaded config 'PORT' from ENV as: [8080] 

pratexo_adapter | 20230127-02:44:27 - DEBUG - Loading config 

pratexo_adapter | 20230127-02:44:27 - DEBUG - Loaded config 'ORGANIZATION' from ENV as: [com.biz] 

pratexo_adapter | 20230127-02:44:27 - DEBUG - inbox bucket is custom-feature-bucket pratexo_adapter | 20230127-02:44:27 - DEBUG - organization is com.biz pratexo_adapter | 20230127-02:44:27 - DEBUG - library location is /features pratexo_adapter | 20230127-02:44:27 - DEBUG - hostname is 6aa1df493370 pratexo_adapter | 20230127-02:44:27 - DEBUG - port is 8080 

pratexo_adapter | 20230127-02:44:27 - INFO - Server started 

http://6aa1df493370:8080 If you desire to stop the PFA, issue the following command: 

docker-compose -f docker-compose-fa.yml --env-file=<your-env-file> stop 4

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article