Skip to content

Commit a602e83

Browse files
Clear env command (#270)
A command to clear the environment and working directory
1 parent cd57da7 commit a602e83

50 files changed

Lines changed: 5785 additions & 190 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ coverage.html
1212
coverage.out
1313

1414
# Ignore git repos checkout out by examples
15-
examples/*/.git
15+
examples/awesome-aks
16+
17+
# ignore initialization files
18+
.openai

.vscode/launch.json

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,66 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"name": "Launch file",
8+
"name": "Debug IE",
99
"type": "go",
1010
"request": "launch",
1111
"mode": "debug",
12-
"cwd": "${workspaceFolder}",
13-
"program": "${workspaceFolder}/cmd/ie/ie.go",
12+
"program": "${workspaceRoot}/cmd/ie/ie.go",
13+
"cwd": "${workspaceRoot}",
14+
// Test scenarios
15+
//"args": ["test", "${workspaceRoot}/docs/helloWorldDemo.md"],
16+
//"args": ["test", "${workspaceRoot}/docs/prerequisitesAndIncludes.md"],
17+
"args": [
18+
"test",
19+
"${workspaceRoot}/docs/environmentVariables.md"
20+
],
21+
//"args": ["test", "${workspaceRoot}/docs/prerequisitesAndIncludes.md"],
22+
"showLog": true,
23+
"console": "integratedTerminal"
24+
},
25+
{
26+
"name": "Debug EG Ask command",
27+
"type": "go",
28+
"request": "launch",
29+
"mode": "debug",
30+
"program": "${workspaceRoot}/examples/eg/main.go",
31+
"cwd": "${workspaceRoot}/examples/eg",
32+
"args": [
33+
"write",
34+
"Deploy a basic AKS cluster for testing purposes. This should focus on low cost as it is not intended for production."
35+
],
36+
"showLog": true,
1437
"console": "integratedTerminal",
38+
"envFile": "${workspaceRoot}/examples/eg/.openai"
39+
},
40+
{
41+
"name": "Debug EG Exec Doc",
42+
"type": "go",
43+
"request": "launch",
44+
"mode": "debug",
45+
"program": "${workspaceRoot}/cmd/ie/ie.go",
46+
"cwd": "${workspaceRoot}/examples/eg",
1547
"args": [
16-
"interactive",
17-
"--working-directory",
18-
"${workspaceFolder}",
19-
"${workspaceFolder}/${input:file}"
20-
]
48+
"execute",
49+
"${workspaceRoot}/examples/eg/README.md"
50+
],
51+
"showLog": true,
52+
"console": "integratedTerminal"
2153
},
22-
],
23-
"inputs": [
2454
{
25-
"id": "file",
26-
"type": "promptString",
27-
"description": "Enter the path to the file to process",
28-
"default": "tutorial.md"
29-
}
55+
"name": "Debug WIP Document",
56+
"type": "go",
57+
"request": "launch",
58+
"mode": "debug",
59+
"program": "${workspaceRoot}/cmd/ie/ie.go",
60+
"cwd": "${workspaceRoot}",
61+
"args": [
62+
"test",
63+
"${workspaceRoot}/examples/AZD/aks-store-demo/aks-store-demo.md"
64+
],
65+
//"args": ["test", "${workspaceRoot}/examples/AKS-Automatic/quick-kubernetes-automatic-deploy.md"],
66+
"showLog": true,
67+
"console": "integratedTerminal"
68+
},
3069
]
3170
}

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM golang:1.20-alpine
2+
3+
RUN apk update
4+
RUN apk add --no-cache --update \
5+
bash \
6+
cargo \
7+
git \
8+
gcc \
9+
libffi-dev \
10+
make \
11+
musl-dev \
12+
openssl-dev \
13+
python3 \
14+
py3-pip \
15+
python3-dev
16+
17+
WORKDIR /InnovationEngine
18+
19+
# Create a virtual environment and install the experimental Authoring Tools and az cli
20+
RUN python3 -m venv /InnovationEngine/venv
21+
RUN /InnovationEngine/venv/bin/pip install openai azure-identity requests pygithub
22+
RUN /InnovationEngine/venv/bin/pip install azure-cli
23+
24+
ENV VIRTUAL_ENV=/InnovationEngine/venv
25+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
26+
27+
RUN mkdir -p AuthoringTools
28+
RUN wget -O AuthoringTools/ada.py https://raw.githubusercontent.com/naman-msft/exec/main/tools/ada.py
29+
RUN chmod +x AuthoringTools/ada.py
30+
31+
# Install the Innovation Engine
32+
COPY . .
33+
RUN make build-ie
34+
ENV PATH="/InnovationEngine/bin:${PATH}"
35+
36+
CMD ["sh", "-c", "ie execute docs/helloWorldDemo.md"]

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ install-ie:
2828
@echo "Installing the Innovation Engine CLI..."
2929
@CGO_ENABLED=0 go install -ldflags "-X $(MODULE_ROOT)/cmd/ie/commands.VERSION=dev -X $(MODULE_ROOT)/cmd/ie/commands.COMMIT=$(LATEST_COMMIT) -X $(MODULE_ROOT)/cmd/ie/commands.DATE=$(BUILD_DATE)" cmd/ie/ie.go
3030

31+
install-ie-home:
32+
@echo "Installing the Innovation Engine CLI to ~/bin..."
33+
@mkdir -p ~/bin
34+
@CGO_ENABLED=0 go build -ldflags "-X $(MODULE_ROOT)/cmd/ie/commands.VERSION=dev -X $(MODULE_ROOT)/cmd/ie/commands.COMMIT=$(LATEST_COMMIT) -X $(MODULE_ROOT)/cmd/ie/commands.DATE=$(BUILD_DATE)" -o ~/bin/ie cmd/ie/ie.go
35+
@echo "IE installed to ~/bin/ie"
36+
3137
# ------------------------------ Test targets ----------------------------------
3238

3339
WITH_COVERAGE := false
@@ -82,6 +88,12 @@ test-upstream-scenarios:
8288
($(MAKE) test-scenario SCENARIO="$${dir}README.md" SUBCRIPTION="$(SUBSCRIPTION)" WORKING_DIRECTORY="$${dir}" ENVIRONMENT="$(ENVIRONMENT)") || exit $$?; \
8389
done
8490

91+
test-docs:
92+
@echo "Testing all documents in the docs folder"
93+
for file in ./docs/*.md; do \
94+
($(MAKE) test-scenario SCENARIO="$${file}") || exit $$?; \
95+
done
96+
8597
# ------------------------------- Run targets ----------------------------------
8698

8799
run-ie: build-ie

README.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,45 @@ command:
5050
./bin/ie execute tutorial.md
5151
```
5252

53+
### Install to ~/bin
54+
55+
If you want to install the Innovation Engine CLI directly to your home bin directory (so it's available system-wide), use:
56+
57+
```bash
58+
make install-ie-home
59+
```
60+
61+
This will build and install the `ie` binary to `~/bin/ie`. Make sure `~/bin` is in your `$PATH` by adding this to your shell profile:
62+
63+
```bash
64+
export PATH="$HOME/bin:$PATH"
65+
```
66+
### Building a Container from Source
67+
68+
```bash
69+
docker build -t ie .
70+
```
71+
72+
Once built you can run the container and connect to it. Innovation Engine will automatically run an introductory
73+
document when you execute this command.
74+
75+
```bash
76+
docker run -it ie
77+
```
78+
79+
You can override the start command if you want to take control immediately with:
80+
81+
```bash
82+
docker run -it ie /bin/sh
83+
```
84+
5385
## Testing Innovation Engine
5486

55-
Innovation Engine is self-documenting, that is all our documentation is written to be executable. Since Innovation Engine can test the actual results of an execution against the intended reslts this means our documentation is also part of our test suite. In our `scripts` folder you will find a `test_ie.sh` script. Running this will run through all of our documentation in test mode.
87+
Innovation Engine is self-documenting, that is all our documentation is written to be executable. Since Innovation Engine can test the results of an execution against the intended results this means our documentation is also part of our test suite. Testing against all our documentation is easy as:
88+
89+
```bash
90+
make test-docs
91+
```
5692

5793
If you make any changes to the IE code (see Contributing below) we would encourage you to tun the full test suite before issuing a PR.
5894

@@ -172,14 +208,27 @@ jobs:
172208
python3 main.py test README.md
173209
```
174210
211+
# Authoring Documents
212+
213+
Authoring documents for use in Innovation Engine is no different from writing high quality documentation for reading. However, it does force you to follow good practice and therefore can sometimes feel a little too involved. That is every edge case needs to be accounted for so that automated testing will reliably pass. We are therefore working on tools to help you in the authoring process.
214+
215+
These tools are independent of Innovation Engine, however, if you build a container from source they will be included in that container. To use them you will need an Azure OpenAI key (you can use an OpenAI key if you prefer) - be sure to add them in the command below.
216+
217+
```bash
218+
docker run -it \
219+
-e AZURE_OPENAI_API_KEY=$AZURE_OPENAI_API_KEY \
220+
-e AZURE_OPENAI_ENDPOINT=$AZURE_OPENAI_ENDPOINT \
221+
ie /bin/sh -c "python AuthoringTools/ada.py"
222+
```
223+
175224
## Contributing
176225

177226
This is an open source project. Don't keep your code improvements,
178227
features and cool ideas to yourself. Please issue pull requests
179228
against our [GitHub repo](https://github.com/Azure/innovationengine).
180229

181230
Be sure to use our Git pre-commit script to test your contributions
182-
before committing, simply run the following command: `python3 main.py test test`
231+
before committing, simply run the following command: `make test-docs`
183232

184233
This project welcomes contributions and suggestions. Most
185234
contributions require you to agree to a Contributor License Agreement

awesome-aks

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 7059c652e797c91d79f7e23ebc4cdd4ee83d7f8e

cmd/ie/commands/clear-env.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package commands
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/Azure/InnovationEngine/internal/lib"
8+
"github.com/Azure/InnovationEngine/internal/logging"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
// Register the command with our command runner.
13+
func init() {
14+
rootCommand.AddCommand(clearEnvCommand)
15+
16+
// Bool flags
17+
clearEnvCommand.PersistentFlags().
18+
Bool("all", false, "Clear both environment variables and working directory state.")
19+
clearEnvCommand.PersistentFlags().
20+
Bool("working-dir", false, "Also clear the working directory state.")
21+
clearEnvCommand.PersistentFlags().
22+
Bool("force", false, "Force clear without confirmation prompt.")
23+
}
24+
25+
var clearEnvCommand = &cobra.Command{
26+
Use: "clear-env",
27+
Short: "Clear the stored environment variables and optionally working directory state.",
28+
Long: `Clear the stored environment variables and optionally working directory state.
29+
30+
This command removes the environment state file that stores variables between
31+
Innovation Engine command executions. By default, it only clears environment
32+
variables, but you can also clear working directory state using the flags.
33+
34+
Examples:
35+
ie clear-env # Clear only environment variables
36+
ie clear-env --working-dir # Clear env vars and working directory
37+
ie clear-env --all # Clear both env vars and working directory
38+
ie clear-env --force # Clear without confirmation`,
39+
Run: func(cmd *cobra.Command, args []string) {
40+
force, _ := cmd.Flags().GetBool("force")
41+
clearAll, _ := cmd.Flags().GetBool("all")
42+
clearWorkingDir, _ := cmd.Flags().GetBool("working-dir")
43+
44+
// Determine what to clear
45+
shouldClearEnv := true // Always clear env vars
46+
shouldClearWD := clearAll || clearWorkingDir
47+
48+
// Show confirmation unless --force is used
49+
if !force {
50+
fmt.Print("This will clear the stored environment state")
51+
if shouldClearWD {
52+
fmt.Print(" and working directory state")
53+
}
54+
fmt.Print(". Continue? (y/N): ")
55+
56+
var response string
57+
fmt.Scanln(&response)
58+
if response != "y" && response != "Y" && response != "yes" {
59+
fmt.Println("Operation cancelled.")
60+
return
61+
}
62+
}
63+
64+
// Clear environment variables
65+
if shouldClearEnv {
66+
if err := lib.DeleteEnvironmentStateFile(lib.DefaultEnvironmentStateFile); err != nil {
67+
// Don't error if file doesn't exist
68+
if !os.IsNotExist(err) {
69+
logging.GlobalLogger.Errorf("Error clearing environment variables: %s", err)
70+
fmt.Printf("Error clearing environment variables: %s\n", err)
71+
os.Exit(1)
72+
} else {
73+
fmt.Println("Environment variables state file was already clear.")
74+
}
75+
} else {
76+
fmt.Println("Environment variables cleared successfully.")
77+
}
78+
}
79+
80+
// Clear working directory state if requested
81+
if shouldClearWD {
82+
if err := lib.DeleteWorkingDirectoryStateFile(lib.DefaultWorkingDirectoryStateFile); err != nil {
83+
// Don't error if file doesn't exist
84+
if !os.IsNotExist(err) {
85+
logging.GlobalLogger.Errorf("Error clearing working directory state: %s", err)
86+
fmt.Printf("Error clearing working directory state: %s\n", err)
87+
os.Exit(1)
88+
} else {
89+
fmt.Println("Working directory state file was already clear.")
90+
}
91+
} else {
92+
fmt.Println("Working directory state cleared successfully.")
93+
}
94+
}
95+
96+
logging.GlobalLogger.Info("Environment state cleared successfully")
97+
},
98+
}

cmd/ie/commands/execute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func init() {
3737
var executeCommand = &cobra.Command{
3838
Use: "execute [markdown file]",
3939
Args: cobra.MinimumNArgs(1),
40-
Short: "Execute the commands for an Azure deployment scenario.",
40+
Short: "Execute the commands in an executable document.",
4141
Run: func(cmd *cobra.Command, args []string) {
4242
markdownFile := args[0]
4343
if markdownFile == "" {

docs/Authoring-With-Copilot.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Confgigure Copilot
2+
3+
* CTRL+SHIFT+P
4+
* Type 'settings.json`
5+
* Select `Preferences Open User Settings`
6+
7+
Add the following to the `settings.json` file that opens.
8+
9+
<!-- TODO: Ensure this is updated from current user settings -->
10+
11+
```json
12+
// A set of instructions that will be added to Copilot requests that generate code.
13+
// Instructions can come from:
14+
// - a file in the workspace: `{ "file": "fileName" }`
15+
// - text in natural language: `{ "text": "Use underscore for field names." }`
16+
//
17+
// Note: Keep your instructions short and precise. Poor instructions can degrade Copilot's quality and performance.
18+
"github.copilot.chat.codeGeneration.instructions": [
19+
{
20+
"text": "When writing mardown files each section should have an introductory paragraph, and optional code block and a summary paragraph."
21+
},
22+
],
23+
```
24+
25+
# Use Copilot
26+
27+
Using Copilot to author docs is easy in Visual Studio Code.
28+
29+
## Initial Authoring
30+
31+
* Create a new document
32+
* `CTRL+I`
33+
* Type "Create an executable document which [Objective]"
34+
* Copilot will attempt to create the document for your, providing heading titles and intro paragraphs
35+
* Review the document, if any section is missing or needs adjustment position the cursor at that point, hit `CTRL-I`, give the instruction
36+
* Work through the document creating the code blocks
37+
38+
## Testing
39+
40+
Once you have the document in good shape and you feel it will work you can test it with Innovation Engine.
41+
42+
* Hit CTRL-SHIFT-` to open a WSL terminal (Innovation Engine does not work in PowerShell)
43+
* Type `ie test filename.md`
44+
* The document will be executed in test mode, any failure will be reported in the terminal
45+
* If you want Copilot assistance with errors, position the cursor in the code block where the error occurred and paste the error message
46+
* Repeat until no errors occur
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This is a simple prerequisite document that sets a value on a test variable:
2+
3+
```bash
4+
export ENV_VAR_TEST="Value set in Environment Variables From Prerequisite."
5+
```

0 commit comments

Comments
 (0)