diff --git a/.gitignore b/.gitignore index 88635c6..3122811 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,5 @@ install-state.gz # Built binaries /bin pages/plugin.yaml +/public +backend/main diff --git a/README.md b/README.md index f02cf45..cd5a28b 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,9 @@ Available image tags are listed in the [container registry](https://github.com/f In one terminal window, run: 1. `yarn install` -2. `yarn run start` +2. `yarn dev` + +This starts both the Go backend server (port 8080) and the webpack dev server (port 9001) in a single process. In another terminal window, run: diff --git a/hack/dev.sh b/hack/dev.sh new file mode 100755 index 0000000..fb5aff7 --- /dev/null +++ b/hack/dev.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Build pages assets into backend/static so the embedded FS serves them +echo "Building pages assets..." +helm template console-functions-plugin charts/openshift-console-plugin \ + -n console-functions-plugin \ + --set plugin.image=ghcr.io/functions-dev/console-functions-plugin:latest \ + > backend/static/plugin.yaml +cp pages/index.html backend/static/index.html + +# Track background PIDs for cleanup +PIDS=() +cleanup() { + echo "" + echo "Stopping dev servers..." + for pid in "${PIDS[@]}"; do + kill "$pid" 2>/dev/null || true + done + rm -f backend/static/plugin.yaml backend/static/index.html + wait +} +trap cleanup EXIT + +# Start backend API server (also serves pages via embedded static files) +echo "Starting backend server on :8080..." +(cd backend && go run ./main.go -http-port 8080) & +PIDS+=($!) + +# Start webpack dev server +echo "Starting webpack dev server..." +yarn webpack serve --progress & +PIDS+=($!) + +echo "" +echo "Dev environment running:" +echo " Backend: http://localhost:8080" +echo " Plugin: http://localhost:9001" +echo "" + +wait diff --git a/package.json b/package.json index 3a1012e..fc08643 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "clean": "rm -rf dist", "build": "yarn clean && NODE_ENV=production yarn webpack", "build-dev": "yarn clean && yarn webpack", + "dev": "./hack/dev.sh", "start": "yarn webpack serve --progress", "start-console": "./start-console.sh", "test": "vitest run", diff --git a/start-console.sh b/start-console.sh index 62eddd8..82e7ea5 100755 --- a/start-console.sh +++ b/start-console.sh @@ -63,6 +63,9 @@ else PLUGIN_HOST="host.docker.internal" fi CONTAINER_NETWORK_OPTS="-p ${CONSOLE_PORT}:9000" +if [[ "$(uname -s)" == "Darwin" ]]; then + CONTAINER_NETWORK_OPTS="${CONTAINER_NETWORK_OPTS} --add-host api.crc.testing:host-gateway" +fi BRIDGE_PLUGINS="${PLUGIN_NAME}=http://${PLUGIN_HOST}:${PLUGIN_PORT}" BRIDGE_PLUGIN_PROXY='{"services":[{"consoleAPIPath":"/api/proxy/plugin/'"${PLUGIN_NAME}"'/backend/","endpoint":"http://'"${PLUGIN_HOST}"':'"${BACKEND_PORT}"'","authorize":false}]}'