GCP: Cloud Run
In this step-by-step guide, we'll guide you how to deploy your VulcanSQL project to Google Cloud Platform(GCP) using Cloud Run. It's a service that we can build and deploy containerized apps written in any language(including Go, Python, Java, Node.js, .Net, and Ruby) on a fully managed platform.
For more detailed information of the deployment process, you can read more here.
Step 1: Install and setup the Google Cloud CLI
Before you begin to use Cloud Run on GCP, you need to do several things:
- In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
- Make sure the billing is enabled for your Google Cloud project.
- Install the Google Cloud CLI.
- Initialize the gcloud CLI with the following command:
gcloud init
- You can set the default project for your Cloud Run service with the following command:
gcloud config set project [PROJECT_ID]
For more detailed instructions on how to setup the environment, you can read more here.
Step 2: Package your VulcanSQL API Server
In this guide, we'll deploy the Docker version of your VulcanSQL API Server. So please execute the following command in the terminal:
vulcan package --output docker
After executing the command, you'll see a message shown like below and a new directory dist
in the project directory.
2023-08-07 08:47:26.246 INFO [CORE] Package successfully, you can go to "dist" folder and run "docker build ." to build the image.
✔ Package successfully.
The directory structure of dist
is as following:
dist
├── Dockerfile
├── config.json
├── index.js
├── package.json
└── result.json
External resources and configurations, such as profiles.yaml
, are not copied to the dist
folder.
You'll need to copy them manually. We strongly recommend using a separate profile instead of the one used for development.
After copying profiles.yaml
into the dist
folder, you should also add one line in Dockerfile
as following:
.
.
.
FROM node:16-bullseye-slim
WORKDIR /usr/app
COPY --from=build /usr/app /usr/app
COPY config.json .
COPY index.js .
COPY result.json .
# add the line below
COPY profiles.yaml .
ENV NODE_ENV production
CMD [ "node", "index.js" ]
Notes: if you have multiple profiles, you should copy them into the dist folder and add them all in the Dockerfile.
Step 3: Deploy to Cloud Run from source
Now you can deploy you VulcanSQL app to GCP with the following command:
gloud run deploy [YOUR_CLOUDRUN_SERVICE_NAME] --port=3000 --allow-unauthenticated
Important: This quickstart assumes that you have owner or editor roles in the project you are using for the quickstart. Otherwise, refer to Cloud Run deployment permissions, Cloud Build permissions, and Artifact Registry permissions for the permissions required.
After successfully deploy the app, you'll see a similar message in the terminal:
Service [vulcansql-project] revision [vulcansql-project-00001-mud] has been deployed and is serving 100 percent of traffic.
Service URL: https://vulcansql-project-ggcxvljfba-df.a.run.app
Congratulations! Now your VulcanSQL app is on the cloud and is ready to be shared to the world!
If you need to clean up the resources on Cloud Run, you can read the documentation here.
Step 4: (Optional) Deploy your VulcanSQL API Catalog Server
If you need to deploy API Catalog Server, you should execute the following command in the terminal:
vulcan package -t catalog-server -o docker
The folder generated by the command is also called dist
, so if you had executed the command of packaging
API server, you should rename the dist
folder generated previously to prevent from being overwritten.
Then, you should modify API_BASE_URL
to the URL of your VulcanSQL API Server you just deployed in Dockerfile:
ENV API_BASE_URL [URL of VulcanSQL API Server]
Finally, you execute the same Google Cloud CLI commands used in the step 3 in the terminal, and change any configurations if you need:
gloud run deploy [YOUR_CLOUDRUN_SERVICE_NAME] --port=4200 --allow-unauthenticated