Expandable Properties
We can use some properties inside strings in Azkfile.js
. These special properties are replaced with runtime values.
The pattern used for these properties is #{group.name}
for general properties and ${VAR_NAME}
for environment variables.
Table of contents:
- General Expandable Properties
- Exportable Expandable Properties
- Load Balancer Expandable Properties
- Environment variables
General Expandable Properties:
#{system.name}
Current system name.
Example:
systems: {
sys1: {
envs: {
SYSTEM_NAME: '#{system.name}',
}
}
}
$ azk shell -c 'env'
SYSTEM_NAME=sys1
#{manifest.dir}
Current folder name where Azkfile.js
is located.
Example:
Here we set workdir
as /azk/test
and current folder name is test
.
systems({
sys1: {
...
workdir: '/azk/#{manifest.dir}',
}
});
$ azk shell
/home/projects/test
$ azk shell -c 'pwd'
/azk/test
#{manifest.path}
Current fullpath where Azkfile.js
is located.
Example:
systems: {
sys1: {
envs: {
HOST_MANIFEST_FULL_PATH: '#{manifest.path}',
}
}
}
$ pwd
/home/projects/test
$ azk shell -c 'env'
HOST_MANIFEST_FULL_PATH=/home/projects/test
#{azk.version}
Current azk
version.
Example:
systems: {
sys1: {
envs: {
AZK_VERSION: '#{azk.version}',
}
}
}
$ azk shell -c 'env'
AZK_VERSION=0.16.3
#{azk.default_domain}
Domain name used by azk
(dev.azk.io
by default).
Example:
This is most common use of #{azk.default_domain}
concatenated with the system name.
systems: {
sys1: {
http: {
domains: [ '#{system.name}.#{azk.default_domain}' ],
},
}
}
$ azk status --text
System Instances Hostname/url Instances-Ports Provisioned
sys1 0 sys1.dev.azk.io - -
#{azk.default_dns}
List of available DNS services, separated by commas, in the following order:
azk
DNS;/etc/resolv.conf
DNSes;
Example:
systems: {
sys1: {
envs: {
ALL_DNS: '#{azk.default_dns}',
}
}
}
$ azk shell -c 'env'
ALL_DNS=172.17.0.1,8.8.8.8,8.8.4.4
#{env}
Object with all the available environment variables in the local machine. Use with dot notation (env.VAR
).
Security Alert: Note that Azkfile.js
is part of the code. Sensitive data such as passwords and private tokens should not be placed on Azkfile.js
. Instead, use a .env
file ignored by your version control system.
Example:
systems: {
sys1: {
envs: {
AZK_ENV: '#{env.AZK_ENV}',
}
}
}
$ azk shell -c 'env'
AZK_ENV=development
Exportable Expandable Properties
net.host
, net.port
and envs
expandable properties can only be used on the Azkfile.js
export_envs
section. These properties are only available after system is running.
#{net.host}
Current system host name. Usually is azk.dev.io
while http.domain
is unset.
#{net.port}
Named port exported to dependent system. We have to tell the port name (such as #{net.port.name}
). See the property #{net.port.data}
bellow.
#{envs}
Environment variables to be exported to dependent systems from environment variables declared in envs
properties.
Do not confuse with
#{env}
.
Example:
/tmp/project/Azkfile.js
systems: {
main_system: {
depends: ['mysql']
}
mysql: {
image: { docker: 'azukiapp/mysql:5.6' },
ports: {
// named port: data
data: '3306/tcp',
},
envs: {
// environment variables
// to sensitive data use `.env` file
MYSQL_USER: 'azk',
MYSQL_PASS: 'azk',
MYSQL_DATABASE: '#{manifest.dir}_development',
},
export_envs: {
// Exporting DATABASE_URL.
// Using `envs`, not `env`.
// more info: https://gist.github.com/gullitmiranda/62082f2e47c364ef9617
DATABASE_URL: 'mysql2://#{envs.MYSQL_USER}:#{envs.MYSQL_PASS}@#{net.host}:#{net.port.data}/#{envs.MYSQL_DATABASE}',
}
},
}
$ azk shell main_system -c 'env'
MYSQL_USER: 'azk'
MYSQL_PASS: 'azk'
MYSQL_DATABASE: 'project_development'
DATABASE_URL=mysql2://azk:azk@dev.azk.io:32772/project_development
Load Balancer Expandable Properties
For expandable properties below, there is no guarantee of support in the future. Use them with caution.
#{azk.balancer_ip}
Load Balancer IP
#{azk.balancer_port}
Load Balancer Port
Example:
systems: {
sys1: {
envs: {
BALANCER_IP: '#{azk.balancer_ip}',
BALANCER_PORT: '#{azk.balancer_port}',
}
}
}
$ azk shell -c 'env'
BALANCER_IP=172.17.0.1
BALANCER_PORT=80
Environment variables
Besides the expandable properties, which allow us to access azk
configuration values, it's possible to use environment variables in properties such as command and provision.
Unlike expandable properties, the pattern used for environment variables is ${VAR_NAME}
or $VAR_NAME
.
Obs: Don't mistake this option with the properties #{env}
and #{envs}
described above, which have a different kind of use.
Examples of usage of environment variables:
systems({
web: {
image: { docker: "azukiapp/ruby" },
command: ["bundle", "exec", "rails", "-p", "$HTTP_PORT"],
envs: {
HTTP_PORT: "8080",
},
},
});