Skip to content

Commit 59a8a6c

Browse files
authored
Merge pull request #77 from mikesir87/75-update-extension-compose-flows
Update DD extension to use published Compose flows
2 parents 7c3a82e + 63faa4d commit 59a8a6c

File tree

9 files changed

+100
-103
lines changed

9 files changed

+100
-103
lines changed

components/launcher/Dockerfile

Lines changed: 0 additions & 3 deletions
This file was deleted.

components/launcher/README.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

components/launcher/launch-labspace.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

dd-extension/README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,49 @@
1+
# Docker Desktop extension
2+
3+
This directory contains the code for the Docker Desktop extension for Labspaces.
4+
5+
## Development
6+
7+
To develop the extension, run the following steps:
8+
9+
1. Install the NPM dependencies:
10+
11+
```console
12+
npm install
13+
```
14+
15+
2. Start the app:
16+
17+
```console
18+
npm run dev
19+
```
20+
21+
3. If you don't have the extension installed yet, install it:
22+
23+
```console
24+
docker extension install dockersamples/labspace-extension
25+
```
26+
27+
4. Enable debug mode for the extension (to get the Chrome developer tools):
28+
29+
```console
30+
docker extension dev debug dockersamples/labspace-extension
31+
```
32+
33+
5. Set the UI source for the extension to be your development environment:
34+
35+
```console
36+
docker extension dev ui-source dockersamples/labspace-extension http://localhost:5173
37+
```
38+
39+
6. Open the extension in Docker Desktop. It will now be using the Vite reload server for the UI, allowing you to make changes and see them reflected immediately.
40+
141
## Deep link support
242

343
Once the extension is installed, deep links can be used to launch a Labspace.
444

545
```
6-
http://open.docker.com/dashboard/extension-tab?extensionId=dockersamples/labspace-extension&repo=REPO_URL&title=TITLE
46+
http://open.docker.com/dashboard/extension-tab?extensionId=dockersamples/labspace-extension&url=PUBLISHED_LABSPACE_URL&title=TITLE
747
```
848
9-
[Click here](http://open.docker.com/dashboard/extension-tab?extensionId=dockersamples/labspace-extension&repo=https://github.com/mikesir87/labspace-docker-overview&title=Demo) to launch a sample Labspace
49+
[Click here](http://open.docker.com/dashboard/extension-tab?extensionId=dockersamples/labspace-extension&url=dockersamples/labspace-container-supported-development&title=Demo) to launch a sample Labspace

dd-extension/src/DockerContext.jsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const HIGHLIGHTED_LABSPACES = [
1313
title: "Container-supported development",
1414
description:
1515
"Use containers to easily run and version databases, debug tools, and more across your entire team with minimal setup.",
16-
repo: "http://github.com/mikesir87/labspace-container-supported-development",
16+
location: "dockersamples/labspace-container-supported-development",
1717
},
1818
];
1919

@@ -22,7 +22,7 @@ const DockerContext = createContext();
2222
export function DockerContextProvider({ children }) {
2323
const [hasLabspace, setHasLabspace] = useState(false);
2424
const [runningLabspace, setRunningLabspace] = useState(null);
25-
const [startingLabspace, setStartingLabspace] = useState(false);
25+
const [startingLabspace, setStartingLabspace] = useState(null);
2626
const [stoppingLabspace, setStoppingLabspace] = useState(false);
2727
const [launchLog, setLaunchLog] = useState("");
2828
const [forceRefreshCount, setForceRefreshCount] = useState(0);
@@ -79,18 +79,21 @@ export function DockerContextProvider({ children }) {
7979
}, [setHasLabspace, setStoppingLabspace]);
8080

8181
const startLabspace = useCallback(
82-
(repoUrl) => {
82+
(location) => {
83+
console.log(`Starting Labspace with location ${location}`);
8384
setLaunchLog("");
84-
setStartingLabspace(true);
85+
setStartingLabspace(location);
8586

8687
ddClient.docker.cli.exec(
87-
"run",
88+
"compose",
8889
[
89-
"--rm",
90-
"-e",
91-
`LABSPACE_CONTENT_REPO=${repoUrl}`,
92-
"--use-api-socket",
93-
"dockersamples/labspace-launcher",
90+
"-f",
91+
`oci://${location}`,
92+
"-p",
93+
"labspace",
94+
"up",
95+
"-d",
96+
"-y",
9497
],
9598
{
9699
stream: {
@@ -100,7 +103,7 @@ export function DockerContextProvider({ children }) {
100103
},
101104
onClose(exitCode) {
102105
setHasLabspace(true);
103-
setStartingLabspace(false);
106+
setStartingLabspace(null);
104107
setForceRefreshCount((c) => c + 1);
105108
},
106109
},
@@ -111,16 +114,16 @@ export function DockerContextProvider({ children }) {
111114
);
112115

113116
const addLabspace = useCallback(
114-
(title, repo) => {
115-
const newLabspace = { title, repo };
117+
(title, location) => {
118+
const newLabspace = { title, location };
116119
setAdditionalLabspaces((labspaces) => [...labspaces, newLabspace]);
117120
},
118121
[setAdditionalLabspaces],
119122
);
120123

121124
const removeLabspace = useCallback(
122-
(repo) => {
123-
setAdditionalLabspaces((labs) => labs.filter((l) => l.repo !== repo));
125+
(location) => {
126+
setAdditionalLabspaces((labs) => labs.filter((l) => l.location !== location));
124127
},
125128
[setAdditionalLabspaces],
126129
);

dd-extension/src/Home.jsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function Home() {
5656
<Col xs={12} sm={6} md={4} key={labspace.title} className="mb-4">
5757
<LabspaceCard
5858
labspace={labspace}
59-
onLaunch={() => startLabspace(labspace.repo)}
59+
onLaunch={() => startLabspace(labspace.location)}
6060
starting={startingLabspace}
6161
running={hasLabspace}
6262
/>
@@ -83,7 +83,7 @@ export function Home() {
8383
<thead>
8484
<tr>
8585
<th>Title</th>
86-
<th>Repo</th>
86+
<th>Location</th>
8787
<th></th>
8888
</tr>
8989
</thead>
@@ -102,25 +102,19 @@ export function Home() {
102102
<tr key={labspace.title}>
103103
<td className="align-middle">{labspace.title}</td>
104104
<td className="align-middle">
105-
<a
106-
href={labspace.repo}
107-
target="_blank"
108-
rel="noopener noreferrer"
109-
>
110-
{labspace.repo}
111-
</a>
105+
{labspace.location}
112106
</td>
113107
<td className="text-end">
114108
<Button
115109
variant="primary"
116-
onClick={() => startLabspace(labspace.repo)}
110+
onClick={() => startLabspace(labspace.location)}
117111
className="me-2"
118112
>
119113
Launch
120114
</Button>
121115
<Button
122116
variant="danger"
123-
onClick={() => removeLabspace(labspace.repo)}
117+
onClick={() => removeLabspace(labspace.location)}
124118
>
125119
Remove
126120
</Button>
@@ -143,10 +137,10 @@ export function Home() {
143137
/>
144138

145139
<UrlHandlingModal
146-
onLaunchConfirmation={(title, repo) => {
147-
if (labspaces.find((l) => l.repo === repo) === undefined)
148-
addLabspace(title, repo);
149-
startLabspace(repo);
140+
onLaunchConfirmation={(title, location) => {
141+
if (labspaces.find((l) => l.location === location) === undefined)
142+
addLabspace(title, location);
143+
startLabspace(location);
150144
}}
151145
/>
152146
</Container>

dd-extension/src/components/AddLabspaceModal.jsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import { useState } from "react";
2-
import { Modal, Button, Form } from "react-bootstrap";
2+
import Modal from "react-bootstrap/Modal";
3+
import Button from "react-bootstrap/Button";
4+
import InputGroup from "react-bootstrap/InputGroup";
5+
import Form from "react-bootstrap/Form";
36

47
export function AddLabspaceModal({ show, onAdd, onCancel }) {
58
const [title, setTitle] = useState("");
6-
const [repo, setRepo] = useState("");
9+
const [location, setLocation] = useState("");
710

811
function handleSubmit(e) {
912
e.preventDefault();
10-
onAdd(title, repo);
13+
onAdd(title, location);
1114
setTitle("");
12-
setRepo("");
15+
setLocation("");
1316
}
1417

1518
function handleCancel() {
1619
setTitle("");
17-
setRepo("");
20+
setLocation("");
1821
onCancel();
1922
}
2023

@@ -36,14 +39,20 @@ export function AddLabspaceModal({ show, onAdd, onCancel }) {
3639
/>
3740
</Form.Group>
3841

39-
<Form.Group className="mb-3" controlId="labspaceRepo">
40-
<Form.Label>Repo</Form.Label>
41-
<Form.Control
42-
type="text"
43-
value={repo}
44-
onChange={(e) => setRepo(e.target.value)}
45-
required
46-
/>
42+
<Form.Group className="mb-3" controlId="labspaceComposeFile">
43+
<Form.Label>Labspace location</Form.Label>
44+
<InputGroup>
45+
<InputGroup.Text>oci://</InputGroup.Text>
46+
<Form.Control
47+
type="text"
48+
value={location}
49+
onChange={(e) => setLocation(e.target.value)}
50+
required
51+
/>
52+
</InputGroup>
53+
<Form.Text muted>
54+
Location of the published Compose file for the Labspace
55+
</Form.Text>
4756
</Form.Group>
4857
</Modal.Body>
4958
<Modal.Footer>

dd-extension/src/components/UrlHandlingModal.jsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@ import { useState } from "react";
55
export function UrlHandlingModal({ onLaunchConfirmation }) {
66
const searchParams = new URLSearchParams(window.location.search);
77
const title = searchParams.get("title");
8-
const repo = searchParams.get("repo");
8+
const location = searchParams.get("location");
99

10-
const [show, setShow] = useState(title && repo);
10+
const [show, setShow] = useState(title && location);
1111

1212
const handleConfirm = () => {
1313
setShow(false);
1414

1515
searchParams.delete("title");
16-
searchParams.delete("repo");
16+
searchParams.delete("location");
1717
window.history.replaceState(
1818
{},
1919
"",
2020
`${window.location.pathname}?${searchParams.toString()}`,
2121
);
2222

23-
onLaunchConfirmation(title, repo);
23+
onLaunchConfirmation(title, location);
2424
};
2525

2626
const handleCancel = () => {
2727
setShow(false);
2828

2929
searchParams.delete("title");
30-
searchParams.delete("repo");
30+
searchParams.delete("location");
3131
window.history.replaceState(
3232
{},
3333
"",
@@ -36,21 +36,21 @@ export function UrlHandlingModal({ onLaunchConfirmation }) {
3636
};
3737

3838
return (
39-
<Modal show={show} onHide={handleCancel} centered>
39+
<Modal show={show} onHide={handleCancel} centered size="lg">
4040
<Modal.Header closeButton>
4141
<Modal.Title className="mb-0">Confirm Labspace Launch</Modal.Title>
4242
</Modal.Header>
4343
<Modal.Body>
44-
<p>You are about to launch a Labspace with the following details:</p>
44+
<p>You have clicked a link to launch the following Labspace:</p>
4545
<ul>
4646
<li>
4747
<strong>Title:</strong> {title}
4848
</li>
4949
<li>
50-
<strong>Repo:</strong> {repo}
50+
<strong>Location:</strong> {location}
5151
</li>
5252
</ul>
53-
<p>Please verify these details before continuing.</p>
53+
<p>Please confirm the details and validate it's a trusted source.</p>
5454
</Modal.Body>
5555
<Modal.Footer>
5656
<Button variant="secondary" onClick={handleCancel}>

docker-bake.hcl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ group "default" {
1919
"support-vscode-extension",
2020
"interface",
2121
"labspace-cleaner",
22-
"launcher",
2322
"dd-extension",
2423
"workspace-base",
2524
"workspace-node",
@@ -108,12 +107,6 @@ target "labspace-cleaner" {
108107
tags = tags(IMAGE_NAMESPACE, "labspace-cleaner", IMAGE_TAG)
109108
}
110109

111-
target "launcher" {
112-
inherits = ["_common"]
113-
context = "./components/launcher"
114-
tags = tags(IMAGE_NAMESPACE, "labspace-launcher", IMAGE_TAG)
115-
}
116-
117110
target "dd-extension" {
118111
inherits = ["_common"]
119112
context = "./dd-extension"

0 commit comments

Comments
 (0)