Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restructure and add new demos #24

Merged
merged 12 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 1 addition & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1 @@
# Qpoint Demos

A collection of apps and helpers to quickly spin up demos

## Setup

Ensure you have all the necessary dependencies:

```bash
make ensure-deps
```

Then build the necessary resources and images:

```bash
make build
```

## Usage

Check to see which apps are available:

```bash
make help
```

Bring up an app:

```bash
make <app>-app

# for example
make gpt4-app
```

Teardown when complete

```bash
make down
```
# QPoint Demo Repository
47 changes: 47 additions & 0 deletions apps/.tools/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

# Get the directory of the current script
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")

# Move to one directory above the script directory
cd "$SCRIPT_DIR/.."

# Read the templates from files
README_WEB_TEMPLATE=$(cat "$SCRIPT_DIR/readme.web.md")
README_CONSOLE_TEMPLATE=$(cat "$SCRIPT_DIR/readme.console.md")

# Skip
skip_projects=()

# List of console languages
console_languages=("curl")

# Iterate through each directory looking for a Dockerfile
for dir in */; do
if [ -f "${dir}Dockerfile" ]; then
# Remove the trailing slash from the directory name
service_name=${dir%/}

# Check if the service_name is in the skip_projects array
if [[ " ${skip_projects[@]} " =~ " ${service_name} " ]]; then
echo "Skipping $service_name"
continue
fi

# Extract the service language
service_language=$(echo "$service_name" | cut -d'-' -f1)

# Choose the appropriate template based on the service language
if [[ " ${console_languages[@]} " =~ " ${service_language} " ]]; then
readme_content=$(echo "$README_CONSOLE_TEMPLATE" | sed "s/{{service_name}}/$service_name/g" | sed "s/{{service_language}}/$service_language/g")
else
readme_content=$(echo "$README_WEB_TEMPLATE" | sed "s/{{service_name}}/$service_name/g" | sed "s/{{service_language}}/$service_language/g")
fi

# Write the content to README.md in the current directory
echo "$readme_content" > "${dir}README.md"
fi
done

echo "README.md files generated successfully."

85 changes: 85 additions & 0 deletions apps/.tools/readme.console.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!--

Warning: This is a generated file. Do Not Edit.

-->
# GeoWeather App ({{service_language}})

A simple demo application that displays the weather for the user's current location based on their IP address. The app is built using `{{service_language}}` and accepts `HTTP_PROXY` and `HTTPS_PROXY` environment variables for interacting with QPoint.

## Prerequisites

- Git
- Docker

## Running the Application

### 1. Setup a Qpoint Qproxy
This demo utilizes the Qpoint Control Plane and requires a free Qpoint account.

1. Head over to [Qpoint](https://qpoint.io) and sign up for an account.
2. Click the `+ Go` button on the nav bar.
3. Select the `Deploy Qproxy` option.
4. Select `Docker`.
5. Copy the provided Docker run command and execute it in a terminal.
6. Set the Address, `localhost` is probably fine for this example.

At this point, you'll have a running Qpoint proxy ready to take on traffic!

### 2. Connect an App to a Transparent Qpoint Proxy

1. On the [Qpoint Dashboard](https://qpoint.io), select `+ Go`.
2. Select `Connect an App` on the right side of the menu.
3. Select the `Proxy Environment Variable` option.
4. Select the `Transparent Proxy` option.
5. Make a note of the HTTP and HTTPS proxy URLs.

### 3. Clone the Repository

```
git clone https://github.com/qpoint-io/demos.git
cd demos/apps/{{service_name}}
```

### 4. Build & Start the Docker Container
Within an app directory of your choosing, run the following command to build and run the application.

> Note: If you used an address other than "localhost," make sure to update those values in this command.

```
docker build -t {{service_name}} . && \
docker run -it --rm \
--network host \
-e http_proxy=http://localhost:18080 \
-e HTTP_PROXY=http://localhost:18080 \
-e HTTPS_PROXY=http://localhost:18443 \
{{service_name}}
```

> Note: This command uses the host machine's network to provide access to the published ports in the Qpoint container.

### 5. Test the App

This app will output details to console, they may look something like:

```bash
Starting weather function
> HTTPS_PROXY environment variable is not set. Skipping.

1. Public IP fetched: 172.217.22.14

2. Location fetched for IP 172.217.22.14:
Vancouver, Canada
(49.2827, -123.1207)

3. Weather for Edmonton, Canada
Temperature: 16.9°C
```

### 6. Review Traffic

This app reaches out to various APIs to retrieve your remote IP, geo-IP location, and weather data. Navigating to the [Qpoint Traffic Dashboard](https://qpoint.io) will display the domain URLs being accessed by the application. Each domain is clickable and will let you dive into the traffic for each.

## License

This project is licensed under the Apache-2.0 License.
70 changes: 70 additions & 0 deletions apps/.tools/readme.web.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!--

Warning: This is a generated file. Do Not Edit.

-->
# GeoWeather App ({{service_language}})

A simple demo application that displays the weather for the user's current location based on their IP address. The app is built using `{{service_language}}` and accepts `HTTP_PROXY` and `HTTPS_PROXY` environment variables for interacting with QPoint.

## Prerequisites

- Git
- Docker

## Running the Application

### 1. Setup a Qpoint Qproxy
This demo utilizes the Qpoint Control Plane and requires a free Qpoint account.

1. Head over to [Qpoint](https://qpoint.io) and sign up for an account.
2. Click the `+ Go` button on the nav bar.
3. Select the `Deploy Qproxy` option.
4. Select `Docker`.
5. Copy the provided Docker run command and execute it in a terminal.
6. Set the Address, `localhost` is probably fine for this example.

At this point, you'll have a running Qpoint proxy ready to take on traffic!

### 2. Connect an App to a Transparent Qpoint Proxy

1. On the [Qpoint Dashboard](https://qpoint.io), select `+ Go`.
2. Select `Connect an App` on the right side of the menu.
3. Select the `Proxy Environment Variable` option.
4. Select the `Transparent Proxy` option.
5. Make a note of the HTTP and HTTPS proxy URLs.

### 3. Clone the Repository

```
git clone https://github.com/qpoint-io/demos.git
cd demos/apps/{{service_name}}
```

### 4. Build & Start the Docker Container
Within an app directory of your choosing, run the following command to build and run the application.

> Note: If you used an address other than "localhost," make sure to update those values in this command.

```
docker build -t {{service_name}} . && \
docker run -it --rm \
--network host \
-e HTTP_PROXY=http://localhost:18080 \
-e HTTPS_PROXY=http://localhost:18443 \
{{service_name}}
```

> Note: This command uses the host machine's network to provide access to the published ports in the Qpoint container.

### 5. Test the App

Navigate to [localhost:4000](http://localhost:4000) and check the weather for your location.

### 6. Review Traffic

This app reaches out to various APIs to retrieve your remote IP, geo-IP location, and weather data. Navigating to the [Qpoint Traffic Dashboard](https://qpoint.io) will display the domain URLs being accessed by the application. Each domain is clickable and will let you dive into the traffic for each.

## License

This project is licensed under the Apache-2.0 License.
25 changes: 25 additions & 0 deletions apps/curl-geoweather/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use a lightweight image with necessary tools
FROM alpine:latest

# cURL only accpets http proxy in lowercase
ENV http_proxy=${HTTP_PROXY}

# Get latest CA's, cURL, and jq
ARG TOKEN
RUN apk --no-cache add curl jq bash ca-certificates && \
if [ -n "$TOKEN" ]; then \
curl -s https://api.qpoint.io/deploy/certificate -H "Authorization: Bearer $TOKEN" > /usr/local/share/ca-certificates/qpoint-ca.crt && \
update-ca-certificates; \
fi

# Set the working directory inside the container
WORKDIR /app

# Copy the Bash script into the container
COPY geoweather.sh .

# Ensure the script has execute permissions
RUN chmod +x geoweather.sh

# Run the Bash script when the container launches
CMD ["./geoweather.sh"]
85 changes: 85 additions & 0 deletions apps/curl-geoweather/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!--

Warning: This is a generated file. Do Not Edit.

-->
# GeoWeather App (curl)

A simple demo application that displays the weather for the user's current location based on their IP address. The app is built using `curl` and accepts `HTTP_PROXY` and `HTTPS_PROXY` environment variables for interacting with QPoint.

## Prerequisites

- Git
- Docker

## Running the Application

### 1. Setup a Qpoint Qproxy
This demo utilizes the Qpoint Control Plane and requires a free Qpoint account.

1. Head over to [Qpoint](https://qpoint.io) and sign up for an account.
2. Click the `+ Go` button on the nav bar.
3. Select the `Deploy Qproxy` option.
4. Select `Docker`.
5. Copy the provided Docker run command and execute it in a terminal.
6. Set the Address, `localhost` is probably fine for this example.

At this point, you'll have a running Qpoint proxy ready to take on traffic!

### 2. Connect an App to a Transparent Qpoint Proxy

1. On the [Qpoint Dashboard](https://qpoint.io), select `+ Go`.
2. Select `Connect an App` on the right side of the menu.
3. Select the `Proxy Environment Variable` option.
4. Select the `Transparent Proxy` option.
5. Make a note of the HTTP and HTTPS proxy URLs.

### 3. Clone the Repository

```
git clone https://github.com/qpoint-io/demos.git
cd demos/apps/curl-geoweather
```

### 4. Build & Start the Docker Container
Within an app directory of your choosing, run the following command to build and run the application.

> Note: If you used an address other than "localhost," make sure to update those values in this command.

```
docker build -t curl-geoweather . && \
docker run -it --rm \
--network host \
-e http_proxy=http://localhost:18080 \
-e HTTP_PROXY=http://localhost:18080 \
-e HTTPS_PROXY=http://localhost:18443 \
curl-geoweather
```

> Note: This command uses the host machine's network to provide access to the published ports in the Qpoint container.

### 5. Test the App

This app will output details to console, they may look something like:

```bash
Starting weather function
> HTTPS_PROXY environment variable is not set. Skipping.

1. Public IP fetched: 172.217.22.14

2. Location fetched for IP 172.217.22.14:
Vancouver, Canada
(49.2827, -123.1207)

3. Weather for Edmonton, Canada
Temperature: 16.9°C
```

### 6. Review Traffic

This app reaches out to various APIs to retrieve your remote IP, geo-IP location, and weather data. Navigating to the [Qpoint Traffic Dashboard](https://qpoint.io) will display the domain URLs being accessed by the application. Each domain is clickable and will let you dive into the traffic for each.

## License

This project is licensed under the Apache-2.0 License.
Loading
Loading