Skip to content

Commit 6ea42bd

Browse files
committed
Merge remote-tracking branch 'origin/feat/1757_actions_arbitrary_namespaces' into dev
2 parents bea569d + fa31d10 commit 6ea42bd

File tree

7 files changed

+39
-16
lines changed

7 files changed

+39
-16
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ GOOGLE_ARTIFACT_UPLOADER_KEY_FILE=anymal-grand-tour-3b7a5d0c8ef4.json
4141
# can be left empty if you don't want to use docker hub
4242
DOCKER_HUB_USERNAME=
4343
DOCKER_HUB_PASSWORD=
44+
VITE_DOCKER_HUB_NAMESPACE=
4445

4546
ARTIFACTS_UPLOADER_IMAGE=rslethz/grandtour-datasets:artifact-uploader-latest

backend/src/services/action.service.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,14 @@ export class ActionService {
100100
data: CreateTemplateDto,
101101
auth: AuthHeader,
102102
): Promise<ActionTemplateDto> {
103-
if (!data.dockerImage.startsWith('rslethz/')) {
103+
const dockerhub_namespace = process.env['VITE_DOCKER_HUB_NAMESPACE'];
104+
// assert that we only run images from a specified namespace
105+
if (
106+
dockerhub_namespace !== undefined &&
107+
!data.dockerImage.startsWith(dockerhub_namespace)
108+
) {
104109
throw new ConflictException(
105-
'Only images from the rslethz namespace are allowed',
110+
`Only images from the ${dockerhub_namespace} namespace are allowed`,
106111
);
107112
}
108113
const exists = await this.actionTemplateRepository.exists({
@@ -140,11 +145,11 @@ export class ActionService {
140145
data: UpdateTemplateDto,
141146
auth: AuthHeader,
142147
): Promise<ActionTemplateDto> {
143-
if (!data.dockerImage.startsWith('rslethz/')) {
144-
throw new ConflictException(
145-
'Only images from the rslethz namespace are allowed',
146-
);
147-
}
148+
//if (!data.dockerImage.startsWith('rslethz/')) {
149+
// throw new ConflictException(
150+
// 'Only images from the rslethz namespace are allowed',
151+
// );
152+
//}
148153
const template = await this.actionTemplateRepository.findOneOrFail({
149154
where: { uuid: data.uuid },
150155
});

common/environment.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,12 @@ export default {
190190
get VITE_USE_FAKE_OAUTH_FOR_DEVELOPMENT(): boolean {
191191
return asBoolean(process.env['VITE_USE_FAKE_OAUTH_FOR_DEVELOPMENT']);
192192
},
193+
194+
/**
195+
* @returns Docker Hub namespace for image validation (optional)
196+
* @example rslethz/
197+
*/
198+
get DOCKER_HUB_NAMESPACE(): string {
199+
return process.env['VITE_DOCKER_HUB_NAMESPACE'] ?? '';
200+
},
193201
};

docs/usage/actions/write-custom-actions.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,16 @@ The following environment variables are deprecated and will be removed in the fu
6969

7070
## Push Actions to Docker Hub
7171

72-
Kleinkram actions must be pushed to Docker Hub under the rslethz/\*\*\* namespace. To publish your action:
72+
Kleinkram actions must be pushed to Docker Hub under a namespace defined by the `VITE_DOCKER_HUB_NAMESPACE` environment variable.
73+
If this is left empty, actions are allowed to be pushed on any namespace. To publish your action:
7374

7475
```bash
7576
# login to docker hub
7677
docker login
7778

7879
# build the image
79-
docker build -t rslethz/my-action .
80+
docker build -t <namespace>/my-action .
8081

8182
# push the image
82-
docker push rslethz/my-action
83+
docker push <namespace>/my-action
8384
```

examples/actions/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM python:latest
22

33
# install kleinkram as CLI
4-
RUN pip install kleinkram --pre --force-reinstall
4+
RUN pip install kleinkram --pre --force-reinstall && pip install "httpx==0.26.0"
55

66
# copy entrypoint and make it executable
77
COPY ./entrypoint.sh /entrypoint.sh

frontend/src/components/action-configuration.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,14 @@ async function submitAnalysis() {
515515
});
516516
return;
517517
}
518-
if (!editingTemplate.value.imageName.startsWith('rslethz/')) {
518+
const dockerhubNamespace = import.meta.env.VITE_DOCKER_HUB_NAMESPACE;
519+
if (
520+
dockerhubNamespace &&
521+
!editingTemplate.value.imageName.startsWith(`${dockerhubNamespace}`)
522+
) {
519523
Notify.create({
520524
group: false,
521-
message: 'The image name must start with "rslethz/"',
525+
message: `The image name must start with "${dockerhubNamespace}/"`,
522526
color: 'negative',
523527
position: 'bottom',
524528
timeout: 2000,

queueConsumer/src/actions/services/docker-daemon.service.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,14 @@ export class DockerDaemon {
303303

304304
@tracing()
305305
private async getImage(dockerImage: string) {
306-
// assert that we only run rslethz images
307-
if (!dockerImage.startsWith('rslethz/')) {
306+
const dockerhub_namespace = process.env['VITE_DOCKER_HUB_NAMESPACE'];
307+
// assert that we only run images from a specified namespace
308+
if (
309+
dockerhub_namespace !== undefined &&
310+
!dockerImage.startsWith(dockerhub_namespace)
311+
) {
308312
throw new Error(
309-
'Only images from the rslethz organization are allowed',
313+
`Only images from the ${dockerhub_namespace} namespace are allowed`,
310314
);
311315
}
312316

0 commit comments

Comments
 (0)