You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/04.pro/boards/portenta-x8/tutorials/custom-container/content.md
+42-21Lines changed: 42 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: Create and Upload a Custom Container Portenta X8
2
+
title: Create and Upload a Custom Container to the Portenta X8
3
3
difficulty: easy
4
-
tags: [Linux, Python, Containers]
4
+
tags: [Linux, Python, Containers, ADB]
5
5
description: This tutorial will show you how to create and upload your custom container to your Portenta X8
6
6
author: Benjamin Dannegård
7
7
hardware:
@@ -12,7 +12,7 @@ software:
12
12
13
13
## Overview
14
14
15
-
In this tutorial we will create a simple container that we can then upload to the Portenta X8. A container consists of an image file and all it's dependencies if there are any. This tutorial will go through the different files needed to create a container and their functions. Building this container locally and then uploading it to a Portenta X8.
15
+
In this tutorial we will create a simple container that we can then upload to the Arduino Portenta X8. A container consists of an image file and all it's dependencies if there are any. This tutorial will go through the different files needed to create a container and their functions. Building this container locally and then uploading it to a Portenta X8. Using docker with ADB to build, run and attach our container to the Portenta X8.
16
16
17
17
## Goals
18
18
@@ -22,6 +22,8 @@ In this tutorial we will create a simple container that we can then upload to th
- USB-C cable (either USB-C to USB-A or USB-C to USB-C)
25
27
26
28
## Instructions
27
29
@@ -37,10 +39,14 @@ To create our container we need to collect our necessary files. Creating a folde
37
39
- src folder
38
40
- main.py (This file should be inside the src folder)
39
41
42
+
The complete folder will look like this:
43
+
44
+

45
+
40
46
Lets go through what these files contain and do.
41
47
42
48
### docker-buil.conf
43
-
A file containing the minimal "unit test" command to be executed on the container to prove it's working. Our file will make our containers minimal unit test a test of Python3's help commmand.
49
+
A file containing the minimal "unit test" command to be executed on the container to prove it's working. Our file will make our containers minimal unit test a test of Python3 help command.
44
50
45
51
```python
46
52
TEST_CMD="python3 --help"
@@ -70,17 +76,8 @@ services:
70
76
This is used to build the container.
71
77
72
78
```python
73
-
# Copyright (c) 2022 Arduino.cc
74
-
#
75
-
76
-
# Examples:
77
-
# docker build --tag "hello-world:latest" .
78
-
# docker run -it --rm --user "63" hello-world:latest
Here we will keep source code of the app you want to run in the container or simply a startup script. We will create a file and name it **main.py** in this folder. This script will print "Hello World!" in the CLI window.
107
+
Here we will keep source code of the app you want to run in the container or a startup script. We will create a file and name it **main.py** in this folder. This script will print "Hello World!" in the CLI window.
111
108
112
109
```python
113
110
from flask import Flask
@@ -123,21 +120,35 @@ if __name__ == '__main__':
123
120
124
121
## Uploading the Container Folder
125
122
126
-
First, you have to have set up your board to a factory, as shown in the [Portenta X8 Out of the Box tutorial]().
123
+
First, you have to have set up your board to a factory, as shown in the [Portenta X8 Out of the Box tutorial](https://docs.arduino.cc/tutorials/portenta-x8/out-of-the-box).
127
124
128
125
Once this is done, we will push our folder to a repository within the factory. Lets place our folder "x8-custom-test" inside the "containers.git" repository. You can find this repository inside your factory page, if you click on "Source". And then on "container.git", the url of this page will be used in the next command.
129
126
130
-
In bash use the following command, replace the "YOUR_FACTORY" with the name of your factory, to get the container repository, where we will put our folder. The "-m" tag selects the manifest file within the repository. If no manifest name is selected, the default is "default.xml". And the "-b" tag specifies a revision.
127
+

128
+
129
+

130
+
131
+

132
+
133
+
In order to pull or push repositories you have to generate an API key. This can be done by going to the user settings on the Factory page. First click on the user drop-down menu, then go into the tokens page and follow the steps of creating a new API key. This token will be used as the password for all git operations while the username can be anything, except an empty string.
134
+
135
+

136
+
137
+

138
+
139
+
Use the following command in a Linux shell, like ADB which the previously mentioned tutorial showed how to set up. To get the repository on your board, replace the "YOUR_FACTORY" with the name of your factory. The "-m" tag selects the manifest file within the repository. If no manifest name is selected, the default is "default.xml". And the "-b" tag specifies a revision. Running this command will get the container repository, where we will put our folder.
We can also run ```repo sync``` to get the latest version of the repository. Put the "x8-custom-test" folder in the repository.
145
+
We can also run ```repo sync``` to get the latest version of the repository. Put the "x8-custom-test" folder in the repository. If you push the commit to "container.git" a new target will automatically build on your Foundries.io Factory page.
146
+
147
+
*** NOTE: The "repo sync" will at some point pause. This is because it is waiting for a username and password but the prompt will be hidden. Enter the username and password to move on. ***
137
148
138
149
### Building and Running the Container
139
150
140
-
After uploading the folder to the repository. Navigate into the "x8-custom-test" folder, that should be located on your board now. This allows us to build our container with a simple command. Using ```docker build``` with --tag will let us give the container a tag so we can easily keep track of what version of the build this is.
151
+
After uploading the folder to the repository. Navigate into the "x8-custom-test" folder, that should be located on your board now. This allows us to build our container with a simple command. Using ```docker build``` with a ```--tag``` will let us give the container a tag so we can easily keep track of what version of the build this is.
A option for testing an app or container is to use "docker-compose". This is helpful when we have a lot of settings in our "docker-compose.yml" file, since we don't have to use those settings in the run argument with this method. First navigate into the container folder.
156
166
157
167
```python
158
168
cd /home/fio/x8-custom-test
159
169
```
160
170
161
-
This docker-compose command will start your application and register it as a systemd service that will presist even when a reboot occurs. So at the next boot your docker-compose app will run automatically.
171
+
This docker-compose command will start your application and register it as a systemd service that will persist even when a reboot occurs. So at the next boot your docker-compose app will run automatically.
162
172
163
173
```python
164
174
docker-compose up --detach
@@ -171,6 +181,17 @@ docker-compose stop
171
181
```
172
182
173
183
184
+
## Troubleshoot
185
+
186
+
Here are some errors that might occur in the process of this tutorial:
187
+
188
+
- Make sure you have followed our other tutorials that shows how to set up the [Portenta X8 out of the box](https://docs.arduino.cc/tutorials/portenta-x8/out-of-the-box)
189
+
- If you are having issues with the adb shell, don't forget to try and use `sudo` and `su`
190
+
191
+
### Next Steps
192
+
193
+
To get a better understanding of how to manage containers with Docker, take a look at our [Managing Containers with Docker on Portenta X8](https://docs.arduino.cc/tutorials/portenta-x8/docker-container). This tutorial will show some useful commands to use with the docker service and ADB or SSH.
194
+
174
195
## Conclusion
175
196
176
-
This tutorial went through how to create a container for a script or app using Python. And then how to upload this container to a Portenta X8. This is a good method for creating and quickly testing containers. Allowing you to make sure a container works before pushing it to your factory.
197
+
This tutorial went through what goes into a container, how the folder should be built and what files it should contain. It then explained what each files purpose is and what they should contain for this example. Then we went through how this relates back to the factory, and how Foundries.io makes the whole process easier for us. We then showed how to build the container and run it on the Portenta X8. Lastly, we showed a usefull testing feature with docker-compose. Which lets us test our container with a faster process.
0 commit comments