newt config
The Newt config action can create a new skeleton YAML file or update
the application’s property of a Newt YAML. It allows you to select which
application is run by newt run
as well as configure those
applications. In addition you can use Newt Config to update the
configurations in the applications’ property. You might need to do this
if the standard ports for the network services need to be changed.
By default if you do not provide a YAML filename the
newt config
command will use the filename of “app.yaml”.
Let’s try creating a “app.yaml” by running the config action.
newt config
You will now get prompted by a series of questions that will configure what is listed inside the applications’ property.
This is a transcript of running newt config
to generated
“app.yaml”.
Creating "app.yaml"
Will app.yaml use Newt Router (Y/n)?
Manage Newt Router Settings
Set [p]ort: 8010
Set [h]tdocs:
Type menu letter and press enter to modify or press enter when done
Will app.yaml use Postgres (Y/n)?
Manage Postgres Settings
Set [p]ort: 5432
Set [d]sn (data source name): postgres://{PGUSER}:{PGPASSWORD}@localhost:5432/app.yaml
Set [n]amespace: app
Type menu letter and press enter to modify or press enter when done
Will app.yaml use PostgREST (Y/n)?
Manage PostgREST Settings
Set [p]ort: 3000
Set [a]pp path: "postgrest"
Set [c]onf path: "postgrest.conf"
Type menu letter and press enter to modify or press enter when done
Will app.yaml use Newt's template engine (Y/n)?
Manage Newt's template engine Settings
Set [p]ort: 8011
Type menu letter and press enter to modify or press enter when done
Will app.yaml need to import environment variables (y/N)?
Will app.yaml provide options to the services (y/N)?
Save and exit (Y/n)?
It appears your are using the git revision control system.
You should make sure that generated code containing secrets is NOT included in your
repository for "app.yaml". It is recommented that add the following to your .gitignore file.
# Newt Project ignore list.
*setup*.sql
postgrest.conf
I’ve just pressed enter at each prompt to accept the defaults. The main questions accept a “Y” or “N” response with the capital letter being the default (i.e. you can just press enter to accept it). The indented blocks are like menus. They have addition keys will which prompt you to change specific settings.
Here’s the generated “app.yaml”.
#/usr/bin/env newt check
#
# This was generated by rsdoiel on 2024-05-22 with newt version 0.0.8 ea131b9.
#
applications:
router:
port: 8010
template_engine:
port: 8011
postgres:
namespace: app
port: 5432
dsn: postgres://{PGUSER}:{PGPASSWORD}@localhost:5432/app.yaml
postgrest:
app_path: postgrest
conf_path: postgrest.conf
port: 3000
enviroment:
- PGUSER
- PGPASSWORD
When I accepted using Postgres the config action knows that the connection string can be built from the standard environment variables expected by Postgres’ psql and database connectors. That is why even through I answered “N” to the question about setting up environment variables to import I still have environment variables listed.
NOTE: The config option can be used to update an existing Newt YAML file, e.g. “app.yaml”. If you change the configuration then you’ll be prompted to save the changes as the last question. If you save the changes the prior file will be saved to a “.bak” version before writing the changes to disk. If you want to abort your changes completely then you can press “control C” to quit at any time before the final save prompt.
Next up Newt Model