<p>The Node JS app that I'm trying to deploy in Kubernetes runs on <code>express js</code> as a backend framework.The repository is managed via <code>Bitbucket</code>. The application is a microservice and the pipeline manifest file for building the Docker image is written this way:</p>
<pre><code>options:
  docker: true
image: node:14.17.0
pipelines:
  branches:
    test:
      - step:
          services:
           - docker
          name: Build and push new docker image
          deployment: dev
          script:
            - yarn install
            - yarn build
            - yarn test
            - yarn lint
            - make deploy.dev
            - docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD
            - docker build -t testapp/helloapp:latest -f ./Dockerfile .
            - docker push testapp/helloapp
          caches:
            - docker # adds docker layer caching
</code></pre>
<p>The K8s cluster is hosted on <a href="https://upcloud.com/community/tutorials/deploy-kubernetes-using-kubespray/" rel="nofollow noreferrer">cloud</a> but does not have the internal <code>Load Balancer</code> of their own. The K8s cluster version is <code>v1.22.4</code> and <code>MetalLB v0.11.0</code> is configured to serve the Load Balancing purpose. To expose the K8s <code>service</code>- Cloudflare Tunnel is configured as a K8s <code>deployment</code>.</p>
<p>So, this is the manifest file set-up used for building the Docker image. The pipeline deploys successfully and in the Kubernetes part, this is the <code>service</code> and <code>deployment</code> manifest:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
 name: helloapp
 labels:
   app: helloapp
spec:
 type: NodePort
 ports:
 - port: 5000
   targetPort: 7000
   protocol: TCP
   name: https
 selector:
   app: helloapp

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloapp
  labels:
    app: helloapp
spec:
  replicas: 3
  selector:
    matchLabels:
      app: helloapp
  template:
    metadata:
      labels:
        app: helloapp
    spec:
      imagePullSecrets:
      - name: regcred
      containers:
      - name: helloapp
        image: testapp/helloapp:latest
</code></pre>
<p>Also, here is the <code>Dockerfile</code> snippet to give more clarity on what I have been doing:</p>
<pre><code>FROM node:14.17.0

WORKDIR /app

COPY package.json /app

RUN npm install

COPY . /app

CMD node app.js

EXPOSE 8100
</code></pre>
<p>Just to give a context, the service and deployment works fine, with no <code>CrashLoopBackOff</code> or any other errors.
My doubt here is, there is <code>dist</code> directory which is not getting deployed to Docker Hub as it is generated during <code>npm build</code>. How can I deploy the app along with the <code>dist</code> directory without having to worry about security risks? Any feedbacks and suggestions on where I could add a script to pull the <code>dist</code> directory would be appreciated.</p>

<p>Eventually, I could resolve the issue. The issue was trivial yet bothering. In the <code>Dockerfile</code>, there was a missing script, i.e., <code>npm run build</code>. So, here is the final <code>Dockerfile</code> I used it for building the <code>dist</code> directory along with other requirements:</p>
<pre><code>FROM node:14.17.0

WORKDIR /app

COPY package.json /app

RUN npm install

RUN npm run build &lt;------ the missing script

COPY . /app

CMD node app.js

EXPOSE 8100
</code></pre>
<p>This way, the entire <code>dist</code> directory gets built inside the container. Also, I removed all the <code>.ENV</code> dependencies from <code>dist</code> directory and stored as Kubernetes secret in <code>base64</code> format.</p>
