Skip to content
Open
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
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ jobs:
- name: Run clippy
run: cargo clippy --all -- -Dwarnings

- name: Run compute-static tests
working-directory: terragrunt/modules/crates-io/compute-static
run: |
curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
cargo install --locked viceroy --version 0.15.0
./scripts/run_tests.sh

terraform:
name: Terraform configuration
runs-on: ubuntu-24.04
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[build]
target = "wasm32-wasi"
target = "wasm32-wasip1"

[target.wasm32-wasip1]
runner = "viceroy run -C fastly.toml -- "
78 changes: 48 additions & 30 deletions terragrunt/modules/crates-io/compute-static/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 31 additions & 1 deletion terragrunt/modules/crates-io/compute-static/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,43 @@ responses.

## Development

Build the function:
Install the Fastly CLI from [here](https://www.fastly.com/documentation/reference/tools/cli/#installing).

Then, build the function:

```shell
cd compute-static
fastly compute build
```

## Testing

Testing requires [cargo-nextest](https://nexte.st/docs/installation/pre-built-binaries/), as specified in
the [Fastly documentation](https://www.fastly.com/documentation/guides/compute/developer-guides/rust/). You can install
it from source with binstall:

```shell
cargo install cargo-binstall
cargo binstall cargo-nextest --secure
```

Then, install [Viceroy](https://github.com/fastly/Viceroy) to run the edge function locally:

```shell
cargo install --locked viceroy
```

Due to the fact Viceroy does not allow easily mocking HTTP requests being sent (
see [issue](https://github.com/fastly/Viceroy/issues/442)), some tests use a small Python HTTP
server to work.
For this reason, a wrapper bash script is provided that runs `cargo nextest run` with the test server active in
background. You can therefore run the tests with:
:

```shell
./run_tests.sh
```

## Deployment

Terraform uses an [external data source] to build the function as part of its
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "stable"
channel = "1.90"
targets = ["wasm32-wasip1"]
16 changes: 16 additions & 0 deletions terragrunt/modules/crates-io/compute-static/scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Start the Python HTTP server in the background, which will act as primary host for requests sent from Rust tests
python3 scripts/test_http_server.py &
SERVER_PID=$!

echo "HTTP server started with PID: $SERVER_PID"

# Run the tests while the HTTP server is active in background
cargo nextest run
CARGO_EXIT_CODE=$?

kill $SERVER_PID
echo "HTTP server stopped"

exit $CARGO_EXIT_CODE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from http.server import BaseHTTPRequestHandler, HTTPServer


class MockHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/crates/libgit2-sys/libgit2-sys-0.12.25%2B1.3.0.crate":
self.send_response(200)
self.end_headers()
# The written data is used in Rust tests to verify whether the primary host (this) has actually been queried
self.wfile.write(b'test_data')
else:
self.send_response(404)
self.end_headers()


HTTPServer(("127.0.0.1", 8080), MockHandler).serve_forever()
Loading