Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
farm: f0cal/farm@1.0.0
Use farm
elements in your existing workflows and jobs.
Opt-in to use of uncertified orbs on your organization’s Security settings page.
This sample shows how to use the F0cal orb to run a build and tests on a Raspberry PI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
orbs:
farm: f0cal/farm@1.0.0
version: 2.1
workflows:
build-test-deploy:
jobs:
- farm/with_f0cal_device:
api_key: <YOUR F0CAL API KEY ENV VAR >
device_type: raspi
name: test_device
ssh_key_fingerprint: <YOUR SSH_KEY FINGER PRINT>
ssh_key_name: my_key_pair
steps:
- farm/f0cal_run:
command: cmake .
- farm/f0cal_run:
command: make
- farm/f0cal_run:
command: ./bin/test
Run steps on an edge device on the F0cal device farm
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
api_key | Your f0cal api key. Populate via the F0CAL_API_KEY environment variable | No | F0CAL_API_KEY | env_var_name |
device_type | The type of the device, should be one of {nano, tx2, tx1, raspi } | Yes | - | string |
path | The path for the files should be copied to the edge device. Recursive | No | '*' | string |
ssh_key_fingerprint | The fingerprint of the private key. This needs to first be added to the project in circle | Yes | - | string |
ssh_key_name | The name of the ssh key in f0cal. Should correspond to the ssh key added to your project. See docs for more info | Yes | - | string |
steps | Build steps to run on the edge device. Use the farm/f0cal_run command to run them on the edge device | Yes | - | steps |
Copy files needed for the build to the edge device
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
path | The path for the files should be copied to the edge device. Recursive | No | '*' | string |
Run commands over on the edge device via ssh
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
command | The command to run on edge device | No | '*' | string |
Use the f0cal cli to request an edge device and wait for it to be ready
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
device_type | The type of the device, should be one of { nano, tx2, tx1, pi } | Yes | - | string |
ssh_key_name | The name of the ssh key in f0cal. Should correspond to the private key env var set here. See docs for more info | Yes | - | string |
Setup F0cal CLI, VPN key, and SSH keys
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
api_key | Your f0cal api key | Yes | - | string |
ssh_key_fingerprint | The fingerprint of the private key. This needs to first be added to the project in circle | Yes | - | string |
This is the executor that must get used with a f0cal job since we need a vpn at the moment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
commands:
copy_files:
description: |
Copy files needed for the build to the edge device
parameters:
path:
default: '*'
description: The path for the files should be copied to the edge device. Recursive
type: string
steps:
- run:
command: |
scp -r << parameters.path >> f0cal@${DEVICE_IP}:
name: Copy File
f0cal_run:
description: |
Run commands over on the edge device via ssh
parameters:
command:
default: '*'
description: The command to run on edge device
type: string
steps:
- run:
command: |
ssh f0cal@${DEVICE_IP} << parameters.command >>
name: run
install:
description: |
Get the f0cal cli and other dependencies
steps:
- run:
command: |
pyenv uninstall -f 3.6.5
sudo apt-get update
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
pyenv install 3.6.5
name: Fix pyenv dependencies
- run:
command: pyenv global 3.6.5
name: Set Python Version
- run:
command: |
sudo apt update
sudo apt install openvpn
python -m venv /tmp/env
source /tmp/env/bin/activate
pip install --upgrade pip
git clone https://github.com/f0cal/f0cal.farm.client.git /tmp/f0cal.farm.client
pip install /tmp/f0cal.farm.client/ -c /tmp/f0cal.farm.client/constraints.txt
name: Install F0cal CLI and dependencies
request_device:
description: |
Use the f0cal cli to request an edge device and wait for it to be ready
parameters:
device_type:
description: The type of the device, should be one of { nano, tx2, tx1, pi
}
type: string
ssh_key_name:
description: The name of the ssh key in f0cal. Should correspond to the private
key env var set here. See docs for more info
type: string
steps:
- run:
command: |
# Blocking call that wait for a device to be ready. Writes current device id to .f0cal_instance
source /tmp/env/bin/activate
f0cal farm instance create -t << parameters.device_type >> -kp << parameters.ssh_key_name >> --wait
echo "export DEVICE_IP=$(f0cal farm instance get ip)" >> $BASH_ENV
source $BASH_ENV
echo "DEVICE_IP set to $DEVICE_IP"
name: Request a device
- run:
command: |
echo Connected to "$(ssh f0cal@$DEVICE_IP hostname)"
name: Verify the device connection
setup:
description: |
Setup F0cal CLI, VPN key, and SSH keys
parameters:
api_key:
description: Your f0cal api key
type: string
ssh_key_fingerprint:
description: The fingerprint of the private key. This needs to first be added
to the project in circle
type: string
steps:
- add_ssh_keys:
fingerprints:
- << parameters.ssh_key_fingerprint >>
- run:
command: |
${<<parameters.api_key>>:?"<<parameters.api_key>> Env Variable not empty!"}
source /tmp/env/bin/activate
f0cal farm configure -k $<<parameters.api_key>>
f0cal farm vpn create >> f0cal_vpn.txt
sudo openvpn --config f0cal_vpn.txt --daemon
echo 'Waiting for openvpn client to initialize'
sleep 20
name: Configure f0cal cli and connect to f0cal vpn
stop_instance:
description: |
Stop the current device listed in .f0cal_instance
steps:
- run:
command: |
source /tmp/env/bin/activate
f0cal farm instance stop
name: stop device
when: always
description: |
F0cal Farm Orb simplifies interactions with the F0cal device farm allowing you to run your builds on a variety of edge compute devices including the Raspberry Pi, Jetson Nano, and the Jetson TX1 and TX2 and many more.
To gain access to the F0cal device farm please visit https://www.f0cal.com
Orb source: https://github.com/f0cal/farm-orb
examples:
test_on-raspberry-pi:
description: |
This sample shows how to use the F0cal orb to run a build and tests on a Raspberry PI
usage:
orbs:
farm: f0cal/farm@1.0.0
version: 2.1
workflows:
build-test-deploy:
jobs:
- farm/with_f0cal_device:
api_key: <YOUR F0CAL API KEY ENV VAR >
device_type: raspi
name: test_device
ssh_key_fingerprint: <YOUR SSH_KEY FINGER PRINT>
ssh_key_name: my_key_pair
steps:
- farm/f0cal_run:
command: cmake .
- farm/f0cal_run:
command: make
- farm/f0cal_run:
command: ./bin/test
executors:
default:
description: |
This is the executor that must get used with a f0cal job since we need a vpn at the moment
machine:
image: ubuntu-1604:201903-01
jobs:
with_f0cal_device:
description: |
Run steps on an edge device on the F0cal device farm
executor: default
parameters:
api_key:
default: F0CAL_API_KEY
description: Your f0cal api key. Populate via the F0CAL_API_KEY environment
variable
type: env_var_name
device_type:
description: The type of the device, should be one of {nano, tx2, tx1, raspi
}
type: string
path:
default: '*'
description: The path for the files should be copied to the edge device. Recursive
type: string
ssh_key_fingerprint:
description: The fingerprint of the private key. This needs to first be added
to the project in circle
type: string
ssh_key_name:
description: The name of the ssh key in f0cal. Should correspond to the ssh
key added to your project. See docs for more info
type: string
steps:
description: Build steps to run on the edge device. Use the farm/f0cal_run
command to run them on the edge device
type: steps
steps:
- checkout
- install
- setup:
api_key: <<parameters.api_key>>
ssh_key_fingerprint: << parameters.ssh_key_fingerprint >>
- request_device:
device_type: << parameters.device_type>>
ssh_key_name: << parameters.ssh_key_name >>
- copy_files:
path: << parameters.path >>
- steps: << parameters.steps >>
- stop_instance
version: 2.1