-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from games-on-whales/dev-backend-api
Exposing Wolf events via API
- Loading branch information
Showing
63 changed files
with
4,127 additions
and
1,321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,3 +130,43 @@ jobs: | |
IMAGE_SOURCE=${{ steps.prep.outputs.github_server_url }}/${{ github.repository }} | ||
cache-from: ${{ steps.prep.outputs.cache_from }} | ||
cache-to: ${{ steps.prep.outputs.cache_to }} | ||
|
||
test_devcontainer: | ||
runs-on: ubuntu-latest | ||
needs: buildx | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Login to GitHub Container Registry | ||
if: steps.prep.outputs.has_github_token != '' # secrets not available in PRs | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GHCR_TOKEN }} | ||
|
||
- name: Run tests in devcontainer | ||
uses: devcontainers/[email protected] | ||
with: | ||
imageTag: devcontainer | ||
imageName: ghcr.io/${{ github.repository_owner }}/wolf | ||
cacheFrom: ghcr.io/${{ github.repository_owner }}/wolf:${{github.ref_name}} | ||
push: never | ||
# TODO: | ||
# runCmd: | | ||
# cmake -Bbuild \ | ||
# -H$GITHUB_WORKSPACE \ | ||
# -DCMAKE_BUILD_TYPE=Debug \ | ||
# -DCMAKE_CXX_EXTENSIONS=OFF \ | ||
# -DTEST_VIRTUAL_INPUT=OFF \ | ||
# -DTEST_DOCKER=ON \ | ||
# -DTEST_RUST_WAYLAND=ON \ | ||
# -DTEST_NVIDIA=OFF \ | ||
# -DTEST_EXCEPTIONS=OFF \ | ||
# -DTEST_UHID=OFF \ | ||
# -G Ninja | ||
# | ||
# ninja -j $(nproc) wolftests | ||
# | ||
# ./wolftests --reporter JUnit::out=${{runner.workspace}}/report.xml --reporter console::out=-::colour-mode=ansi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
:includedir: partial$ | ||
= Wolf API | ||
|
||
Wolf exposes a REST API that allows you to interact with the platform programmatically. + | ||
The API can be accessed only via UNIX sockets, you can control the exact path by setting the `WOLF_SOCKET_PATH` environment variable. If you want to access the socket from outside the container, you should mount the socket to the host machine, ex: `-e WOLF_SOCKET_PATH=/var/run/wolf/wolf.sock` and `-v /var/run/wolf:/var/run/wolf` will allow you to access the socket from the host machine at `/var/run/wolf/wolf.sock`. | ||
|
||
You can test out the API using the `curl` command, for example, to get the OpenAPI specification you can run: | ||
|
||
[source,bash] | ||
.... | ||
curl --unix-socket /var/run/wolf/wolf.sock http://localhost/api/v1/openapi-schema | ||
.... | ||
|
||
When looking at the examples in the xref:api_reference[] remember to add the `--unix-socket` flag to the `curl` command. | ||
|
||
== Exposing the API via TCP | ||
|
||
[WARNING] | ||
==== | ||
Exposing the API is highly dangerous, via the API you can pair clients to the server, execute arbitrary commands, and more. + | ||
*Make sure to secure the API properly if you decide to expose it.* | ||
==== | ||
|
||
If you want to expose the API via TCP you can use a reverse proxy like `nginx`, for example, to expose the API on port 8080 you can use the following config | ||
|
||
.... | ||
server { | ||
listen 8080; | ||
location / { | ||
proxy_pass http://unix:/var/run/wolf/wolf.sock; | ||
proxy_http_version 1.0; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
} | ||
} | ||
.... | ||
|
||
Save it as `wolf.conf` and start an Nginx container with the following command: | ||
|
||
[source,bash] | ||
.... | ||
docker run --name wolf-proxy \ | ||
--network=host \ | ||
-v /var/run/wolf/wolf.sock:/var/run/wolf/wolf.sock:rw \ | ||
-v ./wolf.conf:/etc/nginx/conf.d/wolf.conf:ro \ | ||
nginx | ||
.... | ||
|
||
You can now access the API via `http://localhost:8080`, ex: | ||
|
||
[source,bash] | ||
.... | ||
curl localhost:8080/api/v1/openapi-schema | ||
.... | ||
|
||
[#api_reference] | ||
== API Reference | ||
|
||
[subs=macros] | ||
++++ | ||
<script | ||
id="api-reference" | ||
type="application/json"> | ||
include::{includedir}/spec.json[] | ||
</script> | ||
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script> | ||
++++ |
Oops, something went wrong.