Altogic CLI
Altogic CLI is the command line interface to create, test and deploy full-code functions to your Altogic backend apps.
Installation
The Algotic CLI is a Node-based command line tool to help you interact with the Altogic Platform API.
Install Using NPM
To install via NPM
$ npm install -g altogic-cli
Once the installation is complete, you can verify the installation using
$ altogic -v
Dependencies
The following dependencies are required. By default, when you create a new full-code function using the CLI, Altogic CLI clones a starter project from the Git repository.
- Git
Getting Started
Before using the CLI, you need to log in to your Altogic account.
$ altogic login
? Enter your email or username: [email protected]
? Enter your password: ********
If you have signed up to your Account using your Google credentials, a 6-digit authorization code is sent to your email address. You need to type this code to complete your login.
Once authorized, your session information will be locally stored so that you do not need to log in again, until you log out from your active session. To log out from your current session, you can run the following command.
$ altogic logout
Creating a function
Once logged in, you can create your full-code function. It will first ask you to select the application you want to create the function for. Following app selection, you need to provide a name to your function and select the runtime environment.
$ altogic create function
? To which application do you want to add the new function?
1) Random quotes (611e7f8ae1a047001ccb65a8)
2) Book reviews (6124cfbacc2932001a1afc5c)
3) Instangram clone (612bdfbb8aa25b0019206549)
(Move up and down to reveal more choices)
Answer: 1
? What is the name of your function? send-daily-digest
? What is the runtime of your function?
1) node.js-14.5
2) node.js-16.0
3) node.js-18.0
Answer: 2
The create function
command will create a folder in your current directory using the name of your function and it will also create an altogic.json
file to keep the configuration parameters.
You can use your code editor to write the code for your function. By default, the entrypoint of your cloud function is src/index.js
which exports the function code.
If you change the entrypoint file of your function, you need to edit the entrypoint entry in
altogic.json
configuration file.
Deploying a function
Once you are ready to deploy your function to your app environment, you can run the deploy
command within the directory of the altogic.json
file.
$ altogic deploy
If you have a single execution environment for your app, your full-code function will be deployed to this environment. If you have more than one environment, you will be prompted to select the deployment environment.
Following the deploy command, Altogic will create the Docker image of your function and deploy it to your app's execution environment. Depending on the dependencies, the build and deploy process can take a couple of minutes to complete.
Monitoring build and deploy status
Following the execution of the deploy
command, you can monitor the status of your cloud function's build and deployment. For each deployment, Altogic creates a new Docker image of your cloud function.
To get the status of builds, run get builds
command.
$ altogic get builds
To get the status of deployments, run get deployments
command.
$ altogic get deployments
Accessing build and deployment logs
You can also access the entire build and deployment logs of your functions from the CLI. To get the build logs of a specific of a function build, run the following command with the build id value.
$ altogic logs build <buildId>
Similarly, to get the deployments logs of a specific deployment of a full-code function, run the following command with the deployment id value.
$ altogic logs build <deploymentId>
Local testing your functions
You can test your node.js runtime functions locally by running the start
command. This command will launch a local HTTP server and provide you the endpoint (URL) of the function. The start
command has hot-reloading capabilities. It will watch for any changes to your files and restart the HTTP server.
$ altogic start
Local development HTTP server running at port:4000.
You can now test your function using the following endpoint: http://localhost:4000
Linking your function to triggers
After writing and successfully deploying your function to your execution environment, you need to link your function to an endpoint, message queue, and/or scheduled task. You can use Altogic Designer to configure your endpoint, message queue, and cron job handlers. After linking your functions, you can invoke them by sending a RESTful API request to the linked endpoint, submitting a message to the linked queue or they can also be invoked by the linked scheduled task (e.g., cron-job) trigger.
Altogic CLI commands
The Altogic CLI follows the following general syntax.
$ altogic [command] [sub-command] --[options]
To view the list of available commands, run the following command:
$ altogic
login
The login command allows you to authenticate a user into the CLI using Altogic credentials. If you have signed up to your Account using your Google credentials, a 6-digit authorization code is sent to your email address. You need to type this code to complete your login. Once authorized, your session information will be locally stored so that you do not need to log in again, until you log out from your active session. To log out from your current session, you can run the following command.
The Altogic CLI follows the following general syntax.
$ altogic login
logout
The logout command allows you to logout from the CLI. After successful logout, your session information will be removed from local storage.
$ altogic logout
config
The config command displays current configuration information about logged in user, default application (if any) and default application environment (if any). You can also use the config command to update configuration parameters stored locally.
$ altogic config
To get only the logged in user information from the configuration, run the following command:
$ altogic config get-user
To get default app information from the configuration, run the following command:
$ altogic config get-app
To set default app information in the configuration, run the following command. If you provide the appId (optional), the default app will be set to the provided appId. If appId is omitted, a list of applications of the logged in user will be displayed and you can select the default application from this list.
$ altogic config set-app [appId]
To get default environment information from the configuration, run the following command:
$ altogic config get-env
To set default environment information in the configuration, run the following command. If you provide the envId (optional), the default environment will be set to the provided envId. If envId is omitted, a list of environments of the default app will be displayed and you can select the default environment from this list.
$ altogic config set-env [appId]
To clear the default app and environment configuration, you can run the following command:
$ altogic config clear-app
To clear the default environment configuration, you can run the following command:
$ altogic config clear-env
create
The create command initializes a new full-code function. If no default app is specified in the configuration, it prompts to select the application, asks for the name of the new function and prompts to select the function's runtime. If successful, it creates a new folder with the given function name and clones a starter repository of the selected runtime from GitHub.
$ altogic create function
deploy
The deploy command provides a wrapper for deploying your function to the selected application environment. If you specify the envId (optional) parameter, it deploys the function to the specified environment, otherwise prompts you to select an application environment if there is more than one environment. This command actually performs what build
and apply
commands do individually.
info
You need to run the deploy command under the root directory of your function, where the function's altogic.json file is stored.
$ altogic deploy --env [envId]
build
The build command creates a docker image of your function. This command does not perform the actual deployment.
$ altogic build
apply
The apply command deploys a specific build of your function to the selected application environment. If buildId (optional) is not specified, prompts you to select a build of your function. If envId (optional) is not specified, prompts you to select the deployment environment of your application
$ altogic apply --build [buildId] --env [envId]
undeploy
The undeploy command removes the function deployment from the specified application environment. If you specify the envId (optional) parameter, it deploys the function to the specified environment, otherwise prompts you to select an application environment if there is more than one environment.
$ altogic undeploy --env [envId]
get
The get command returns information about the logged in users's apps, environments and functions
To get the list of apps of the logged in user, run the following command:
$ altogic get apps
To get the list of environments of an app, run the following command. If you specify the appId (optional) parameter, it lists the environments of the specified app, otherwise prompts you to select an application.
$ altogic get envs --app [appId]
To get the list of functions of an app, run the following command. If you specify the appId (optional) parameter, it lists the functions of the specified app, otherwise prompts you to select an application.
$ altogic get functions --app [appId]
To get the list of builds of a function, run the following command. If you run this command from the root directory of your function where the altogic.json
file is stored, you do not need to specify the appId and functionId. Otherwise, you need to provide the appId and functionId parameters.
$ altogic get builds --app [appId] --func [functionId]
To get the list of deployments of a function, run the following command. If you run this command from the root directory of your function where the altogic.json
file is stored, you do not need to specify the appId and functionId. Otherwise, you need to provide the appId and functionId parameters.
$ altogic get deployments --app [appId] --func [functionId]
logs
The logs command returns build and deployment CI/CD logs.
To get the specific build logs of a function, run the following command. If you run this command from the root directory of your function where the altogic.json
file is stored, you do not need to specify the appId and functionId, you just need to specify the buildId. Otherwise, you need to provide the appId and functionId parameters.
$ altogic logs build --app [appId] --func [functionId] [buildId]
To get the specific deployment logs of a function, run the following command. If you run this command from the root directory of your function where the altogic.json
file is stored, you do not need to specify the appId and functionId, you just need to specify the deploymentId. Otherwise, you need to provide the appId and functionId parameters.
$ altogic logs deployment --app [appId] --func [functionId] [deploymentId]
start
The start command helps you to locally test your function. This command will launch a local HTTP server and provide you with the endpoint (URL) of the function. The start
command has hot-reloading capabilities. It will watch for any changes to your files and restart the HTTP server. If the port number is not specified, it spins up the HTTP server at port 4000.
$ altogic start [port]
Uninstall Altogic CLI
You can use the following command to uninstall the CLI.
$ npm uninstall -g altogic-cli