How to Configure Your ACC Application with akinon.json and Procfile?
To run your application on ACC, it must first be containerized. The approach for this will vary based on the programming language and framework you're using—searching for "dockerize $language $framework" is a good way to discover the recommended practices.
ACC packages your application into a Docker container and deploys it on a Kubernetes cluster. To do this, it needs specific instructions on how to build and run your app.
Instead of using a traditional Dockerfile, ACC relies on an app manifest composed of two files: akinon.json
and a Procfile
.
akinon.json
This file outlines the essential details about your application—what it is, how it should be built and executed, and any dependencies it requires to function correctly (such as a database or message broker). It must be placed at the root of your application's repository.
Here’s a minimal example of an akinon.json
file:
Name and description are pretty self-explanatory, they're used to identify your app in the UI.
Scripts are used to build & run your app in different stages of its lifecycle. Since they're executed inside the container, they can use any shell available in the container (sh, bash, xonsh, etc.).
We'll explore other fields and their uses in the following sections.
Converting a Dockerfile into a build script
ACC abstracts Dockerfile
into a script that is run while building the Docker container. It effectively combines all RUN
statements into one. This is to prevent users from generating a massive Docker container, often due to creating too many layers by mistake.
It's best to start from a Dockerfile and later convert it to an app manifest that ACC can understand.
Take this minimal (though not optimized) Dockerfile as an example of a Python application served by Gunicorn server.
We have a number of RUN
commands in the Dockerfile. And an CMD
command that runs starts process.
To create a build script, we combine all RUN
statements. Files inside the repo are copied to the Docker container, and the script is run at the root of the repo.
Then this is specified in akinon.json
under $.scripts.build
, and the base image under $.runtime
:
This also means you can put your scripts under a subdirectory and point to it in $.scripts.build
:
Release Script
Release script is an optional script that is run just before deploying your app. This is usually used to run migrations.
Keep in mind that this script can and will likely be run multiple times, so it must be idempotent, meaning it should expect some changes to be already made by previous runs.
It contents could potentially be:
Formations and Procfile
Formation defines how the app is deployed on a Kubernetes cluster and how many replicas it has or how many instances it can scale to.
Keys of the formation are the names of the processes that are defined in Procfile. We expect to find this file at repo root.
Procfile is a file that contains a list of processes that can be run inside the container.
This command will be used as CMD
statement in the Dockerfile.
For example, if you have a Django app, it is usually served by Gunicorn. But it also needs a worker process to run background tasks.
So we define two processes, both of which will be deployed as separate containers. This means they cannot share state among each other without using a shared database or a broker like Redis.
Healthcheck
If the app is expected to be accessed from the internet, it must have a web
process which listens to all interfaces 0.0.0.0
at port 8008
. And it must have a healthcheck endpoint.
A healthcheck endpoint is a path used that responds to HTTP GET requests to confirm if the app is ready to receive traffic.
It is like the following command that is run inside the container:
After deployment, once the app starts returning HTTP 200 responses from this endpoint, it is assumed to be healthy and ready to serve traffic.
This means, that if the app is not ready to serve traffic, such as, it cannot access the database or other upstream services & APIs it depends on, it should not return HTTP 200 responses from this endpoint. If it does, the traffic will be routed to the app, and it will most likely crash, and return HTTP 500 responses.
It is also possible to use health checks for processes other than web
. In this case, the health check path will correspond to a file rather than an endpoint.
This indicates that if the health check file exists, the deployment is assumed to be healthy. Conversely, if the file is absent, the deployment is assumed to be unhealthy.
The following example demonstrates the process of creating a health check file with Celery:
Addons
With all this information, the app is now ready for deployment. However, most applications require a database to store state, which is provided through addons.
It's an array of objects, each of which defines an addon (with optional configuration).
Each addon causes a number of environment variables to be passed to the container. And the app needs to read these environment variables to configure itself.
You can define a type of addon multiple times, but they must have different roles defined in as
field.
This will cause environment variables to have different prefixes. In this case, the app will have two different Redis instances, and their details will be stored in CACHE_*
and BROKER_*
environment variables.
Postgresql Addon
This addon provides a Postgresql database. It can be defined as follows:
This will pass the following environment variables to the container:
DB_HOST
: the hostname of the databaseDB_PORT
: the port to connect to the hostDB_NAME
: the name of the databaseDB_USER
: the username to connect to the databaseDB_PASSWORD
: the password of the user
Redis Addon
This addon provides a Redis instance to the app. It can be defined as follows:
This will pass the following environment variables to the container:
CACHE_HOST
: the hostname of the Redis instanceCACHE_PORT
: the port to connect to the hostCACHE_DATABASE_INDEX
: the index of the database to use
Combining these, you'll need to prepare a Redis DSN as follows:
Sentry Addon
This addon provides a Sentry DSN to send error logs to. It can be defined as follows:
This will pass the following environment variables to the container:
SENTRY_DSN
: the DSN of the Sentry instance
Mail Addon
This addon provides SMTP details to allow the app to send emails. It's included with every app by default, so it doesn't need to be defined in akinon.json.
This will pass the following environment variables to the container:
EMAIL_HOST
: the hostname of the SMTP serverEMAIL_PORT
: the port to connect to the hostEMAIL_HOST_USER
: the username to connect to the SMTP serverEMAIL_HOST_PASSWORD
: the password of the userEMAIL_USE_TLS
: whether to use TLS or not
CDN Addon
This addon provides a CDN instance to the app. It can be defined as follows:
This will pass the following environment variables to the container:
CDN_DOMAIN
: the domain of the CDN serverS3_BUCKET_NAME
: the name of the AWS S3 bucketS3_REGION_NAME
: the name of the AWS S3 region nameAWS_ACCESS_KEY_ID
: the access key id of the AWS accountS3_SIGNATURE_VERSION
: the signature version of the AWS S3AWS_SECRET_ACCESS_KEY
: the secret access key of the AWS account
Static CDN Addon
This addon provides a Static CDN instance to the app. It can be defined as follows:
This will pass the following environment variables to the container:
BASE_STATIC_URL
: the url of the Static CDN server
Elasticsearch Addon
This addon provides an Elasticsearch instance to the app. It can be defined as follows:
This will pass the following environment variables to the container:
ES_HOST
: the hostname of the Elasticsearch serverES_PORT
: the port to connect to the host
Adding Required Environment Variables in akinon.json
When developing and deploying an extension in ACC, there might be cases where specific environment variables must be set before the extension can be added to a project. For example, sensitive configurations like SECRET_KEY
or critical settings like API_URL
can be defined as prerequisites for installation.
This requirement can be enforced by defining the env
field in the akinon.json
file. The example below includes two required environment variables:
SECRET_KEY
: A sensitive key with specific length constraints.API_URL
: The base URL needed for API communication.
When a user attempts to deploy this extension, ACC validates the env
section in the akinon.json
file. If the required environment variables (SECRET_KEY or API_URL) are not provided or do not meet the specified criteria (e.g., type or length), the deployment process will be interrupted, prompting the user to input the required information.
Last updated
Was this helpful?