Programming by configuration
About declarative programming and the use of configs for managing systems
It is becoming more popular to use systems which use a config to define how your application should run or how the infrastructure (such as a website or monitor) should be setup. This is declarative programming which means you don’t have to spend time writing step-by-step code which would probably be more detailed and error-prone.
Config-based systems
Below is a list of systems I have worked with or read about which use config files to manage state (such as deploying and running a web application).
- AWS infrastructure management
- DNS and Cloudfront (cache).
- Configuration is managed by a directory Terraform files. Which includes
.tf
and.tfvar
files, depending how you do it.
- DataDog synthetic tests
- Cloud monitoring as a service.
- Configuration is managed by a directory Terraform files.
- See datadoghq.com.
- Containers
- Docker containers
Dockerfile
,docker-compose.yml
.
- Kubernetes (for deploying containers)
- YAML file.
- See declarative config on the Kubernetes docs.
- Helm
- YAML file. This config is known as a “Helm chart”.
- See Getting started for example files and layout. See also helm.sh homepage.
- Docker containers
- Deploys
- CircleCI
config.yml
file.- For Continuous Integration / Continuous Deployments (CI/CD).
- See circleci.com.
- BuildKite
- YAML file configs.
- See buildkite.com
- Deploy applications including running tests and building containers.
- GitHub Pages
_config.yml
.- This describes attributes like the title, URL, theme, Jekyll plugins. Locally you might use a
Gemfile
, but the config itself is sufficient for deploying remotely. See GitHub Pages website.
- Netlify
netlify.toml
.- Netlify is similar to GitHub Pages but allows more fine-grained control. You can use the config to set similar details but also custom build commands (such as using npm, Hugo or Gatsby). While you can set details through the Netlify UI, having it in a config file makes it easier to manage, especially when setting the website up a second time using the same details as before. See Netlify.
- GitHub Actions
.github/workflows/action-name.yml
.- See Actions page on GitHub.
- Can be used running automated tests and publishing a package or deploying. This could be for a Ruby or Python or GitHub Pages project for example. It can also be used for automation like sending a tweet or maintaining a GitHub repo with a bot.
- CircleCI
- Managing servers
- Puppet
puppet.conf
.- See puppet docs.
- Ansible
playbook.yml
.- See Ansible setup on Ubuntu tutorial.
- Chef
.chef/knife.rb
.- See Beginners guide to Chef blog post.
- Puppet
Other declarative systems
Here are some other forms of programming which are not config-based but still use declarative logic, or manage tasks or state at a high-level.
- Jenkins Pipeline
Jenkinsfile
orpipeline.gvy
. This runs in the Groovy language (built on Java) typically on a Jenkins server. This is a way of running named items in a sequence and is useful for deploying to or backing up, especially to multiple servers. You can run groovy scripts and shell commands in the file. See Pipeline doc or Creating your first Pipeline.
- Python Fabric
fabfile.py
See fabfile.org. Similar to Pipeline, Fabric is the Python way of running tasks like shell commands for a deploy.
- React
- See reactjs.org.
- This is a JS library with a main advantage managing state, to make DOM manipulations and preserving state might lighter.
- Postgres
- A flavor of SQL, Postgres is declarative as the SQL query describes what you want to achieve (selecting, grouping, filtering, ordering) and the server decides how to handle this. In fact, you can run the same query multiple times and depending on things like the number of rows or what indexes are available, it can run different logic behind the scenes for the best performance. See the EXPLAIN command.
Resources
- Declarative programming on Wikipedia.
- Imperative vs Declarative Programming blog post.
“Imperative programming is like how you do something, and declarative programming is more like what you do.”