Skip to content

Insight and analysis of technology and business strategy

Analyzing a Movie Dataset Housed on MongoDB Through GraphQL - Part 3: App Containerization & Deployment

If you haven't read Part 2 of the Analyzing a Movie Dataset Housed on MongoDB Through GraphQL series, please click here.

Our application is now running locally; let's containerize it and deploy it to GKE.

Docker file:

FROM node:16-slim

# Create and change to the app directory.
WORKDIR /usr/src/app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure copying both package.json AND package-lock.json (when available).
# Copying this first prevents re-running npm install on every code change.
COPY package*.json ./

RUN npm ci --only=production

# Remove the below dependencies from package.json while installing and run them separately.
RUN npm install graphql-type-json --legacy-peer-deps 
RUN npm install graphql-iso-date --legacy-peer-deps 

# Copy local code to the container image.
COPY . ./

EXPOSE 10000

# Run the web service on container startup.
CMD npm start

Let's execute the build command to generate an application image and push it to GCR (Google Container Registry):

gcloud builds submit --tag gcr.io/<<project_id>>/movie-analysis-v2

Let's use the image to deploy the application on a Kubernetes cluster.

1. Navigate to the Kubernetes cluster and click on deploy.

2. Select the image from the GCR and set deployment name in “Configuration section”.

3. Let's build a load balancer to make the application accessible from outside the cluster. Configure Target Port as 10000 and click on Deploy.

When all the stages are completed, we will get the result displayed in the figure below.

We would be directed to the Application UI after clicking the Endpoints link.

As seen in the image above, we are able to select and query columns (email and name), and the results are obtained from MongoDB. 

Conclusion

The declarative model (schema based) of GraphQL enables you to design an API that is predictable and consistent across all of your clients. That API remains unchanged from the client's perspective regardless of the addition, deletion, or shift backend (data storage / DB).

Top Categories

  • There are no suggestions because the search field is empty.

Tell us how we can help!

dba-cloud-services
Upcoming-Events-banner