Building snap application for nodejs project

I have simple nodejs project, i am trying to build its snap application but getting issues, first of all, what i did,

1) Installed CtrlX works, installed and run virtual enviorment

2) Then create ctrlX CORE App build enviorement and started,

3) Using Remote SSH for vscode. and created nodejs application. npm install 

4) then create snapcraft.yaml describe below, then try to make its by run task build -> amd64

5) it takes more than 8 hours but process is on-going, screen shot attached.


Plus i have also build an snap application of helloworld example available in ctrlx-automation-sdk folder but that provide me built fine, 

here is my snapcraft.yaml 

version: "1.0.0"
name: node-express-app
summary: Node.js Express Application.
description: |
  This is a description of your Node.js Express application.

confinement: strict
grade: devel
base: core22
type: app

apps:
  app:
    command: app.js
    daemon: simple
    plugs:
      - node
    restart-condition: always
    passthrough:
      restart-delay: 10s  

parts:
  app:
    source: src
    build-environment:
      # Set the node version here. We recommend using the latest LTS version.
      - NODE_VERSION: "18.17.0"
    plugin: npm

    override-build: |
      # set target arch
      if [ $SNAPCRAFT_TARGET_ARCH == "arm64" ]; then
          arch="arm64"
      else
          arch="x64"
      fi

      # fetch node
      echo fetching: $node_uri

      if [ ! -f "${SNAPCRAFT_PART_INSTALL}/bin/node" ]; then
          curl $node_uri | tar xzf - -C $SNAPCRAFT_PART_INSTALL/ --no-same-owner --strip-components=1
      fi
      npm install --ignore-scripts --no-fund --unsafe-perm
      node app.js
   
      npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --ignore-scripts --omit=dev --no-fund --unsafe-perm

      # remove unused node_modules
      rm -rf ${SNAPCRAFT_PART_INSTALL}/lib/node_modules/npm
      rm -rf ${SNAPCRAFT_PART_INSTALL}/lib/node_modules/corepack
Best reply by jawad

Thanks everyone 

I achevied it, Built snap app, then installed on ctrlx works. then I access the snap web app by ip address and the route define in code

 

View original
14 replies