Skip to content

Commit 2af3424

Browse files
sgaistleafty
andauthored
feat: add feature flag for private repo builds (#4234)
* feat: add support for private repo build feature flag The feature flag allows admins to enable independently the builds feature and the support for building images from private repositories. The code repository selector has been updated to disable private repository selection with a proper message. This makes the workflow consistent for the user. * chore: fix equality tests Co-authored-by: Flora Thiebaut <flora@leafty.dev> * chore: update error message "Cannot clone repository" is more accurate than "No public access" as it applies whether private repo build support is enabled or not. Co-authored-by: Flora Thiebaut <flora@leafty.dev> --------- Co-authored-by: Flora Thiebaut <flora@leafty.dev>
1 parent 31c6a25 commit 2af3424

9 files changed

Lines changed: 60 additions & 14 deletions

File tree

client/run-telepresence.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ tee > ./public/config.json << EOF
201201
"USER_PREFERENCES_MAX_PINNED_PROJECTS": ${USER_PREFERENCES_MAX_PINNED_PROJECTS:-5},
202202
"SESSION_CLASS_EMAIL_US": { "enabled": false },
203203
"IMAGE_BUILDERS_ENABLED": true,
204+
"BUILD_PRIVATE_REPO_BUILDS_ENABLED": true,
204205
"CONTACT_EMAIL": "hello@renku.io"
205206
}
206207
EOF

client/server/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export const CONFIG_JSON = {
8383
process.env.USER_PREFERENCES_MAX_PINNED_PROJECTS,
8484
SESSION_CLASS_EMAIL_US: safeJsonToObject(process.env.SESSION_CLASS_EMAIL_US),
8585
IMAGE_BUILDERS_ENABLED: process.env.IMAGE_BUILDERS_ENABLED,
86+
BUILD_PRIVATE_REPO_BUILDS_ENABLED:
87+
process.env.BUILD_PRIVATE_REPO_BUILDS_ENABLED,
8688
CONTACT_EMAIL: process.env.CONTACT_EMAIL || "hello@renku.io",
8789
};
8890

client/src/features/sessionsV2/components/SessionForm/CodeRepositorySelector.tsx

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
import cx from "classnames";
20-
import { useCallback, useEffect, useMemo } from "react";
20+
import { useCallback, useContext, useEffect, useMemo } from "react";
2121
import { ChevronDown, XLg } from "react-bootstrap-icons";
2222
import {
2323
Controller,
@@ -38,6 +38,8 @@ import Select, {
3838
import { Label } from "reactstrap";
3939

4040
import { GetRepositoriesApiResponse } from "~/features/repositories/api/repositories.api";
41+
import AppContext from "../../../../utils/context/appContext";
42+
import { DEFAULT_APP_PARAMS } from "../../../../utils/context/appParams.constants";
4143
import { getRepositoryName } from "../../../ProjectPageV2/ProjectPageContent/CodeRepositories/repositories.utils";
4244

4345
import styles from "./Select.module.scss";
@@ -129,6 +131,11 @@ function CodeRepositorySelect({
129131
value: value_,
130132
disabled,
131133
}: CodeRepositorySelectProps) {
134+
const { params } = useContext(AppContext);
135+
const privateRepoBuildEnabled =
136+
params?.BUILD_PRIVATE_REPO_BUILDS_ENABLED ??
137+
DEFAULT_APP_PARAMS.BUILD_PRIVATE_REPO_BUILDS_ENABLED;
138+
132139
const defaultValue = useMemo(
133140
() => options.find((repository) => repository.url === defaultValue_),
134141
[defaultValue_, options],
@@ -165,7 +172,9 @@ function CodeRepositorySelect({
165172
unstyled
166173
isOptionDisabled={(option) =>
167174
option.data?.status !== "valid" ||
168-
!option.data.metadata?.pull_permission
175+
!option.data.metadata?.pull_permission ||
176+
(option.data.metadata.visibility === "private" &&
177+
!privateRepoBuildEnabled)
169178
}
170179
onChange={onChange}
171180
onBlur={onBlur}
@@ -207,6 +216,11 @@ interface OptionValueContentProps {
207216

208217
function OptionValueContent({ option, isDisabled }: OptionValueContentProps) {
209218
const title = getRepositoryName(option.url);
219+
const { params } = useContext(AppContext);
220+
const privateRepoBuildEnabled =
221+
params?.BUILD_PRIVATE_REPO_BUILDS_ENABLED ??
222+
DEFAULT_APP_PARAMS.BUILD_PRIVATE_REPO_BUILDS_ENABLED;
223+
210224
return (
211225
<>
212226
<div>
@@ -218,12 +232,19 @@ function OptionValueContent({ option, isDisabled }: OptionValueContentProps) {
218232
>
219233
{title}
220234
</span>
221-
{isDisabled && (
222-
<span className="ms-1">
223-
<XLg className={cx("bi", "me-1")} />
224-
No public access
225-
</span>
226-
)}
235+
{isDisabled &&
236+
(option.data?.metadata?.visibility === "private" &&
237+
!privateRepoBuildEnabled ? (
238+
<span className="ms-1">
239+
<XLg className={cx("bi", "me-1")} />
240+
Private repository builds are not available
241+
</span>
242+
) : (
243+
<span className="ms-1">
244+
<XLg className={cx("bi", "me-1")} />
245+
Cannot clone repository
246+
</span>
247+
))}
227248
</div>
228249
<div>{option.url}</div>
229250
</>
@@ -236,17 +257,29 @@ interface SingleValueContentProps {
236257
}
237258

238259
function SingleValueContent({ option, isDisabled }: SingleValueContentProps) {
260+
const { params } = useContext(AppContext);
261+
const privateRepoBuildEnabled =
262+
params?.BUILD_PRIVATE_REPO_BUILDS_ENABLED ??
263+
DEFAULT_APP_PARAMS.BUILD_PRIVATE_REPO_BUILDS_ENABLED;
264+
239265
return (
240266
<>
241267
<span className={cx(isDisabled && "text-decoration-line-through")}>
242268
{option.url}
243269
</span>
244-
{isDisabled && (
245-
<span className="ms-1">
246-
<XLg className={cx("bi", "me-1")} />
247-
No public access
248-
</span>
249-
)}
270+
{isDisabled &&
271+
(option.data?.metadata?.visibility == "private" &&
272+
!privateRepoBuildEnabled ? (
273+
<span className="ms-1">
274+
<XLg className={cx("bi", "me-1")} />
275+
Private repository builds are not available
276+
</span>
277+
) : (
278+
<span className="ms-1">
279+
<XLg className={cx("bi", "me-1")} />
280+
Cannot clone repository
281+
</span>
282+
))}
250283
</>
251284
);
252285
}

client/src/utils/context/appParams.constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,6 @@ export const DEFAULT_APP_PARAMS: AppParams = {
8181
USER_PREFERENCES_MAX_PINNED_PROJECTS:
8282
DEFAULT_USER_PREFERENCES_MAX_PINNED_PROJECTS,
8383
IMAGE_BUILDERS_ENABLED: false,
84+
BUILD_PRIVATE_REPO_BUILDS_ENABLED: false,
8485
CONTACT_EMAIL: "hello@renku.io",
8586
};

client/src/utils/context/appParams.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface AppParams {
2424
GATEWAY_URL: string;
2525
HOMEPAGE: HomepageParams;
2626
IMAGE_BUILDERS_ENABLED: boolean;
27+
BUILD_PRIVATE_REPO_BUILDS_ENABLED: boolean;
2728
KEYCLOAK_REALM: string;
2829
MAINTENANCE: string;
2930
PREVIEW_THRESHOLD: PreviewThresholdParams;

client/src/utils/context/appParams.utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export function validatedAppParams(params: unknown): AppParams {
6969
params_,
7070
"IMAGE_BUILDERS_ENABLED",
7171
);
72+
const BUILD_PRIVATE_REPO_BUILDS_ENABLED = validateBoolean(
73+
params_,
74+
"BUILD_PRIVATE_REPO_BUILDS_ENABLED",
75+
);
7276

7377
// Integer params
7478
const USER_PREFERENCES_MAX_PINNED_PROJECTS = validateInteger(
@@ -91,6 +95,7 @@ export function validatedAppParams(params: unknown): AppParams {
9195
GATEWAY_URL,
9296
HOMEPAGE,
9397
IMAGE_BUILDERS_ENABLED,
98+
BUILD_PRIVATE_REPO_BUILDS_ENABLED,
9499
KEYCLOAK_REALM,
95100
MAINTENANCE,
96101
PREVIEW_THRESHOLD,

tests/cypress/fixtures/config-no-legacy.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
},
7070
"USER_PREFERENCES_MAX_PINNED_PROJECTS": 5,
7171
"IMAGE_BUILDERS_ENABLED": true,
72+
"BUILD_PRIVATE_REPO_BUILDS_ENABLED": true,
7273
"LEGACY_SUPPORT": {
7374
"enabled": false
7475
},

tests/cypress/fixtures/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,6 @@
6969
},
7070
"USER_PREFERENCES_MAX_PINNED_PROJECTS": 5,
7171
"IMAGE_BUILDERS_ENABLED": true,
72+
"BUILD_PRIVATE_REPO_BUILDS_ENABLED": true,
7273
"CONTACT_EMAIL": "hello@renku.io"
7374
}

tests/cypress/fixtures/config_privacy_banner.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,6 @@
6969
},
7070
"USER_PREFERENCES_MAX_PINNED_PROJECTS": 5,
7171
"IMAGE_BUILDERS_ENABLED": true,
72+
"BUILD_PRIVATE_REPO_BUILDS_ENABLED": true,
7273
"CONTACT_EMAIL": "hello@renku.io"
7374
}

0 commit comments

Comments
 (0)