Skip to content

Commit ffafe73

Browse files
authored
fix(front): fix setting default agent type, image in wf editor (#191)
## 📝 Description **Fixes** #187 This PR introduces the following improvements: - Sets the default machine type to the first available self-hosted agent type. - Sets the default container image for promotions that use Docker environments. ### Behavior - **Self-hosted agent default:** When adding a promotion with a block (without overriding global agent definition), the first available self-hosted agent is selected by default. ![Self-hosted default](https://github.com/user-attachments/assets/e53199c0-c9a5-4d41-8256-16db1e3b1a04) - **Docker environment default:** When adding a promotion with a block that uses a Docker environment, the default container image is automatically set. ![Docker image default](https://github.com/user-attachments/assets/e9cd7420-7a3b-4e86-8e35-0bb6c96617e9) ## ✅ Checklist - [x] I have tested this change - [x] ~This change requires documentation update~ - N/A
1 parent 3d12f5b commit ffafe73

File tree

9 files changed

+60
-3
lines changed

9 files changed

+60
-3
lines changed

front/assets/js/workflow_editor/models/agent.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import _ from "lodash"
22

33
import { Container } from "./container"
4+
import { Features } from "../../features"
45

56
export class Agent {
67
// injected when the Editor app starts
@@ -164,12 +165,13 @@ export class Agent {
164165
break
165166

166167
case Agent.ENVIRONMENT_TYPE_DOCKER:
167-
this.type = "e1-standard-2"
168-
this.osImage = this.defaultOSImage(this.type)
168+
const isOS = Features.isEnabled("isOS")
169+
this.type = isOS ? this.defaultMachineTypeForOS() : "e1-standard-2"
170+
this.osImage = isOS ? "" : this.defaultOSImage(this.type)
169171
this.containers = [
170172
new Container(this, {
171173
"name": "main",
172-
"image": "semaphoreci/ubuntu:20.04"
174+
"image": this.getDefaultUbuntuImage()
173175
})
174176
]
175177
break
@@ -183,6 +185,10 @@ export class Agent {
183185
}
184186

185187
defaultMachineType() {
188+
if (Features.isEnabled("isOS")) {
189+
return this.defaultMachineTypeForOS()
190+
}
191+
186192
if (_.includes(this.availableMachineTypes("LINUX"), "e1-standard-2")) {
187193
return "e1-standard-2"
188194
}
@@ -202,6 +208,20 @@ export class Agent {
202208
return ""
203209
}
204210

211+
getDefaultUbuntuImage() {
212+
return Features.isEnabled("isOS")
213+
? "registry.semaphoreci.com/ubuntu:22.04"
214+
: "semaphoreci/ubuntu:20.04"
215+
}
216+
217+
defaultMachineTypeForOS() {
218+
if (this.availableMachineTypes("SELF_HOSTED").length > 0) {
219+
return this.availableMachineTypes("SELF_HOSTED")[0]
220+
}
221+
222+
return "s1-kubernetes"
223+
}
224+
205225
availableOSImages(type) {
206226
if (this.isSelfHostedType(type)) {
207227
return []

front/config/runtime.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,7 @@ config :front,
189189
config :front,
190190
:single_tenant,
191191
System.get_env("SINGLE_TENANT") == "true"
192+
193+
config :front,
194+
:edition,
195+
System.get_env("EDITION", "") |> String.trim() |> String.downcase()

front/helm/templates/job-page.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ spec:
8888
- secretRef:
8989
name: {{ include "secrets.authentication.name" . }}
9090
env:
91+
- name: EDITION
92+
value: {{ .Values.global.edition | quote }}
9193
- name: PORT
9294
value: "4000"
9395
- name: USE_RBAC_API

front/helm/templates/project-page.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ spec:
114114
- configMapRef:
115115
name: {{ .Values.global.internalApi.configMapName }}
116116
env:
117+
- name: EDITION
118+
value: {{ .Values.global.edition | quote }}
117119
- name: AMQP_URL
118120
valueFrom:
119121
secretKeyRef:

front/helm/templates/ui-cache-reactor.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ spec:
6868
env:
6969
- name: START_REACTOR
7070
value: "true"
71+
- name: EDITION
72+
value: {{ .Values.global.edition | quote }}
7173
- name: PREHEAT_PROJECT_PAGE
7274
value: "true"
7375
- name: USE_RBAC_API

front/lib/front.ex

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,28 @@ defmodule Front do
1111
def ce_roles? do
1212
Application.get_env(:front, :ce_roles)
1313
end
14+
15+
@doc """
16+
Check if it's CE edition
17+
"""
18+
@spec ce?() :: boolean()
19+
def ce? do
20+
Application.get_env(:front, :edition) == "ce"
21+
end
22+
23+
@doc """
24+
Check if it's EE edition
25+
"""
26+
@spec ee?() :: boolean()
27+
def ee? do
28+
Application.get_env(:front, :edition) == "ee"
29+
end
30+
31+
@doc """
32+
Check if it's OS edition
33+
"""
34+
@spec os?() :: boolean()
35+
def os? do
36+
ee?() || ce?()
37+
end
1438
end

front/lib/front_web/templates/project/edit_workflow.html.eex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
window.InjectedDataByBackend.Features = <%= raw Poison.encode!(%{
2424
"parameterizedPromotions" => FeatureProvider.feature_enabled?(:parameterized_promotions, param: @conn.assigns.organization_id),
2525
"hidePromotions" => @hide_promotions,
26+
"isOS" => Front.os?(),
2627
"deploymentTargets" => FeatureProvider.feature_enabled?(:deployment_targets, param: @conn.assigns.organization_id),
2728
"uiMonacoWorkflowCodeEditor" => FeatureProvider.feature_enabled?(:ui_monaco_workflow_code_editor, param: @conn.assigns.organization_id),
2829
"useCommitJob" => FeatureProvider.feature_enabled?(:wf_editor_via_jobs, param: @conn.assigns.organization_id)

front/lib/front_web/templates/project_onboarding/setup.html.eex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
window.InjectedDataByBackend.Features = <%= raw Poison.encode!(%{
2222
"parameterizedPromotions" => FeatureProvider.feature_enabled?(:parameterized_promotions, param: @conn.assigns.organization_id),
2323
"hidePromotions" => @hide_promotions,
24+
"isOS" => Front.os?(),
2425
"deploymentTargets" => FeatureProvider.feature_enabled?(:deployment_targets, param: @conn.assigns.organization_id),
2526
"uiMonacoWorkflowCodeEditor" => FeatureProvider.feature_enabled?(:ui_monaco_workflow_code_editor, param: @conn.assigns.organization_id),
2627
"useCommitJob" => FeatureProvider.feature_enabled?(:wf_editor_via_jobs, param: @conn.assigns.organization_id)

front/lib/front_web/templates/workflow/edit.html.eex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
window.InjectedDataByBackend.Features = <%= raw Poison.encode!(%{
1010
"parameterizedPromotions" => FeatureProvider.feature_enabled?(:parameterized_promotions, param: @conn.assigns.organization_id),
1111
"hidePromotions" => @hide_promotions,
12+
"isOS" => Front.os?(),
1213
"deploymentTargets" => FeatureProvider.feature_enabled?(:deployment_targets, param: @conn.assigns.organization_id),
1314
"uiMonacoWorkflowCodeEditor" => FeatureProvider.feature_enabled?(:ui_monaco_workflow_code_editor, param: @conn.assigns.organization_id),
1415
"useCommitJob" => FeatureProvider.feature_enabled?(:wf_editor_via_jobs, param: @conn.assigns.organization_id)

0 commit comments

Comments
 (0)