Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren Edge committed Nov 6, 2024
2 parents 783ac2f + bdb8798 commit e851f25
Show file tree
Hide file tree
Showing 42 changed files with 510 additions and 65 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ coverage.xml
.mypy_cache
.pytest_cache
.ruff_cache
.venv
.venv
.streamlit/app_secrets.toml
.streamlit/secrets.toml
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ jobs:
- name: Install Dependencies
run: poetry install

- name: Tests
run: poetry run poe test
- name: Unit Tests
run: poetry run poe test_unit

- name: Smoke Tests
run: poetry run poe test_smoke


10 changes: 8 additions & 2 deletions .vsts-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ stages:
targetType: "inline"
script: poetry install
- task: Bash@3
displayName: Run Tests
displayName: Run Unit Tests
inputs:
workingDirectory: ./
targetType: "inline"
script: poetry run poe test
script: poetry run poe test_unit
- task: Bash@3
displayName: Run Smoke Tests
inputs:
workingDirectory: ./
targetType: "inline"
script: poetry run poe test_smoke

- job: buildAndPush
displayName: BuildAndPushContainer
Expand Down
130 changes: 130 additions & 0 deletions DEPLOYING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Deploying the app

#### Recommended configuration:

- *Minimum disk space*: 8GB

- *Minimum memory*: 4GB
- If too many users using at the same time, it might need to be higher.

## Azure

You can modify the code and deploy the container, or use our default container hosted on ghcr.io.

### Deploying your container
#### TODO

### Using ghcr.io

**Prerequisites**

- Azure Account: Ensure you have an [active Azure subscription](https://azure.microsoft.com/en-us/pricing/purchase-options/azure-account?msockid=1e4bc940d7cf6738158eda91d616667e).

- Terraform: Install Terraform on your local machine. You can download it from [terraform.io](https://developer.hashicorp.com/terraform/install?product_intent=terraform).

- Azure CLI: Install Azure CLI. You can download it from [docs.microsoft.com](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli).

**Steps**

1. Set Up Azure CLI
Login to Azure:

`az login`

This will open a browser window for you to authenticate.
Set the Subscription:
If you have multiple subscriptions, set the one you wish to use:

`az account set --subscription "your-subscription-id"`

Create a Directory for Your Project:

```
mkdir my-terraform-app
cd my-terraform-app
```
2. Use our Terraform Configuration File:
Download the [terraform configuration file here](https://github.com/microsoft/intelligence-toolkit/blob/main/deploy/azure/main.tf)
-Modify the `variables` default field to match your desired resource configuration
- az_webapp_name (change necessary. Should be unique within Global Azure)
- az_rg_name (change optional)
- location (change optional)
- az_asp_name (change optional)
3. Initialize Terraform
`terraform init`
This command downloads the Azure provider and sets up your workspace.
4. Create an Execution Plan
Plan the Deployment:
`terraform plan`
This command creates an execution plan, which lets you preview the changes that Terraform will make to your infrastructure.
5. Apply the Execution Plan
Deploy the Resources:
`terraform apply`
Terraform will prompt you for confirmation before making any changes. Type yes and press Enter.
6. Verify Deployment
Check the Resources in Azure Portal:
Go to the Azure Portal and verify that the resources have been created.
Check the deployed URL:
`<az_webapp_name>.azurewebsites.net`
## AWS
Wait for step 1 to be set as complete before starting step 2. The whole process will take up to 20 minutes.
1. Launch the infrastructure deploy:
- Give it a sugestive name since you'll be using it in the next step.
[![launch-stack](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=itk-infra-stack&templateURL=https://s3.us-east-1.amazonaws.com/cf-templates-19n482mly1fba-us-east-1/2024-10-07T124926.165Z3xc-infrastructure.yaml)
2. Launch the code deploy
- In VPC Configuration, you should select the resources created by the previous step: <u>VPCId, PublicSubnetAId, PublicSubnetBId, PrivateSubnetAId, PrivateSubnetBId</u>
[![launch-stack](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=itk-code-stack&templateURL=https://s3.us-east-1.amazonaws.com/cf-templates-19n482mly1fba-us-east-1/2024-10-07T125858.730Zlsu-2-development.yaml)
Once step 2 it's complete, in the output tab, you'll see the deployed URL.
**Note: This code doesn't have auth, so this URL will be open to the internet.**
## Environment configuration
`MODE: CLOUD` to hide Settings page so users can't change configuration that would affect other users experiences.
`AUTH_ENABLED: TRUE` if you would like to limit access into the app by user and password defined in a .secrets.toml file inside .streamlit:
```
[passwords]
user_test = "user123"
...
```
Inserting secrets.toml file to the web app:
Add a value of user=password separating each user by `;` to your web app environment.
`USER_CREDENTIALS="user1=pass1;user2=pass2"`
56 changes: 9 additions & 47 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

## Running the app


## GPT settings

You can configure your OpenAI access when running the app via `Settings page`, or using environment variables.
Expand Down Expand Up @@ -104,8 +103,8 @@ See the documentation and an example of how to run the code with your data to ob

##### Recommended configuration:

- *Minimum disk space*: 10GB
- *Minimum memory*: 8GB
- *Minimum disk space*: 8GB
- *Minimum memory*: 4GB

Download, install and then open docker app: https://www.docker.com/products/docker-desktop/

Expand All @@ -122,65 +121,28 @@ Use `cd `+ the path to the folder. For example:

`cd C:\Users\user01\projects\intelligence-toolkit`

Pull the latest built image:
` docker pull ghcr.io/microsoft/intelligence-toolkit:latest`

or build it with your own code:
Build the container:

`docker build . -t intelligence-toolkit`

Once the pull/build ir fininshed, run the docker container:
Once the build is finished, run the docker container:

- via shell:
- via terminal:

`docker run -d -p 80:80 intelligence-toolkit --name intelligence-toolkit`
`docker run -d --name intelligence-toolkit -p 80:80 intelligence-toolkit`

Open [localhost:80](http://localhost:80)

## Deploying

#### Recommended configuration:

- *Minimum disk space*: 10GB

- *Minimum memory*: 8GB
- If too many users using at the same time, it might need to be higher.


### Using AWS

Wait for step 1 to be set as complete before starting step 2. The whole process will take up to 20 minutes.

1. Launch the infrastructure deploy:

- Give it a sugestive name since you'll be using it in the next step.

[![launch-stack](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=itk-infra-stack&templateURL=https://s3.us-east-1.amazonaws.com/cf-templates-19n482mly1fba-us-east-1/2024-10-07T124926.165Z3xc-infrastructure.yaml)

2. Launch the code deploy
- In VPC Configuration, you should select the resources created by the previous step: <u>VPCId, PublicSubnetAId, PublicSubnetBId, PrivateSubnetAId, PrivateSubnetBId</u>

[![launch-stack](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=itk-code-stack&templateURL=https://s3.us-east-1.amazonaws.com/cf-templates-19n482mly1fba-us-east-1/2024-10-07T125858.730Zlsu-2-development.yaml)


Once step 2 it's complete, in the output tab, you'll see the deployed URL.

**Note: This code doesn't have auth, so this URL will be open to the internet.**

### Using Azure

In [this tutorial](https://dev.to/keneojiteli/deploy-a-docker-app-to-app-services-on-azure-5d3h), you can learn how to create the necessary services in azure.

From there, you can deploy it manually as described, or use [our YAML file](/.vsts-ci.yml) to automatically deploy to your environment.

**Note that docker might sleep and you might need to start it again. Open Docker Desktop, in the left menu click on Container and press play on intelligence-toolkit.**

# Lifecycle Scripts

For Lifecycle scripts it utilizes [Poetry](https://python-poetry.org/docs#installation) and [poethepoet](https://pypi.org/project/poethepoet/) to manage build scripts.

Available scripts are:

- `poetry run poe test` - This will execute unit tests.
- `poetry run poe test_unit` - This will execute unit tests on api.
- `poetry run poe test_smoke` - This will execute smoke tests on api.
- `poetry run poe check` - This will perform a suite of static checks across the package, including:
- formatting
- documentation formatting
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ RUN curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor
ENV PATH="/root/.local/bin:$PATH"

COPY . .
RUN rm -rf .streamlit/app_secrets.toml
RUN poetry install --only main

# Run application
EXPOSE 80
ENTRYPOINT ["poetry", "run", "poe", "run_streamlit", "--server.port=80"]
ENTRYPOINT ["poetry", "run", "poe", "run_streamlit", "--server.port=80", "--server.address=0.0.0.0"]
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ flowchart TD

### NGOs

Non-profit organizations can apply for an annual Azure credit grant of up to $3,500, which can be used to set up and run an instance of the intelligence-toolkit app for your organization.
Non-profit organizations can apply for an annual Azure credit grant of $2,000, which can be used to set up and run an instance of the intelligence-toolkit app for your organization.

[Read more about eligibility and registration here](https://nonprofit.microsoft.com/en-us/getting-started)
[Read more about eligibility and registration here](https://www.microsoft.com/en-us/nonprofits/azure)

### Getting started

Expand All @@ -164,10 +164,38 @@ Non-profit organizations can apply for an annual Azure credit grant of up to $3,

- To pull the latest docker image with the app interface, pull it with docker.

docker pull ghcr.io/microsoft/intelligence-toolkit:latest
Download, install and then open docker app: https://www.docker.com/products/docker-desktop/

Then, open a terminal:
Windows: Search and open the app `Windows Powershell` on Windows start menu

Linux and Mac: Open `Terminal`

For any OS:

Navigate to the folder where you cloned this repo.

Use `cd `+ the path to the folder. For example:

`cd C:\Users\user01\projects\intelligence-toolkit`

Build the container:

`docker build . -t intelligence-toolkit`

Once the build is finished, run the docker container:

- via terminal:

`docker run -d --name intelligence-toolkit -p 80:80 ghcr.io/microsoft/intelligence-toolkit:latest`

**Note that docker might sleep and you might need to start it again. Open Docker Desktop, in the left menu click on Container and press play on intelligence-toolkit.**

Open [localhost:80](http://localhost:80)


- To start developing, see [DEVELOPING.md](./DEVELOPING.md).
- To instructions on how to deploy, see [DEPLOYING.md](./DEPLOYING.md).
- To learn about our contribution guidelines, see [CONTRIBUTING.md](./CONTRIBUTING.md).
- For license details, see [LICENSE.md](./LICENSE.md).

Expand Down
8 changes: 4 additions & 4 deletions app/Home.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ def main():
page_icon=f"{path}myapp.ico",
page_title="Intelligence Toolkit | Home",
)

load_multipage_app()
transparency_faq, mermaid_text = get_readme_and_mermaid()

st.markdown(
transparency_faq
)
st.markdown(transparency_faq)

mermaid.mermaid(
code=mermaid_text,
height=1000,
)



if __name__ == "__main__":
main()
main()
Loading

0 comments on commit e851f25

Please sign in to comment.