Quick Start
This guide gets floci-gcp running and verifies that GCP SDK and gcloud CLI commands work against it in under five minutes.
Step 1 — Start floci-gcp
Step 2 — Configure GCP emulator environment variables
GCP SDKs automatically skip credential validation when these emulator variables are set:
export PUBSUB_EMULATOR_HOST=localhost:4578
export FIRESTORE_EMULATOR_HOST=localhost:4578
export DATASTORE_EMULATOR_HOST=localhost:4578
export STORAGE_EMULATOR_HOST=http://localhost:4578
export SECRET_MANAGER_EMULATOR_HOST=localhost:4578
Add these to your shell profile (.bashrc / .zshrc) to persist across sessions.
Step 3 — Verify the Setup
Run a few quick smoke tests using the gcloud CLI:
gcloud config set project floci-local
# Pub/Sub — create a topic and publish a message
gcloud pubsub topics create my-topic
gcloud pubsub subscriptions create my-sub --topic=my-topic
gcloud pubsub topics publish my-topic --message="hello from floci-gcp"
gcloud pubsub subscriptions pull my-sub --auto-ack
# Cloud Storage — create a bucket and upload a file
gcloud storage buckets create gs://my-bucket
echo "hello floci-gcp" | gcloud storage cp - gs://my-bucket/hello.txt
gcloud storage ls gs://my-bucket
Step 4 — Use in Your Application
Point your GCP SDK clients at floci-gcp:
// Pub/Sub
ManagedChannel channel = ManagedChannelBuilder
.forTarget("localhost:4578")
.usePlaintext()
.build();
TopicAdminClient topicAdminClient = TopicAdminClient.create(
TopicAdminSettings.newBuilder()
.setTransportChannelProvider(
FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)))
.setCredentialsProvider(NoCredentialsProvider.create())
.build());
topicAdminClient.createTopic(TopicName.of("floci-local", "my-topic"));
// Cloud Storage
Storage storage = StorageOptions.newBuilder()
.setHost("http://localhost:4578")
.setProjectId("floci-local")
.setCredentials(NoCredentials.getInstance())
.build()
.getService();
storage.create(BucketInfo.of("my-bucket"));
storage.create(BlobInfo.newBuilder("my-bucket", "hello.txt").build(),
"hello from floci-gcp".getBytes());
import os
os.environ["PUBSUB_EMULATOR_HOST"] = "localhost:4578"
from google.cloud import pubsub_v1
publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path("floci-local", "my-topic")
publisher.create_topic(request={"name": topic_path})
future = publisher.publish(topic_path, b"hello from floci-gcp")
future.result()