Jiffy Test Drive

If you want to try a small jiffy generated application without installing jiffy thats fine! Check out the libraryapp showcase to pull a docker image of a compiled jiffy application and follow the tutorial to test it out. If you want to install Jiffy and generate a services application yourself, keep reading!

Application Background

Libraryapp exposes a Library entity and a Book entity in order to simplify the test-drive of a jiffy generated application. To make the experience as straight-forward as possible, the services can be tested simply by loading the docker image (libraryapp.tar) from the libraryapp repository. Alternatively, you can choose to pull down the repository and start the application on your system directly. We will cover both options here.

Getting the Docker Image Installed

  1. Make sure port :8080 is not being held by another process on the host system. Ordinarily this would not be a problem, as we would just edit .dev.config.json to select a different port, but this is not an option when using the preconfigured test-drive image.
  2. Ensure that Docker is installed and running on the host machine.
  3. Clone the libraryapp repository to the host system, or minimally download the libraryapp.tar file from the libraryapp repository.
  4. Use docker load to load the image into docker.
  5. Start the libraryapp image and run some tests with Postman.

Load the Image

The docker load command can be used to extract the libraryapp image from the libraryapp.tar file and load it as a docker image.

Aardvark:libraryapp stevem$ docker load --input libraryapp.tar
01d7fe70da5c: Loading layer [==================================================>]  15.43MB/15.43MB
c12245161295: Loading layer [==================================================>]  4.096kB/4.096kB
f210cee51b6f: Loading layer [==================================================>]   2.56kB/2.56kB
06867f677dc6: Loading layer [==================================================>]   2.56kB/2.56kB
90571e324a88: Loading layer [==================================================>]  2.048kB/2.048kB
b8fb7e4542f7: Loading layer [==================================================>]  24.58kB/24.58kB
fd23e9cd4bef: Loading layer [==================================================>]  1.428MB/1.428MB
0f2acd65de52: Loading layer [==================================================>]  5.811MB/5.811MB
6bb5b02469f6: Loading layer [==================================================>]   4.67MB/4.67MB
Loaded image: libraryapp:latest
Aardvark:libraryapp stevem$

Check that the image has been loaded correctly into the Docker image store.

Aardvark:libraryapp stevem$ docker image ls libraryapp
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
libraryapp          latest              1c2810de379f        3 hours ago         48.2MB
Aardvark:libraryapp stevem$

Once you have reached this point, the image is ready for use and you may pick up at the View the Image Section of the Jiffy with Docker and SQLite tutorial.

Test the Application directly

  1. Pull the libraryapp repository to your local system using the go get command.
  2. Review and edit the .dev.config.json configuration file.
  3. Start the application using the go run command.
go get -u github.com/1414C/libraryapp

Review the .dev.config.json file. You may wish to update the “external_address” value to use a different ipv4 address:port combination. When running a single-instance of a jiffy application there is no need to change the default setting of the “internal_address” key.

The demo is setup to create and use a sqlite3 database, so you will need to ensure that sqlite3 is in the $PATH of the executing user. Alternatively, you may update the keys contained in the “database” block to use another of the supported databases. See the sample database configurations for details.

The “logging” block in the .dev.config.json file contains the settings for the console log. By default the “info” messages are enabled, which will result in a very busy console. Experiment with running the application with different log settings.

{
    "external_address": "127.0.0.1:8080",
    "internal_address": "127.0.0.1:4444",
    "env": "dev",
    "ping_cycle": 1,
    "failure_threshold": 5,
    "pepper": "secret-pepper-key",
    "hmac_Key": "secret-hmac-key",
    "database": {
        "db_dialect": "sqlite",
        "host": "",
        "port": 0,
        "usr": "",
        "password": "",
        "name": "testbd.db",
        "ormLogActive": true,
        "ormDebugTraceActive": false
    },
    "group_leader_kvs": {
        "local_standalone": {
            "active": true,
            "internal_address": "127.0.0.1:4444"
        },
        "redis": {
            "active": false,
            "max_idle": 80,
            "max_active": 12000,
            "redis_protocol": "tcp",
            "redis_address": "127.0.0.1:6379"
        },
        "memcached": {
            "active": false,
            "memcached_addresses": [
                "127.0.0.1:11211"
            ]
        },
        "sluggo": {
            "active": false,
            "sluggo_address": "127.0.0.1:7070"
        }
    },
    "logging": {
        "active": true,
        "callLocation": false,
        "colorMsgTypes": true,
        "infoMsgs": true,
        "warningMsgs": true,
        "errorMsgs": true,
        "debugMsgs": false,
        "traceMsgs": false
    },
    "cert_file": "",
    "key_file": "",
    "rsa256_priv_key_file": "",
    "rsa256_pub_key_file": "",
    "rsa384_priv_key_file": "",
    "rsa384_pub_key_file": "",
    "rsa512_priv_key_file": "",
    "rsa512_pub_key_file": "",
    "ecdsa256_priv_key_file": "",
    "ecdsa256_pub_key_file": "",
    "ecdsa384_priv_key_file": "jwtkeys/ecdsa384/ec384.priv.pem",
    "ecdsa384_pub_key_file": "jwtkeys/ecdsa384/ec384.pub.pem",
    "ecdsa521_priv_key_file": "",
    "ecdsa521_pub_key_file": "",
    "jwt_sign_method": "ES384",
    "jwt_lifetime": 120,
    "service_activations": [
        {
            "service_name": "Library",
            "service_active": true
        },
        {
            "service_name": "Book",
            "service_active": true
        }
    ]
}

Once the .dev.config.json file has been updated to your satisfaction, save it and start the application as follows:

go run main.go -dev

This should result in a lot of output to the console, as the application is creating all of the model artifacts (Library and Book), as well as the database artifacts used to facilitate user access and control.

2020/05/28 14:34:17 sqac init...
successfully loaded the config file...
2020/05/28 14:34:17 SELECT COUNT(*) FROM sqlite_master WHERE type="table" AND name="library";
2020/05/28 14:34:17 SELECT COUNT(*) FROM sqlite_master WHERE type="table" AND name="library";
2020/05/28 14:34:17 CREATE TABLE IF NOT EXISTS "library" ("id" integer PRIMARY KEY AUTOINCREMENT, "name" varchar(255) NOT NULL, "city" varchar(255) NOT NULL, UNIQUE( "id"));
2020/05/28 14:34:17 CREATE INDEX idx_library_name ON library (name);
...
...
...
2020/05/28 14:34:17 SELECT * FROM groupauth WHERE id = 58 LIMIT 1;
2020/05/28 14:34:17 INSERT OR FAIL INTO groupauth ( group_id,  auth_id) VALUES ( 1,  35);
2020/05/28 14:34:17 SELECT * FROM groupauth WHERE id = 59 LIMIT 1;
The Super UsrGroup has been initialized with 59 Auth objects.
re-initializing local middleware to accomodate Super group changes.
WARNING:  2020-05-28T14:34:17.675542769-05:00	reading Usr by email got: sql: no rows in result set
WARNING:  2020-05-28T14:34:19.191808081-05:00	reading Usr by email got: sql: no rows in result set
2020/05/28 14:34:19 INSERT OR FAIL INTO usr ( active,  groups,  name,  email,  password_hash) VALUES ( 1,  'Super',  'Admin',  'admin',  '$2a$14$slyclyuMN6EzcpSxgXX4EuaVMDIAP.MUQWxwByaEYM8ZPnMYlg3oq');
2020/05/28 14:34:19 SELECT * FROM usr WHERE id = 1 LIMIT 1;
admin user created with ID: 1 and initial password of initpass
Development settings selected...
Starting http server on: 192.168.112.35:8080
Listening for ws traffic on: 127.0.0.1:4444
WARNING:  2020-05-28T14:34:24.487568293-05:00	JOIN: no leader detected - setting myID = 1 as leader
initialization complete...
leader info is: {1 127.0.0.1:4444}

At this point the application is ready to be accessed at the <external_address:port> and you may pick up at the Login to the Application section of the Jiffy with Docker and SQLite tutorial. Don’t worry if you are using one of the other database systems; the testing steps will work irrespective of the DBMS used. If you wish to run the tests with TLS (https), check the instructions in the Testing With TLS section of the jiffy documentation.