Develop an application
This page describes how to develop applications for the SPEKTRA Edge platform.
SPEKTRA Edge utilizes the Docker containers to package and deploy applications for your devices. We follow the standard docker build process for creating applications so that you can benefit from the knowlege and experience you may already have through the prior application development process. Once the image is built, you publish it to one of the container registries to make devices to retrieve and run it on the device.
What you need
To build and publish the application image to the registry, you need:
- Docker Engine on your local machine
- An access to the container registry
Follow the Docker installation guide to install Docker Engine on your machine. For the container registry access, please consult your container registry documentation, e.g. Docker Hub quickstart guide.
Dockerfile
SPEKTRA Edge application development starts with a Dockerfile.
Here is a quote from the official Docker documentation:
Docker builds images by reading the instructions from a Dockerfile. A Dockerfile is a text file containing instructions for building your source code. The Dockerfile instruction syntax is defined by the specification reference in the Dockerfile reference.
Those are the typical instructions used in Dockerfile:
-
FROM <image>
initializes a new build stage and sets the base image for subsequent instructions.
-
RUN <command>
executes any commands to create a new layer on top of the current image.
-
WORKDIR <directory>
sets the working directory for any
RUN
,CMD
,ENTRYPOINT
,COPY
, andADD
instructions that follow it in the Dockerfile. -
COPY <src> <dest>
copies new files or directories from
<src>
and adds them to the filesystem of the image at the path<dest>
. -
CMD <command>
sets the command to be executed when running a container from an image.
Python Flask application example
Let’s take a look at the example Dockerfile, which builds the simple Python Flask application:
# syntax=docker/dockerfile:1
FROM ubuntu:22.04
# Prepare the python environment on the image.
RUN apt-get update && apt-get install -y python3 python3-pip
RUN pip install flask==3.0.*
# Copy the Flask app to the image.
COPY hello.py /
# Run the Flask app.
ENV FLASK_APP=hello
EXPOSE 8000
CMD ["flask", "run", "--host", "0.0.0.0", "--port", "8000"]
with the following hello.py file:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
Place those two files on your current directry.
$ tree .
.
├── Dockerfile
└── hello.py
1 directory, 2 files
then, run the following command to build your application image.
docker build --tag test:latest .
You can give any tag name here, for example awesome:v1.0.0
, but
pick the one you can remember, as you will reference it when you
push it to the container registry.
The last '.' in the command
It’s called Docker build context and specifies the location of the build environment, which in this case, composed of Dockerfile and hello.py files shown above.Now, your application image is ready. Let’s publish it to the container registry next.
Push to registry
Repositories let you share container images to be downloaded by the devices.
In this section, we’ll use the Docker Hub as the container registry, as it’s free and publicly accessible. Please consult your container registry documentation in case you use other one.
Private container registries
You can deploy applications from the private registries on SPEKTRA Edge. Please take a look at the private registries page how to do it.You can create a free account on Docker Hub. Please follow the Docker Hub quickstart guide to create one if you haven’t created.
Here is the simple step to publish your application to the Docker Hub:
-
Login to the Docker Hub:
docker login
-
Re-tag the image you build in the previous step to point to the Docker Hub repository you own:
docker tag test:latest <hub-user>/<repo-name>:<tag>
-
Push the image to the registry:
docker push <hub-user>/<repo-name>:<tag>
Please consult the official Docker documentation if you get error with those commands.
Next step
Once you develop your application and publish it to the registry, it’s time to deploy it on your device. Please move on to the deployment document next.