Skip to content

Commit 60d2b08

Browse files
LMGchristian-schilling
authored andcommitted
Add Working with workspaces doc
- restructure doc folder - add workspaces .t
1 parent fd322c6 commit 60d2b08

File tree

9 files changed

+427
-13
lines changed

9 files changed

+427
-13
lines changed

docs/src/SUMMARY.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
- [Intro](./intro.md)
44
- [Use cases](./usecases.md)
55
# Guide
6-
- [Getting started](./gettingstarted.md)
7-
- [Working with workspaces]()
6+
- [Getting started](./guide/gettingstarted.md)
7+
- [Working with workspaces](./guide/workspaces.md)
88
- [Importing projects]()
99
- [Integrating with CI]()
1010
# Reference
11-
- [Filter syntax](./filters.md)
12-
- [Proxy](./proxy.md)
13-
- [Workspaces](./workspace.md)
14-
- [Command line tools](./cli.md)
11+
- [Filter syntax](./reference/filters.md)
12+
- [Proxy](./reference/proxy.md)
13+
- [Workspaces](./reference/workspace.md)
14+
- [Command line tools](./reference/cli.md)
1515
- [Graphql API]()
1616
- [Handlebar generator]()
1717
- [The josh UI]()

docs/src/gettingstarted.md renamed to docs/src/guide/gettingstarted.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ proxy to serve your own git repository.
66
---
77
***NOTE***
88

9-
All the commands in this book are included from the file `tutorial.t`
10-
which can be run with `cram tutorial.t`.
9+
All the commands are included from the file `gettingstarted.t`
10+
which can be run with [cram](https://bitheap.org/cram/).
1111

1212
---
1313

@@ -17,7 +17,7 @@ Josh is distributed via [docker hub](https://hub.docker.com/r/esrlabs/josh-proxy
1717
and is installed and started with the following command:
1818

1919
```shell
20-
{{#include tutorial.t:docker_github}}
20+
{{#include gettingstarted.t:docker_github}}
2121
```
2222

2323
This starts josh as a proxy to github.com, in a docker container,
@@ -29,13 +29,13 @@ Once josh is running, we can clone a repository through it.
2929
For example, let's clone josh:
3030

3131
```shell
32-
{{#include tutorial.t:clone_full}}
32+
{{#include gettingstarted.t:clone_full}}
3333
```
3434

3535
As we can see, this repository is simply the normal josh one:
3636

3737
```shell
38-
{{#include tutorial.t:ls_full}}
38+
{{#include gettingstarted.t:ls_full}}
3939
```
4040

4141
## Extracting a module
@@ -45,7 +45,7 @@ Let's check out the josh repository again, but this time let's filter
4545
only the documentation out:
4646

4747
```shell
48-
{{#include tutorial.t:clone_doc}}
48+
{{#include gettingstarted.t:clone_doc}}
4949
```
5050

5151
Note the addition of `:/docs` at the end of the url.
@@ -57,7 +57,7 @@ different. Indeed, it contains only the commits pertaining to the
5757
subfolder that we checked out.
5858

5959
```shell
60-
{{#include tutorial.t:ls_doc}}
60+
{{#include gettingstarted.t:ls_doc}}
6161
```
6262

6363
This repository is a real repository in which we can pull, commit, push,
File renamed without changes.

docs/src/guide/workspaces.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Working with workspaces
2+
3+
---
4+
***NOTE***
5+
6+
All the commands are included from the file `workspaces.t`
7+
which can be run with [cram](https://bitheap.org/cram/).
8+
9+
---
10+
11+
Josh really starts to shine when using workspaces.
12+
13+
Simply put, they are a list of files and folders, remapped from the central repository
14+
to a new repository.
15+
For example, a shared library could be used by various workspaces, each mapping it to
16+
their appropriate subdirectory.
17+
18+
In this chapter, we're going to set up a new git repository with a couple of libraries,
19+
and then use it to demonstrate the use of workspaces.
20+
21+
## Test set-up
22+
---
23+
***NOTE***
24+
25+
The following section describes how to set-up a local git server with made-up content
26+
for the sake of this tutorial.
27+
You're free to follow it, or to use your own existing repository, in which case you
28+
can skip to the next section
29+
30+
---
31+
32+
To host the repository for this test, we need a git server.
33+
We're going to run git as a [cgi](https://en.wikipedia.org/wiki/Common_Gateway_Interface)
34+
program using its provided http backend, served with the test server included in
35+
the [hyper\_cgi](https://crates.io/crates/hyper_cgi) crate.
36+
37+
### Serving the git repo
38+
First, we create a *bare* repository, which will be served by hyper\_cgi. We enable
39+
the option `http.receivepack` to allow the use of `git push` from the clients.
40+
41+
```shell
42+
{{#include workspaces.t:git_setup}}
43+
```
44+
45+
Then we start the server which will allow clients to access the repository through
46+
http.
47+
48+
```shell
49+
{{#include workspaces.t:git_server}}
50+
```
51+
52+
Our server is ready, serving all the repos in the `remote` folder on port `8001`.
53+
54+
```shell
55+
{{#include workspaces.t:clone}}
56+
```
57+
58+
### Adding some content
59+
Of course, the repository is for now empty, and we need to populate it.
60+
The following script creates a couple of libraries, as well as two applications that use
61+
them.
62+
63+
```shell
64+
{{#include workspaces.t:populate}}
65+
```
66+
67+
## Creating our first workspace
68+
Now that we have a git repo populated with content, let's serve it through josh:
69+
70+
```shell
71+
{{#include workspaces.t:docker_josh}}
72+
```
73+
74+
---
75+
**NOTE**
76+
77+
For the sake of this example, we run docker with --network="host" instead of publishing the port.
78+
This is so that docker can access localhost, where our ad-hoc git repository is served.
79+
80+
---
81+
82+
To facilitate developement on applications 1 and 2, we want to create workspaces for them.
83+
Creating a new workspace looks very similar to checking out a subfolder through josh, as explain
84+
in "Getting Started".
85+
86+
Instead of just the name of the subfolder, though, we also use the `:workspace=` filter:
87+
88+
```shell
89+
{{#include workspaces.t:clone_workspace}}
90+
```
91+
92+
Looking into the newly cloned workspace, we see our expected files and the history containing the
93+
only relevant commit.
94+
95+
---
96+
**NOTE**
97+
98+
Josh allows us to create a workspace out of any directory, even one that doesn't exist yet.
99+
100+
---
101+
102+
### Adding workspace.josh
103+
104+
The workspace.josh file describes how folders from the central repository (real\_repo.git)
105+
should be mapped to the workspace repository.
106+
107+
Let's create one with the relevant components.
108+
First, the library we depend on:
109+
110+
```shell
111+
{{#include workspaces.t:library}}
112+
```
113+
114+
We decided to map library1 to modules/lib1 in the workspace.
115+
After pushing and fetching the result, we se that it has been succesfully mapped by josh.
116+
117+
One suprising thing is the history: our "mapping" commit became a merge commit!
118+
This is because josh needs to merge the history of the module we want to map into the
119+
repository of the workspace.
120+
After this is done, all commit will be present in both of the histories.
121+
122+
---
123+
**NOTE**
124+
125+
`git sync` is a utility provided with josh which will push contents, and, if josh tells
126+
it to, fetch the transformed result. Otherwise, it works like git push.
127+
128+
---
129+
130+
By the way, what does the history look like on the real\_repo ?
131+
132+
```shell
133+
{{#include workspaces.t:real_repo}}
134+
```
135+
136+
We can see the newly added commit for workspace.josh in application1, and as expected,
137+
no merge here.

0 commit comments

Comments
 (0)