GoogleCloudPlatform / cloud-code-vscode

Cloud Code for Visual Studio Code: Issues, Documentation and more
Other
413 stars 111 forks source link

Run emulator without vscode #524

Open MaSven opened 2 years ago

MaSven commented 2 years ago

Use case Local development in general. From non vscode editors.

Feature I want to use the apigee emulator for local development and testing. Currently, this is only documented for vscode. As this plugin is not opensource I cannot figure this out myself.

glouischandra commented 2 years ago

Hello @MaSven is there an issue with the VSCode Apigee extension that makes it unusable for local development?

MaSven commented 2 years ago

Have a look at aws apigateway emulator where i can just do sam local start-api and be done with it. https://github.com/aws/serverless-application-model. I'm not tied to any foreign workflow with this.

gsjurseth commented 2 years ago

Executing the emulator outside of VSCode is a good idea and something we're now discussing internally. More info to follow once we have come to some internal decisions.

MaSven commented 2 years ago

Are there any news on this?

gaeshi commented 2 years ago

+1.

My main IDE is IntelliJ IDEA and I would like to be able to deploy to emulator from it. Currently I have to switch between IDEA and VS Code each time I need to deploy to emulator which is not super productive.

tarrball commented 2 years ago

+1 for automated testing

progvb commented 3 months ago

+1 for this feature

bartdw commented 1 month ago

Although it's not documented it is possible to run the emulator on itself. I use the following scripts in vscode to start a pod on podman, deploy a proxy and dependent proxies and run some pyunit tests in vscode. You can however use exactly the same in your cicd pipeline.

This is also a workaround for using podman in vscode, which is not supported by the vscode plugin.

It's not the nicest code, but it does what needs to be done ;-)

file structure

.
|-- apiproxy
|   |-- policies
|   |   |-- ***
|   |-- proxies
|   |   `-- default.xml
|   |-- resources
|   |   `-- ***
|   `-- ***.xml
`-- tests
    |-- scripts
    |   |-- deploy-proxy.sh
    |   |-- run-apigee-pod.sh
    |   `-- src
    |       |-- main
    |       |   `-- apigee
    |       |       |-- apiproxies
    |       |       |   `-- jwks
    |       |       |       `-- apiproxy
    |       |       |           |-- jwks.xml
    |       |       |           |-- policies
    |       |       |           |   `-- ***
    |       |       |           |-- proxies
    |       |       |           |   `-- default.xml
    |       |       |           `-- resources
    |       |       |-- environments
    |       |       |   `-- test
    |       |       |       |-- debugmask.json
    |       |       |       |-- deployments.json
    |       |       |       |-- flowhooks.json
    |       |       |       |-- keystores.json
    |       |       |       `-- targetservers.json
    |       |       `-- sharedflows
    |       `-- tests
    |           `-- test
    |               |-- developerapps.json
    |               |-- developers.json
    |               |-- maps.json
    |               `-- products.json
    `-- test_proxy.py

run-apigee-pod.sh

#!/usr/bin/env bash

APIGEE_VERSION=1.11.0
PODMAN=/opt/homebrew/bin/podman
PODNAME=apigee-emulator-${APIGEE_VERSION}

if ! ${PODMAN} container list | grep ${PODNAME}; then
${PODMAN} pull gcr.io/apigee-release/hybrid/apigee-emulator:${APIGEE_VERSION}
${PODMAN} rm ${PODNAME}
${PODMAN} run \
    --name ${PODNAME} \
    --detach \
    --publish 0.0.0.0:8080:8080 \
    --publish 0.0.0.0:8998:8998 \
    gcr.io/apigee-release/hybrid/apigee-emulator:${APIGEE_VERSION}
fi
${PODMAN} start ${PODNAME}

attempt_counter=0
max_attempts=20

until curl -m 5 --output /dev/null --silent --fail http://localhost:8080/v1/emulator/tree; do
    if [ ${attempt_counter} -eq ${max_attempts} ];then
    echo "Max attempts reached"
    exit 1
    fi

    printf '.'
    attempt_counter=$(($attempt_counter+1))
    sleep 5
done

deploy-proxy.sh

#!/usr/bin/env bash

set -x

PROXY=test-proxy

mkdir temp
cp -R tests/scripts/src temp
mkdir temp/src/main/apigee/apiproxies/${PROXY}
cp -R ./apiproxy temp/src/main/apigee/apiproxies/${PROXY}/
echo '{"proxies": ["'${PROXY}'", "jwks"],"sharedflows": []}' > temp/src/main/apigee/environments/test/deployments.json

cd temp
zip -r apiproxy.zip src
curl -v -X POST "http://localhost:8080/v1/emulator/reset"
curl -v "http://localhost:8080/v1/emulator/deploy?environment=test" \
    -H 'Content-Type: zip' \
    --data-binary "@apiproxy.zip"

cd ..
rm -rf temp

api calls

These are the emulator's api call's I know of:

As you can see also taking traces is possible although it is not (yet?) available in vscode.