Skip to content

na-launch-workshop/workshop-nodejs-blue_green_deployments

Repository files navigation

🚀 Module: Node.js Hello Country Service

Technology Stack:

  • Knative
  • Node.js

🎯 Scenario

Simple Express service that returns a phonetic "Hello World" greeting for a configured country code. The app loads configuration from environment variables (via dotenv for local development) and supports deployment to Knative.


✏️ Local Development

  1. Run the application
npm install
npm run dev
  1. Set the greeting by updating .env or exporting variables before running:
export COUNTRY_CODE=GA
export PORT=3000
npm start

🔨 Container Build

Select the option that is most appropriate:

Generic Registry

# Replace <registry>/<repo> with your container registry path
IMAGE=<REGISTRY>/<REPOSITORY>/hello-country-service:latest

podman build -t "$IMAGE" .
# or: docker build -t "$IMAGE" .

podman push "$IMAGE"
# or: docker push "$IMAGE"

OpenShift Local Registry (external route)

oc project <NAMESPACE>
REGISTRY=$(oc registry info)
podman login -u "$(oc whoami)" -p "$(oc whoami -t)" "$REGISTRY"
IMAGE=${REGISTRY}/<NAMESPACE>/hello-country-service:latest
podman build -t "$IMAGE" .
podman push "$IMAGE"

Build Inside OpenShift (BuildConfig)

# Point to the project that should own the image
oc project <NAMESPACE>

# Create a Docker strategy BuildConfig (run once)
oc new-build --strategy=docker --binary --name hello-country-service

# Start a build using the local working tree and stream logs
oc start-build hello-country-service --from-dir=. --follow

# Verify the resulting image stream tag
oc get is hello-country-service -n <NAMESPACE>

The successful build publishes the image at:

image-registry.openshift-image-registry.svc:5000/<NAMESPACE>/hello-country-service:latest

🚢 Deploy to Knative

  1. Update knative-service.yaml with your image reference (for OpenShift local registry, set your-namespace accordingly), then apply it:
oc apply -f knative-service.yaml -n <NAMESPACE>
  1. Knative injects a PORT environment variable automatically; do not set one in the manifest. Override the greeting via COUNTRY_CODE.

Or, using the Knative CLI without modifying the YAML:

IMAGE=image-registry.openshift-image-registry.svc:5000/<NAMESPACE>/hello-country-service:latest

kn service apply hello-country-service \
  --image "$IMAGE" \
  --env COUNTRY_CODE=EN
  1. Retrieve the URL:
kn service describe hello-country-service -o url
  1. Test the service once it is ready:
curl "$(kn service describe hello-country-service -o url)"
  1. To update the greeting later, patch the service:
kn service update hello-country-service --env COUNTRY_CODE=FR

About

Module: Node.js Hello Country Service

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors