Skip to content

Commit f1b02db

Browse files
feat: add feature flag for pre-embargo stuff (#558)
Co-authored-by: Alessio Perugini <alessio@perugini.xyz>
1 parent f5fc8be commit f1b02db

File tree

3 files changed

+55
-54
lines changed

3 files changed

+55
-54
lines changed

Taskfile.yml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ vars:
1111
GOLANGCI_LINT_VERSION: v2.4.0
1212
GOIMPORTS_VERSION: v0.29.0
1313
DPRINT_VERSION: 0.48.0
14-
RUNNER_VERSION: "0.1.16"
1514
EXAMPLE_VERSION: "0.1.18"
1615
VERSION: # if version is not passed we hack the semver by encoding the commit as pre-release
1716
sh: echo "${VERSION:-0.0.0-$(git rev-parse --short HEAD)}"
@@ -327,29 +326,6 @@ tasks:
327326
cp build/remoteocd.exe ~/AppData/Local/Arduino15/packages/arduino/tools/remoteocd/0.0.1/remoteocd.exe
328327
platforms: [windows]
329328
330-
generate:bricks-and-models-index:
331-
desc: This generates the models and bricks index.
332-
cmds:
333-
- |
334-
tmpdir="${TMPDIR:-/tmp}"
335-
semver_tag={{.RUNNER_VERSION}}
336-
ROOT_DEST_DIR=debian/arduino-app-cli/home/arduino/.local/share/arduino-app-cli/assets
337-
DST_DIR="${ROOT_DEST_DIR}/${semver_tag}"
338-
if [ -d "$DST_DIR" ]; then
339-
exit 0
340-
fi
341-
gh release download -R bcmi-labs/app-bricks-py "release/${semver_tag}" -p '*.whl' -D "$tmpdir" --clobber
342-
343-
ZIP_NAME="$tmpdir"/arduino_app_bricks-"${semver_tag}"-py3-none-any.whl
344-
OUTPUT_DIR="${tmpdir}/${semver_tag}"
345-
unzip -o "$ZIP_NAME" -d "$OUTPUT_DIR"
346-
rm -rf "$ROOT_DEST_DIR"
347-
mkdir -p "$ROOT_DEST_DIR"
348-
mv "$OUTPUT_DIR"/arduino/app_bricks/static "$DST_DIR"
349-
rm -r "$OUTPUT_DIR" "$ZIP_NAME"
350-
# Bumps the default pinned latest base python image tag
351-
sed -i "s#runnerVersion = \".*#runnerVersion = \"${semver_tag}\"#" internal/orchestrator/config/config.go
352-
353329
update-deb-copyright:
354330
desc: Extract project and dependency licenses into asd copyright
355331
cmds:

internal/orchestrator/config/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/arduino/go-paths-helper"
1111
)
1212

13-
// Do not manually modify this, we keep it updated with the `task generate:bricks-and-models-index`
1413
var runnerVersion = "0.1.16"
1514

1615
type Configuration struct {

internal/orchestrator/provision.go

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/arduino/go-paths-helper"
2222
"github.com/docker/cli/cli/command"
2323
"github.com/docker/docker/api/types/container"
24-
dockerClient "github.com/docker/docker/client"
2524
yaml "github.com/goccy/go-yaml"
2625
)
2726

@@ -49,30 +48,55 @@ type Provision struct {
4948
pythonImage string
5049
}
5150

51+
// isPreEmbargo checks if the runner version is the pre-embargo version.
52+
// Before the embargo, boards are stuck to run the docker contains version 0.1.16.
53+
// We need to be sure that we aren't enabling features that aren't available in that version, such as:
54+
// - Disable dynamic provisioning
55+
// - Render group functionality
56+
func isPreEmbargo(cfg config.Configuration) bool {
57+
return cfg.RunnerVersion == "0.1.16"
58+
}
59+
60+
func isDevelopmentMode(cfg config.Configuration) bool {
61+
return cfg.RunnerVersion != cfg.UsedPythonImageTag
62+
}
63+
5264
func NewProvision(
5365
docker command.Cli,
5466
cfg config.Configuration,
5567
) (*Provision, error) {
56-
isDevelopmentMode := cfg.UsedPythonImageTag != cfg.RunnerVersion
57-
if isDevelopmentMode {
58-
dynamicProvisionDir := cfg.AssetsDir().Join(cfg.UsedPythonImageTag)
68+
provision := &Provision{
69+
docker: docker,
70+
pythonImage: cfg.PythonImage,
71+
}
72+
73+
if isPreEmbargo(cfg) && !isDevelopmentMode(cfg) {
74+
return provision, nil
75+
}
76+
77+
dynamicProvisionDir := cfg.AssetsDir().Join(cfg.UsedPythonImageTag)
78+
79+
// In development mode we want to make sure everything is fresh.
80+
if isDevelopmentMode(cfg) {
5981
_ = dynamicProvisionDir.RemoveAll()
60-
tmpProvisionDir, err := cfg.AssetsDir().MkTempDir("dynamic-provisioning")
61-
if err != nil {
62-
return nil, fmt.Errorf("failed to perform creation of dynamic provisioning dir: %w", err)
63-
}
64-
if err := dynamicProvisioning(context.Background(), docker.Client(), cfg.PythonImage, tmpProvisionDir.String()); err != nil {
65-
return nil, fmt.Errorf("failed to perform dynamic provisioning: %w", err)
66-
}
67-
if err := tmpProvisionDir.Rename(dynamicProvisionDir); err != nil {
68-
return nil, fmt.Errorf("failed to rename tmp provisioning folder: %w", err)
69-
}
7082
}
7183

72-
return &Provision{
73-
docker: docker,
74-
pythonImage: cfg.PythonImage,
75-
}, nil
84+
if dynamicProvisionDir.Exist() {
85+
return provision, nil
86+
}
87+
88+
tmpProvisionDir, err := cfg.AssetsDir().MkTempDir("dynamic-provisioning")
89+
if err != nil {
90+
return nil, fmt.Errorf("failed to perform creation of dynamic provisioning dir: %w", err)
91+
}
92+
if err := provision.init(tmpProvisionDir.String()); err != nil {
93+
return nil, fmt.Errorf("failed to perform dynamic provisioning: %w", err)
94+
}
95+
if err := tmpProvisionDir.Rename(dynamicProvisionDir); err != nil {
96+
return nil, fmt.Errorf("failed to rename tmp provisioning folder: %w", err)
97+
}
98+
99+
return provision, nil
76100
}
77101

78102
func (p *Provision) App(
@@ -96,13 +120,11 @@ func (p *Provision) App(
96120
return generateMainComposeFile(arduinoApp, bricksIndex, p.pythonImage, cfg, mapped_env, staticStore)
97121
}
98122

99-
func dynamicProvisioning(
100-
ctx context.Context,
101-
docker dockerClient.APIClient,
102-
pythonImage, srcPath string,
123+
func (p *Provision) init(
124+
srcPath string,
103125
) error {
104126
containerCfg := &container.Config{
105-
Image: pythonImage,
127+
Image: p.pythonImage,
106128
User: getCurrentUser(),
107129
Entrypoint: []string{
108130
"/bin/bash",
@@ -117,14 +139,14 @@ func dynamicProvisioning(
117139
Binds: []string{srcPath + ":/app"},
118140
AutoRemove: true,
119141
}
120-
resp, err := docker.ContainerCreate(ctx, containerCfg, containerHostCfg, nil, nil, "")
142+
resp, err := p.docker.Client().ContainerCreate(context.Background(), containerCfg, containerHostCfg, nil, nil, "")
121143
if err != nil {
122144
if errors.Is(err, errdefs.ErrNotFound) {
123-
if err := pullBasePythonContainer(ctx, pythonImage); err != nil {
145+
if err := pullBasePythonContainer(context.Background(), p.pythonImage); err != nil {
124146
return fmt.Errorf("provisioning failed to pull base image: %w", err)
125147
}
126148
// Now that we have pulled the container we recreate it
127-
resp, err = docker.ContainerCreate(ctx, containerCfg, containerHostCfg, nil, nil, "")
149+
resp, err = p.docker.Client().ContainerCreate(context.Background(), containerCfg, containerHostCfg, nil, nil, "")
128150
}
129151
if err != nil {
130152
return fmt.Errorf("provisiong failed to create container: %w", err)
@@ -133,8 +155,8 @@ func dynamicProvisioning(
133155

134156
slog.Debug("provisioning container created", slog.String("container_id", resp.ID))
135157

136-
waitCh, errCh := docker.ContainerWait(ctx, resp.ID, container.WaitConditionNextExit)
137-
if err := docker.ContainerStart(ctx, resp.ID, container.StartOptions{}); err != nil {
158+
waitCh, errCh := p.docker.Client().ContainerWait(context.Background(), resp.ID, container.WaitConditionNextExit)
159+
if err := p.docker.Client().ContainerStart(context.Background(), resp.ID, container.StartOptions{}); err != nil {
138160
return fmt.Errorf("provisioning failed to start container: %w", err)
139161
}
140162
slog.Debug("provisioning container started", slog.String("container_id", resp.ID))
@@ -283,7 +305,11 @@ func generateMainComposeFile(
283305
}
284306

285307
devices := getDevices()
286-
groups := []string{"dialout", "video", "audio", "render"}
308+
309+
groups := []string{"dialout", "video", "audio"}
310+
if !isPreEmbargo(cfg) || isDevelopmentMode(cfg) {
311+
groups = append(groups, "render")
312+
}
287313

288314
mainAppCompose.Services = &mainService{
289315
Main: service{

0 commit comments

Comments
 (0)