-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#185492729 : Istio support and example cluster configuration (#4)
Istio support for the WASM plugin
- Loading branch information
Showing
17 changed files
with
469 additions
and
64 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Build environment setup | ||
# examples/envoy/docker-compose.yaml shows how to mount the build directory | ||
# as a volume so the build artifacts will be cached locally | ||
FROM rust:1.70.0 as builder | ||
|
||
# The user ID and group ID of the host user | ||
# so the container can be run as the host user to avoid permission issues | ||
ARG USER_ID | ||
ARG GROUP_ID | ||
|
||
# Create a new user with the host user's ID and group ID | ||
# This enables mounting the project directory as a volume for build caching | ||
RUN groupadd -f -g $GROUP_ID user && useradd -l -u $USER_ID -g user user | ||
USER user | ||
|
||
WORKDIR /build | ||
|
||
# Install wasm32-wasi target to build for WASM | ||
RUN rustup target add wasm32-wasi |
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,3 @@ | ||
FROM scratch | ||
|
||
COPY moesif_envoy_wasm_plugin.wasm ./plugin.wasm |
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,34 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: echo | ||
namespace: default | ||
spec: | ||
ports: | ||
- port: 80 | ||
targetPort: 5678 | ||
selector: | ||
app: echo | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: echo | ||
namespace: default | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: echo | ||
template: | ||
metadata: | ||
labels: | ||
app: echo | ||
spec: | ||
containers: | ||
- name: echo | ||
image: hashicorp/http-echo | ||
args: | ||
- "-text=Hello from echo service" | ||
ports: | ||
- containerPort: 5678 |
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,35 @@ | ||
apiVersion: networking.istio.io/v1beta1 | ||
kind: Gateway | ||
metadata: | ||
name: http-echo-gateway | ||
namespace: default | ||
spec: | ||
selector: | ||
istio: ingressgateway | ||
servers: | ||
- port: | ||
number: 80 | ||
name: http | ||
protocol: HTTP | ||
hosts: | ||
- "*" | ||
--- | ||
apiVersion: networking.istio.io/v1beta1 | ||
kind: VirtualService | ||
metadata: | ||
name: echo-virtual-service | ||
namespace: default | ||
spec: | ||
hosts: | ||
- "*" | ||
gateways: | ||
- http-echo-gateway | ||
http: | ||
- match: | ||
- uri: | ||
exact: /echo | ||
route: | ||
- destination: | ||
host: echo | ||
port: | ||
number: 80 |
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,26 @@ | ||
# This file is used to configure Istio to allow traffic to Moesif API | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: ServiceEntry | ||
metadata: | ||
name: moesif | ||
namespace: istio-system | ||
spec: | ||
hosts: | ||
- api.moesif.net | ||
ports: | ||
- number: 443 | ||
name: https | ||
protocol: HTTPS | ||
location: MESH_EXTERNAL | ||
resolution: DNS | ||
--- | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: DestinationRule | ||
metadata: | ||
name: moesif | ||
namespace: istio-system | ||
spec: | ||
host: api.moesif.net | ||
trafficPolicy: | ||
tls: | ||
mode: SIMPLE |
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,19 @@ | ||
apiVersion: extensions.istio.io/v1alpha1 | ||
kind: WasmPlugin | ||
metadata: | ||
name: moesif-plugin | ||
namespace: istio-system | ||
spec: | ||
selector: | ||
matchLabels: | ||
istio: ingressgateway | ||
url: oci://docker.io/moesif/moesif-envoy-wasm-plugin:latest | ||
imagePullPolicy: Always | ||
phase: AUTHZ | ||
priority: 10 | ||
pluginConfig: | ||
moesif_application_id: <YOUR MOESIF APPLICATION ID> | ||
user_id_header: X-User-Example-Header | ||
company_id_header: X-Company-Example-Header | ||
upstream: outbound|443||api.moesif.net | ||
debug: true |
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,46 @@ | ||
#!/bin/bash -e | ||
|
||
TAG=${1:-latest} | ||
if [ "$2" == "debug" ]; then | ||
BUILD_VARIANT=debug | ||
BUILD_FLAGS="" | ||
else | ||
BUILD_VARIANT=release | ||
BUILD_FLAGS="--release" | ||
fi | ||
|
||
# Docker image names | ||
REPO=docker.io/moesif | ||
TAG_BUILD=$REPO/moesif-envoy-wasm-plugin-builder:latest | ||
TAG_ARTIFACT=$REPO/moesif-envoy-wasm-plugin:$TAG | ||
TAG_LATEST=$REPO/moesif-envoy-wasm-plugin:latest | ||
|
||
# Get the directory of this script to make sure we can run it from anywhere | ||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
BASE_DIR="$SCRIPT_DIR/../.." | ||
SOURCE="$BASE_DIR/moesif-wasm" | ||
OUTPUT="$SOURCE/target/wasm32-wasi/$BUILD_VARIANT" | ||
|
||
# Create the build environment for the plugin | ||
docker build \ | ||
--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) \ | ||
-t $TAG_BUILD \ | ||
-f $BASE_DIR/Cargo-build.dockerfile \ | ||
$SOURCE | ||
|
||
# perform the build inside the container by mounting the current directory | ||
docker run \ | ||
-v $SOURCE:/build \ | ||
$TAG_BUILD \ | ||
bash -c "cargo build --target=wasm32-wasi $BUILD_FLAGS" | ||
|
||
# package the plugin into a docker image for deployment | ||
docker build \ | ||
-t $TAG_ARTIFACT \ | ||
-f $BASE_DIR/examples/istio/artifact.dockerfile \ | ||
$OUTPUT | ||
|
||
docker push $TAG_ARTIFACT | ||
|
||
docker tag $TAG_ARTIFACT $TAG_LATEST | ||
docker push $TAG_LATEST |
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,48 @@ | ||
#!/bin/bash -e | ||
TAG=${1:-latest} | ||
|
||
if [ "$2" == "debug" ]; then | ||
BUILD_VARIANT=debug | ||
BUILD_FLAGS="" | ||
else | ||
BUILD_VARIANT=release | ||
BUILD_FLAGS="--release" | ||
fi | ||
|
||
TAG=${1:-latest} | ||
|
||
# WASME is use to publish to WebAssemblyHub | ||
# https://docs.solo.io/web-assembly-hub/latest/installation/ | ||
WASME=$HOME/.wasme/bin/wasme | ||
|
||
# Get the directory of this script to make sure we can run it from anywhere | ||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
BASE_DIR="$SCRIPT_DIR/../.." | ||
SOURCE="$BASE_DIR/moesif-wasm" | ||
OUTPUT="$SOURCE/target/wasm32-wasi/$BUILD_VARIANT" | ||
|
||
# Docker image names | ||
TAG_BUILD=moesiftest.azurecr.io/moesif-envoy-wasm-plugin-builder:latest | ||
TAG_ARTIFACT=webassemblyhub.io/brian_moesif/moesif_envoy_wasm_plugin | ||
|
||
# Create the build environment for the plugin | ||
docker build \ | ||
--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) \ | ||
-t $TAG_BUILD \ | ||
-f $BASE_DIR/Cargo-build.dockerfile \ | ||
$SOURCE | ||
|
||
# perform the build inside the container by mounting the current directory | ||
docker run \ | ||
-v $SOURCE:/build \ | ||
$TAG_BUILD \ | ||
bash -c "cargo build --target=wasm32-wasi $BUILD_FLAGS" | ||
|
||
# package the plugin into a docker image for deployment | ||
VERSION_TAG=$TAG_ARTIFACT:$TAG | ||
$WASME build precompiled $BASE_DIR/moesif-wasm/target/wasm32-wasi/$BUILD_VARIANT/moesif_envoy_wasm_plugin.wasm --tag $VERSION_TAG --config $BASE_DIR/runtime-config.json | ||
$WASME push $VERSION_TAG | ||
|
||
LATEST_TAG=$TAG_ARTIFACT:latest | ||
$WASME tag $VERSION_TAG $LATEST_TAG | ||
$WASME push $LATEST_TAG |
Oops, something went wrong.