Skip to content

Commit

Permalink
Simple http2 server config
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Zago <[email protected]>
  • Loading branch information
rafaelvzago committed Jan 6, 2025
1 parent 356324d commit 79f4060
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 193 deletions.
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ RUN wget -O go.tar.gz $GO_URL && \
tar -C /usr/local -xzf go.tar.gz && \
rm go.tar.gz

# Add SSL certificates
COPY certs /etc/nginx/certs

# Set Go path
ENV PATH="/usr/local/go/bin:${PATH}"

Expand Down
175 changes: 86 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
Here's the updated README that includes both the new HTTP/2 examples and the original `ping` example:

---

# Lanyard - A Versatile Networking Toolkit Docker Image

**Lanyard** is a Docker image based on Alpine Linux that includes a comprehensive set of networking tools along with a simple Flask API. This image allows you to either run the Flask application or execute any of the included networking utilities directly.
**Lanyard** is a Docker image based on Alpine Linux that includes a comprehensive set of networking tools and a lightweight Nginx server with HTTPS and HTTP/2 support. This image allows you to serve static files securely or execute any of the included networking utilities directly.

## Table of Contents

- [Included Tools](#included-tools)
- [Getting Started](#getting-started)
- [Running the Flask API](#running-the-flask-api)
- [Running Nginx](#running-nginx)
- [Running Networking Tools](#running-networking-tools)
- [Flask Application](#flask-application)
- [Nginx Configuration](#nginx-configuration)
- [HTTP/2 Support](#http2-support)
- [Building the Docker Image Locally](#building-the-docker-image-locally)
- [Usage Examples](#usage-examples)
- [Notes](#notes)
Expand All @@ -17,6 +22,7 @@

The Docker image includes the following tools:

- `bash`
- `curl`
- `traceroute`
- `openssl`
Expand All @@ -36,27 +42,27 @@ The Docker image includes the following tools:
- `coreutils`
- `mongodb-tools`
- `postgresql-client`
- `py3-flask`
- **Go** (installed minimally)
- `nginx`

## Getting Started

### Running the Flask API
### Running Nginx

To run the Flask API, execute the following command:
To run the Nginx server:

```sh
docker run --rm -d -p 5000:5000 quay.io/rzago/lanyard:latest
docker run --rm -d -p 8080:8080 quay.io/rzago/lanyard:latest
```

- `--rm`: Automatically removes the container when it exits.
- `-d`: Runs the container in detached mode.
- `-p 5000:5000`: Maps port 5000 of the host to port 5000 of the container.
- `-p 8080:8080`: Maps port 8080 of the host to port 8080 of the container.

Once the container is running, you can access the API at [http://localhost:5000/](http://localhost:5000/). You should see the message:
Once the container is running, you can access the server at [http://localhost:8080](http://localhost:8080). You will see the response:

```
Hello, World from Lanyard!
<h1>Hello from Lanyard</h1>
```

### Running Networking Tools
Expand All @@ -81,121 +87,112 @@ PING google.com (142.250.79.14): 56 data bytes
round-trip min/avg/max = 7.189/7.298/7.509 ms
```

## Flask Application
## Nginx Configuration

The Flask application (`app.py`) included in the image is a simple "Hello World" app:
### Default Configuration

```python
from flask import Flask
- **HTTP/2 and HTTP/1.1:** Nginx supports both HTTP/2 and HTTP/1.1.
- **Static Files:** Static files are served from `/usr/share/nginx/html`.

app = Flask(__name__)
### Custom Configuration

@app.route('/')
def hello_world():
return 'Hello, World from Lanyard!'
You can mount custom Nginx configuration files to modify the server's behavior:

if __name__ == '__main__':
app.run(host='0.0.0.0')
```sh
docker run --rm -d -p 8080:8080 -v $(pwd)/my-nginx.conf:/etc/nginx/nginx.conf quay.io/rzago/lanyard:latest
```

## Building the Docker Image Locally
## HTTP/2 Support

If you prefer to build the Docker image locally, use the provided `Dockerfile`:
Nginx in the Lanyard image supports HTTP/2. Below are examples demonstrating HTTP/2 and HTTP/1.1 behavior:

```dockerfile
FROM alpine:latest

# Install base tools
RUN apk update && apk add --no-cache \
curl \
traceroute \
openssl \
iperf \
wget \
busybox-extras \
nmap \
netcat-openbsd \
tcpdump \
mtr \
socat \
bind-tools \
iproute2 \
openssh-client \
python3 \
procps \
coreutils \
mongodb-tools \
postgresql-client \
py3-flask

# Install Go separately in a minimal way
RUN apk add --no-cache --virtual .build-deps go && \
mkdir -p /usr/local/go/bin && \
mv /usr/bin/go /usr/local/go/bin/ && \
apk del .build-deps

# Copy the Flask app
COPY app.py /app.py

# Expose port 5000 for the Flask app
EXPOSE 5000

# Default command to run the Flask app
CMD ["python3", "/app.py"]
```

**Build the image:**
#### Testing HTTP/2

```sh
docker build -t lanyard .
curl --http2 --http2-prior-knowledge http://localhost:8080
```

## Usage Examples
Output:

Here are some examples of how to use the Docker image to run various networking tools.
```html
<h1>Hello from Lanyard</h1>
```

### Run `ping`
#### Testing HTTP/1.1

```sh
docker run --rm lanyard ping -c 4 google.com
curl http://localhost:8080
```

### Run `traceroute`
Output:

```sh
docker run --rm lanyard traceroute google.com
```html
<h1>Hello from Lanyard</h1>
```

### Run `curl`
#### Inspecting HTTP Headers (HTTP/1.1)

```sh
docker run --rm lanyard curl -I https://www.google.com
curl -I http://localhost:8080
```

Output:

```
HTTP/1.1 200 OK
Server: nginx/1.26.2
Date: Mon, 06 Jan 2025 18:06:29 GMT
Content-Type: text/html
Content-Length: 29
Last-Modified: Mon, 06 Jan 2025 18:06:06 GMT
Connection: keep-alive
ETag: "677c1b8e-1d"
Accept-Ranges: bytes
```

### Run `nmap`
#### Inspecting HTTP Headers (HTTP/2)

```sh
docker run --rm lanyard nmap -sV google.com
curl -I --http2 --http2-prior-knowledge http://localhost:8080
```

Output:

```
HTTP/2 200
server: nginx/1.26.2
date: Mon, 06 Jan 2025 18:06:39 GMT
content-type: text/html
content-length: 29
last-modified: Mon, 06 Jan 2025 18:06:06 GMT
etag: "677c1b8e-1d"
accept-ranges: bytes
```

### Run `iperf`
## Building the Docker Image Locally

If you prefer to build the Docker image locally, use the provided `Dockerfile`:

```sh
# As an iperf server
docker run --rm -p 5201:5201 lanyard iperf -s
docker build -t lanyard .
```

# As an iperf client
docker run --rm lanyard iperf -c <server_ip>
## Usage Examples

### Run `ping`

```sh
docker run --rm lanyard ping -c 4 google.com
```

## Notes
### Serve Custom Static Files

Mount a directory containing your static files:

- **Default Behavior:** If no command is specified, the container will run the Flask API.
- **Overriding the Command:** You can run any of the included tools by specifying the command after the image name.
- **Exposed Ports:** Ensure that the ports you intend to use are not blocked by your firewall or used by other applications.
- **Networking:** When running networking tools, you might need to adjust Docker's network settings depending on your environment.
- **Alpine Linux:** The image is based on Alpine Linux for a minimal footprint.
```sh
docker run --rm -d -p 8080:8080 -v $(pwd)/html:/usr/share/nginx/html quay.io/rzago/lanyard:latest
```

---

Feel free to contribute or raise issues if you encounter any problems. Enjoy using Lanyard for all your networking needs!
Feel free to contribute or raise issues if you encounter any problems. Enjoy using Lanyard for all your networking and lightweight web-serving needs!
22 changes: 0 additions & 22 deletions certs/server.crt

This file was deleted.

28 changes: 0 additions & 28 deletions certs/server.key

This file was deleted.

39 changes: 0 additions & 39 deletions custom-nginx-http2.conf

This file was deleted.

6 changes: 5 additions & 1 deletion custom-nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ events {}
http {
server {
listen 8080;
http2 on;

root /usr/share/nginx/html; # Set the root directory for your static files
index index.html; # Specify the default index file

location / {
return 200 "Hello, Lanyard!";
try_files $uri $uri/ =404; # Ensure files in the root directory are served
}
}
}
Expand Down
12 changes: 1 addition & 11 deletions html/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome</title>
</head>
<body>
<h1>Hello from Lanyard</h1>
</body>
</html>
<h1>Hello from Lanyard</h1>

0 comments on commit 79f4060

Please sign in to comment.