Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit 44e41cd

Browse files
committed
reworked uid for linux, debugging and documentation enhancements
1 parent c61efe1 commit 44e41cd

12 files changed

+121
-47
lines changed

DEBUG.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Tips to help debugging
2+
3+
## Hidden flags
4+
5+
The `iosdk` has a number of hidden flags useful for development
6+
7+
Global flags
8+
9+
- `--use-default-api-key`: do not generate an api key use the default one
10+
- `--skip-docker-version`: do not check the docker version
11+
- `--skip-pull-images`: do not pull images
12+
- `--skip-open-browser`: no not open the browser
13+
- `--skip-ide`: do not start the ide
14+
15+
Hidden commands:
16+
17+
- `wskprops`: set the .wskprops to use `wsk` with the server
18+
- `ide-deploy`: deploy the ide
19+
- `ide-destroy`: destroy the ide
20+
- `whisk-deploy`: deploy whisk
21+
- `whisk-destroy`: destroy whisk
22+
- `redis-deploy`: deploy redis
23+
- `redis-destroy`: destroy redis
24+
25+
## Checking ide test results
26+
27+
You can run the test suite of the cli with
28+
29+
```
30+
cd iosdk
31+
make test
32+
```
33+
34+
If a test fails it may be difficult to understand what is wrong in the output.
35+
36+
The test command saves the test output in `difftest.out`
37+
38+
The `difftest.py` comes to the rescue, you pass the test output and returns a list of failed tests , with an index:
39+
40+
```
41+
$ python3 difftest.py difftest.out
42+
0 --- FAIL: ExampleIdeDockerRun (0.00s)
43+
1 --- FAIL: ExampleStart (1.03s)
44+
```
45+
46+
Then you can see what went wrong in a single test passing the index:
47+
48+
```
49+
$ python3 difftest.py difftest.out 1
50+
31c31
51+
< docker run -d -p 3000:3000 --rm --name iosdk-theia -e HOME=/home/project --add-host=openwhisk: 172.17.0.2 -v /tmp/iosdk-test/javascript:/home/project pagopa/iosdk-theia:test
52+
---
53+
> docker run -d -p 3000:3000 --rm --name iosdk-theia --add-host=openwhisk:172.17.0.2 -v /tmp/iosdk-test/javascript:/home/project pagopa/iosdk-theia:test
54+
```
55+
56+
## Debugging action tests
57+
58+
Bats tests are shell scripts.
59+
60+
The easiest way to debug them is to execute them line by line using VSCode.
61+
62+
First, configure a keybinding to execute a line in the terminal.
63+
64+
Open the `keybindings.json` as [described here](https://code.visualstudio.com/docs/getstarted/keybindings#_advanced-customization) and add this snippet:
65+
66+
```
67+
{
68+
"key": "ctrl+enter",
69+
"command": "workbench.action.terminal.runSelectedText",
70+
"when": "editorTextFocus"
71+
}
72+
```
73+
74+
Open a terminal, change to `admnin/actions` then do a `source debug-src`.
75+
76+
Open a test and send each line to the terminal with control-enter.
77+
78+
79+

DEVEL.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
# Using IO-SDK as a developer
77

8-
If you are one of those heroic people wanting to help and you can deal with bugs, crashes and the occasional complete destruction of you computer, you can follow with those instructions.
8+
If you are one of those heroic people wanting to help and you can deal with bugs, crashes and the occasional complete destruction of you computer, you can follow with those instructions.
9+
10+
After you read this document, do not forget to [check also this other document](DEBUG.md) for debugging tips.
911

1012
## Prerequisites
1113

12-
Supported development platforms are:
14+
Supported development platforms are:
1315
- Linux Ubuntu 18.x
14-
- Mac OS Catalina
16+
- Mac OS Catalina
1517
- Windows 10 build 2003 with WSL2 and Ubuntu 18.04
1618

1719
Also your workstation needs at least 8gb of memory.
@@ -42,7 +44,7 @@ Windows configuration is a bit more complex. The steps are:
4244
#### Update to build 2009
4345

4446
More informations [to update windows are here](https://support.microsoft.com/en-us/help/4027667/windows-10-update)
45-
47+
4648
#### Install Ubuntu-18.04 under WSL2
4749

4850
Go into the Microsof Store and seach for Ubuntu. Install version 18.04 and launch it.
@@ -59,7 +61,7 @@ Instructions to install Docker Desktop for Windows [are here](https://docs.docke
5961

6062
#### Use docker for windows as docker backend in WSL 2
6163

62-
This step is critical.
64+
This step is critical.
6365

6466
After installation follow [these instructions](https://docs.docker.com/docker-for-windows/wsl/) to use the Docker running in Windows as the Docker to use in WSL.
6567

@@ -122,7 +124,7 @@ DO `make build` from the top level to embed the code you modified in the image.
122124
123125
## Backend Actions
124126
125-
The server side part of the backend are [OpenWhisk](http://openwhisk.apache.org), action written in various languages.
127+
The server side part of the backend are [OpenWhisk](http://openwhisk.apache.org), action written in various languages.
126128
127129
Source code is under `admin/actions/src`
128130
@@ -134,11 +136,11 @@ You can deploy actions after changes with `make deploy`
134136
135137
The CLI, that is used to launch and initialize the environment is under `iosdk` and it is written in the Go programming language.
136138
137-
To develop the cli, do `cd iosdk` and use `make`.
139+
To develop the cli, do `cd iosdk` and use `make`.
138140
139-
The cli embeds the version number of the images to refer to them correctly.
141+
The cli embeds the version number of the images to refer to them correctly.
140142
141-
In development, the version is just the branch name.
143+
In development, the version is just the branch name.
142144
143145
When you push to master, the CI builds images and pushes to the Docker Hub, so the CLI can retrieve the version stored in Docker Hub.
144146

admin/actions/DEBUG.md

-24
This file was deleted.

ide/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM pagopa/theia:2020.06.08
22
ADD ide-plugin /home/theia/plugins/ide-plugin
33
RUN sudo find /home/theia -uid 0 -exec chown theia:theia {} \;
4+
RUN echo 'export PS1="\w\$ "' | sudo tee -a /etc/bash.bashrc
45
#RUN cd /home/theia/plugins/ide-plugin && npm install && npm run build

iosdk/config.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ func PropagateConfig() {
170170

171171
fmt.Println("Configuring Whisk")
172172
WhiskUpdatePackageParameters("iosdk", ConfigMap())
173-
fmt.Println("Configuring IDE")
174-
configureIde()
173+
if !*skipIde {
174+
fmt.Println("Configuring IDE")
175+
configureIde()
176+
}
175177
}

iosdk/const.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package main
22

3+
import "runtime"
4+
35
// ConfigFile is the config file, change number if you need the project to be re-initialized
46
const ConfigFile = "~/.iosdk.v2"
57

@@ -35,3 +37,6 @@ const DefaultWhiskAPIKey = "23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v
3537

3638
// MinDockerMem is the minimum amount of memory required by docker
3739
const MinDockerMem = (4 * 1000 * 1000 * 1000) - 1
40+
41+
// RuntimeOS to be changed for tests
42+
var RuntimeOS = runtime.GOOS

iosdk/ide.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os/user"
66
"path/filepath"
7-
"runtime"
87
)
98

109
// IdeDeploy deploys and mounts a folder
@@ -48,7 +47,7 @@ func ideDockerRun(dir string) (err error) {
4847
}
4948

5049
uid := ""
51-
if runtime.GOOS == "linux" {
50+
if RuntimeOS == "linux" {
5251
usr, err := user.Current()
5352
LogIf(err)
5453
if err == nil {
@@ -57,8 +56,8 @@ func ideDockerRun(dir string) (err error) {
5756
}
5857

5958
command := fmt.Sprintf(`docker run -d -p 3000:3000
60-
--rm --name iosdk-theia -e HOME=/home/project -e USER=iosdk %s
61-
--add-host=openwhisk:%s %s %s`, uid, *openwhiskIP, mount, image)
59+
--rm --name iosdk-theia -e HOME=/home/project
60+
%s %s --add-host=openwhisk:%s %s`, mount, uid, *openwhiskIP, image)
6261
Sys(command)
6362
return nil
6463
}

iosdk/ide_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@ func ExampleIdeDockerRun() {
99
DryRunPush("", "172.17.0.2", "641792b3e0112c8fa1896b8944a846dbbab88fe5729f3d464e71475afd9e6057",
1010
"", "Error:",
1111
"", "172.17.0.2")
12+
RuntimeOS = "darwin"
1213
fmt.Println(1, ideDockerRun("/tmp"))
1314
fmt.Println(2, ideDockerRun("/tmp"))
1415
fmt.Println(3, ideDockerRun(""))
1516
// Output:
1617
// docker pull pagopa/iosdk-theia:test
1718
// docker inspect --format={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} iosdk-openwhisk
18-
// docker run -d -p 3000:3000 --rm --name iosdk-theia --add-host=openwhisk:172.17.0.2 -v /tmp:/home/project pagopa/iosdk-theia:test
19+
// docker run -d -p 3000:3000 --rm --name iosdk-theia -e HOME=/home/project -v /tmp:/home/project --add-host=openwhisk:172.17.0.2 pagopa/iosdk-theia:test
1920
// 1 <nil>
2021
// docker pull pagopa/iosdk-theia:test
2122
// docker inspect --format={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} iosdk-openwhisk
2223
// 2 cannot find openwhisk
2324
// docker pull pagopa/iosdk-theia:test
2425
// docker inspect --format={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} iosdk-openwhisk
25-
// docker run -d -p 3000:3000 --rm --name iosdk-theia --add-host=openwhisk:172.17.0.2 pagopa/iosdk-theia:test
26+
// docker run -d -p 3000:3000 --rm --name iosdk-theia -e HOME=/home/project --add-host=openwhisk:172.17.0.2 pagopa/iosdk-theia:test
2627
// 3 <nil>
2728
}
2829

iosdk/main.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var (
2323
skipDockerVersion = kingpin.Flag("skip-docker-version", "Skip check of docker version").Hidden().Default("false").Bool()
2424
skipPullImages = kingpin.Flag("skip-pull-images", "skip pull images").Hidden().Default("false").Bool()
2525
skipOpenBrowser = kingpin.Flag("skip-open-browser", "skip pull images").Hidden().Default("false").Bool()
26+
skipIde = kingpin.Flag("skip-ide", "skip starting ide").Hidden().Default("false").Bool()
2627

2728
// hidden debug commands
2829
debugCmd = kingpin.Command("debug", "debug").Hidden()
@@ -48,6 +49,8 @@ var (
4849

4950
// stop
5051
stopCmd = kingpin.Command("stop", "Stop Development Environment")
52+
// restart
53+
restartCmd = kingpin.Command("restart", "Restart Development Environment")
5154
// status
5255
statusCmd = kingpin.Command("status", "Check Containers Status")
5356
)
@@ -58,11 +61,15 @@ func parseDebug(cmd string) bool {
5861
ConfigLoad()
5962
WskPropsSave()
6063
case ideDeployCmd.FullCommand():
61-
IdeDeploy("")
64+
FatalIf(ConfigLoad())
65+
IdeDeploy(Config.AppDir)
66+
configureIde()
6267
case ideDestroyCmd.FullCommand():
6368
IdeDestroy()
6469
case whiskDeployCmd.FullCommand():
70+
FatalIf(ConfigLoad())
6571
WhiskDeploy()
72+
WhiskUpdatePackageParameters("iosdk", ConfigMap())
6673
case whiskDestroyCmd.FullCommand():
6774
WhiskDestroy()
6875
case redisDeployCmd.FullCommand():

iosdk/start.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ func Start() error {
2424
if err != nil {
2525
return err
2626
}
27-
err = IdeDeploy(Config.AppDir)
28-
if err != nil {
29-
return err
27+
if !*skipIde {
28+
err = IdeDeploy(Config.AppDir)
29+
if err != nil {
30+
return err
31+
}
3032
}
3133
return nil
3234
}

iosdk/start_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func ExampleStart() {
4848
// Deploying IDE...
4949
// docker pull pagopa/iosdk-theia:test
5050
// docker inspect --format={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} iosdk-openwhisk
51-
// docker run -d -p 3000:3000 --rm --name iosdk-theia --add-host=openwhisk:172.17.0.2 -v /tmp/iosdk-test/javascript:/home/project pagopa/iosdk-theia:test
51+
// docker run -d -p 3000:3000 --rm --name iosdk-theia -e HOME=/home/project -v /tmp/iosdk-test/javascript:/home/project --add-host=openwhisk:172.17.0.2 pagopa/iosdk-theia:test
5252
// <nil>
5353
}
5454

test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ iosdk/iosdk init $HOME/tmp-iosdk-test pagopa/io-sdk-javascript --io-apikey=12345
99
echo "****** START"
1010
iosdk/iosdk -v start --skip-pull-images --skip-docker-version --skip-open-browser
1111
echo "****** BUILD"
12-
docker exec --user=$UID iosdk-theia bash -c 'cp /home/theia/.wskprops /home/project/.wskprops ; env HOME=/home/project bash /home/project/build.sh'
12+
docker exec --user=$UID iosdk-theia bash -c 'bash /home/project/build.sh'
1313
echo "****** STATUS"
1414
iosdk/iosdk status
1515
CHECK=ISPXNB32R82Y766F

0 commit comments

Comments
 (0)