Creating Containers
Overview
Tangram Pro will build container images for your components or transforms when you provide a Dockerfile.
- Images are built for each component separately. Provide a Dockerfile for each one.
- The selected transport(s) will automatically have an image built (except for TCP, UDP and Serial).
- Separate component containers communicate with each other via the transport container.
Dockerfile Suggestions
The first line should include the image you want to create a layer from (e.g. FROM ubuntu:22.04
).
If your container needs to be built with an image from a private registry, you can authorize your Tangram Pro account to access it. You'll need to authorize each private registry for your container before starting a build. See Container Registries
Use COPY
to copy the build artifacts generated by Tangram Pro into the container. (Note: the "Include Generated Code" option must be enabled.)
Copy Component Artifacts
The component artifacts are in a folder named code-gen
FROM ubuntu:22.04
COPY /code-gen /working/code-gen
WORKDIR /working/code-gen
CMD [ "sh", "-c", "sleep 2 && ls *" ]
When run, this container will list the contents of the code-gen folder.
Copy Transform Artifacts
Transform with CSIs
The transform artifacts are in a folder named out
if the build option Generate Transform with CSIs
was used.
FROM ubuntu:22.04
COPY /out /working/out
WORKDIR /working/out
CMD [ "sh", "-c", "sleep 2 && ls *" ]
When run, this container will list the contents of the out folder.
Transform without CSIs
The transform artifacts are in a folder named transform
if the build option Generate Transform Code
was used.
FROM ubuntu:22.04
COPY /transform /working/transform
WORKDIR /working/transform
CMD [ "sh", "-c", "sleep 2 && ls *" ]
When run, this container will list the contents of the transform folder.
Copy Repository Source Code
The root of the linked repository is mounted and its contents available to be copied.
For example, if a component is linked to this repository: https://github.com/TangramFlex/autonomous-uav-demo/, all of its source code is available to be copied into the container. If we only need the source code from the repo's SatNav
directory, we could use the following Dockerfile to copy SatNav src and Makefile, then compile it.
FROM ubuntu:22.04
RUN apt update && apt install -y make g++ build-essential autoconf libssl-dev libtool pkgconf
ENV LD_LIBRARY_PATH=/working/code-gen/build/libs:/working/code-gen/local_install/lib
WORKDIR /working
COPY code-gen /working/code-gen
RUN make -C code-gen
COPY SatNav/src /working/src
COPY SatNav/Makefile /working/
RUN make
CMD ["/working/sat_nav"]
Build Images using a Repository
For this process we assume you have access to a GitHub or GitLab repository that has source code and a Dockerfile.
- Set up a source code host integration. Go to Source Code Integration and follow the instructions to connect to GitLab or GitHub. (This only needs to be done once)
- Open your project and go to Build
- Select a component or transform
- Go to its Code tab, select your source code host, search for and select a repository
- Go to its Actions tab
- Enable
Containerize
- Enable
Include Generated Code
to copy the build artifacts into the container - Choose
Use Dockerfile Path
and enter its path from the root of the linked repository.
e.g. if your Dockerfile is at the root of your repository, then enter
Dockerfile
. If it is in a directory named/writer
, then enterwriter/Dockerfile
. - Enable
- Click Build to start the process
Build Images without a Repository
If you do not need external source code in a container, and only need Tangram Pro-generated code, you can provide a local Dockerfile.
- Open your project and go to Build
- Select a component or transform
- Go to its Actions tab
- Enable
Containerize
- Enable
Include Generated Code
to copy the build artifacts into the container - Choose
Use Local Dockerfile
and upload or input one
- Enable
- Click Build to start the process
Run Containers in Tangram Pro
There are two ways to spin up and run the containers inside of Tangram Pro.
- Use Run to run the containers as defined by your Dockerfiles and view the container logs.
- Use Verify to run a container and test it against a message sequence model.
Run Containers Locally with Docker
The container images that Tangram Pro creates can be run locally from your computer using Docker by downloading an auto-generated docker-compose.yml
file.
- View a completed build that was containerized
- Click the blue Docker Compose button to download its docker-compose.yml file
- Create an API Key for your Tangram User
- Select the Registry Scope.
- Copy the
docker login ...
command and store your token in a safe place
- Install and open the Docker Desktop app
- Open Terminal
- Enter the
docker login ...
command that you copied earlier - Change directory to where you downloaded the docker-compose.yml file, like
cd Downloads
- Enter command
docker compose up
. If you are on a newer version of docker compose, enter commanddocker compose up -d && docker compose logs --follow
to print logs to the terminal
- Enter the