Skip to content

Commit

Permalink
fix: allow starlark limit to be customized (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 authored Aug 21, 2024
1 parent 8284887 commit 1459f61
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ VELA_API=http://localhost:8080
# default: 30
# VELA_MAX_BUILD_LIMIT=

# customize the max number of starlark exec steps that the UI will allow an admin to configure
#
# default: 99999
# VELA_MAX_STARLARK_EXEC_LIMIT=

# customize the set of repos that are allowed to use schedules
#
# default: *
Expand Down
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -eu
for f in /usr/share/nginx/html/*.js
do
# shellcheck disable=SC2016
envsubst '${VELA_API},${VELA_DOCS_URL},${VELA_FEEDBACK_URL},${VELA_MAX_BUILD_LIMIT},${VELA_SCHEDULE_ALLOWLIST}' < "$f" > "$f".tmp && mv "$f".tmp "$f"
envsubst '${VELA_API},${VELA_DOCS_URL},${VELA_FEEDBACK_URL},${VELA_MAX_BUILD_LIMIT},${VELA_MAX_STARLARK_EXEC_LIMIT},${VELA_SCHEDULE_ALLOWLIST}' < "$f" > "$f".tmp && mv "$f".tmp "$f"
done

NGINX_CONF=/etc/nginx/conf.d/default.conf
Expand Down
14 changes: 7 additions & 7 deletions src/elm/Pages/Admin/Settings.elm
Original file line number Diff line number Diff line change
Expand Up @@ -876,22 +876,22 @@ view shared route model =
[ viewFieldHeader "Starlark Exec Limit"
, viewFieldDescription "The number of executions allowed for Starlark scripts."
, viewFieldEnvKeyValue "VELA_COMPILER_STARLARK_EXEC_LIMIT"
, viewFieldLimits <| text <| numberBoundsToString starlarkExecLimitMin starlarkExecLimitMax
, viewFieldLimits <| text <| numberBoundsToString starlarkExecLimitMin <| starlarkExecLimitMax shared
, div [ class "form-controls" ]
[ Components.Form.viewNumberInput
{ title = Nothing
, subtitle = Nothing
, id_ = starlarkExecLimitHtmlId
, val = model.starlarkExecLimitIn
, placeholder_ = numberBoundsToString starlarkExecLimitMin starlarkExecLimitMax
, placeholder_ = numberBoundsToString starlarkExecLimitMin <| starlarkExecLimitMax shared
, wrapperClassList = [ ( "-wide", True ) ]
, classList_ = []
, rows_ = Nothing
, wrap_ = Nothing
, msg = StarlarkExecLimitOnInput
, disabled_ = False
, min = Just starlarkExecLimitMin
, max = Just starlarkExecLimitMax
, max = Just <| starlarkExecLimitMax shared
}
, Components.Form.viewButton
{ id_ = starlarkExecLimitHtmlId ++ "-update"
Expand All @@ -908,7 +908,7 @@ view shared route model =
limit
== s.compiler.starlarkExecLimit
|| (limit < starlarkExecLimitMin)
|| (limit > starlarkExecLimitMax)
|| (limit > starlarkExecLimitMax shared)

Nothing ->
True
Expand Down Expand Up @@ -1269,6 +1269,6 @@ starlarkExecLimitMin =

{-| starlarkExecLimitMax : returns the maximum value for the starlark exec limit
-}
starlarkExecLimitMax : Int
starlarkExecLimitMax =
9999
starlarkExecLimitMax : Shared.Model -> Int
starlarkExecLimitMax shared =
shared.velaMaxStarlarkExecLimit
4 changes: 4 additions & 0 deletions src/elm/Shared.elm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type alias Flags =
, velaRedirect : String
, velaLogBytesLimit : Int
, velaMaxBuildLimit : Int
, velaMaxStarlarkExecLimit : Int
, velaScheduleAllowlist : String
}

Expand All @@ -72,6 +73,7 @@ decoder =
|> required "velaRedirect" Json.Decode.string
|> required "velaLogBytesLimit" Json.Decode.int
|> required "velaMaxBuildLimit" Json.Decode.int
|> required "velaMaxStarlarkExecLimit" Json.Decode.int
|> required "velaScheduleAllowlist" Json.Decode.string


Expand All @@ -95,6 +97,7 @@ init flagsResult route =
, velaRedirect = ""
, velaLogBytesLimit = 0
, velaMaxBuildLimit = 0
, velaMaxStarlarkExecLimit = 0
, velaScheduleAllowlist = ""
}

Expand Down Expand Up @@ -134,6 +137,7 @@ init flagsResult route =
, velaRedirect = flags.velaRedirect
, velaLogBytesLimit = flags.velaLogBytesLimit
, velaMaxBuildLimit = flags.velaMaxBuildLimit
, velaMaxStarlarkExecLimit = flags.velaMaxStarlarkExecLimit
, velaScheduleAllowlist = Util.stringToAllowlist flags.velaScheduleAllowlist

-- BASE URL
Expand Down
1 change: 1 addition & 0 deletions src/elm/Shared/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type alias Model =
, velaRedirect : String
, velaLogBytesLimit : Int
, velaMaxBuildLimit : Int
, velaMaxStarlarkExecLimit : Int
, velaScheduleAllowlist : List ( String, String )

-- BASE URL
Expand Down
2 changes: 2 additions & 0 deletions src/static/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export type Flags = {
readonly velaLogBytesLimit: number;
/** @property velaMaxBuildLimit: number */
readonly velaMaxBuildLimit: number;
/** @property velaMaxStarlarkExecLimit: number */
readonly velaMaxStarlarkExecLimit: number;
/** @property velaScheduleAllowlist: string */
readonly velaScheduleAllowlist: string;
};
Expand Down
12 changes: 10 additions & 2 deletions src/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const feedbackURL: string =
const docsURL: string = 'https://go-vela.github.io/docs';
const defaultLogBytesLimit: number = 2000000; // 2mb
const maximumBuildLimit: number = 30;
const maximumStarlarkExecLimit: number = 99999;
const scheduleAllowlist: string = '*';

// setup for auth redirect
Expand Down Expand Up @@ -51,10 +52,17 @@ const flags: Flags = {
),
velaMaxBuildLimit: Number(
process.env.VELA_MAX_BUILD_LIMIT ||
envOrNull('VELA_MAX_BUILD_LIMIT', 'VELA_MAX_BUILD_LIMIT') ||
envOrNull('VELA_MAX_BUILD_LIMIT', '$VELA_MAX_BUILD_LIMIT') ||
maximumBuildLimit,
),

velaMaxStarlarkExecLimit: Number(
process.env.VELA_MAX_STARLARK_EXEC_LIMIT ||
envOrNull(
'VELA_MAX_STARLARK_EXEC_LIMIT',
'$VELA_MAX_STARLARK_EXEC_LIMIT',
) ||
maximumStarlarkExecLimit,
),
velaScheduleAllowlist:
(window.Cypress && window.Cypress.env('VELA_SCHEDULE_ALLOWLIST')) ||
process.env.VELA_SCHEDULE_ALLOWLIST ||
Expand Down

0 comments on commit 1459f61

Please sign in to comment.