NuxtJS deployment using CircleCi CPU spikes 100%+

Posted April 7, 2021 369 views

I am deploying my NuxtJS app using a deployment script, which I added below. I use some of the instructions from this tutorial:

If I access my droplet using SSH and run the script manually, it seems to work fine. But as soon as CircleCI starts a docker instance (see config.yml below), it needs at least 5 minutes to run the script, if I am lucky. And while doing that, the CPU of my droplet spikes, and it takes a lot of patience trying to reconnect with my droplet using SSH from my local machine.

Quite odd this only happens when running the script through CircleCI. I tried to spin up a medium docker instance, instead of a small, but without luck. Most of the time, the deployment is killed after 10 minutes, so I end up with a failed deployment most of the time.

If CircleCI fails, my droplet’s CPU stays over 100% and node_modules/.bin/nuxt build keeps running. Rebooting the droplet is the easiest solution (sometimes necessary, if reconnecting using SSH just isn’t possible or the terminal which is already connected, isn’t responding anymore). After reboot, the first CircleCi deployment succeeds and the rest fail again.

I looked at htop, and it seems that kswapd0 takes over 40% CPU, snapd over 30 and the rest are for node, etc.


#move to project folder
cd /var/www/

#pull from the branch
git pull origin main

# build nuxt project and run pm2
npm install
npm run build

pm2 start

circleci config.yml

version: 2.1

      - image: buildpack-deps:trusty
    resource_class: small   # we use a small docker instance to use as little credits as possible
      - add_ssh_keys:
            - "xx:xx:xx:xx:xx:xx:xx:xx"
      - run:
          name: Deploy Over SSH
          command: |
              ssh -oStrictHostKeyChecking=no -v $SSH_USER@$SSH_HOST "./"
      - deploy:
                - main # only deploy on the main branch

Any thoughts?

My droplet: 1 GB Memory / 25 GB Disk / AMS3 - Ubuntu 20.04 (LTS) x64

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Solved it:
Saving some memory for other processes, by setting the –max-old-space-size parameter on the build process in package.json seems to solve this. My app was deployed in under a minute.

"build": "node --max-old-space-size=600 node_modules/nuxt/bin/nuxt.js build"