cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Building snap application for nodejs project

Building snap application for nodejs project

jawad
Long-established Member

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/corepackScreenshot_2.png
14 REPLIES 14

Sgilk
Contributor

Hi,

What version of ctrlX Works and the SDK are you using?

Could you please provide a screenshot of the build script? I notice you have a CMakeLists.txt file in your project. I'm wondering if your build scripts were also copied from a c++ sample?

If these are the proper build scripts for Node-JS, you could try executing them via terminal rather than build task. Any build logs or additional info would be useful in troubleshooting.

MauroRiboniMX
Contributor

Hello, 

you have to run als the two scripts provided in the ./script folder:

- install SDK 

- install node

DO you have internet connection in the Build Environment?

jawad
Long-established Member

No additional logs are showing, beacuse it doesnot generate any error,
But i can share you my snapcraft.yaml file, maybe i making any mistake in snapcraft.yaml file. 

name: node-express-app
version: "1.0.0"
summary: Node.js Express Application.
description: |
  This is a description of your Node.js Express application.
confinement: devmode
grade: stable
base: core22
type: app

apps:
  node-express-app:
    command: node app.js
    restart-condition: always
    plugs:
          - network-bind

parts:
  node-express-app:
    source: .
    plugin: npm
    npm-include-node: true
    npm-node-version: 18.17.0
   
    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

jawad
Long-established Member

Yes, I have internet connection i have verify it through by google ping, and i have installed both of above mentioned.

may be i am making mistake in snapcraft.yaml file, here is my yaml file

name: node-express-app
version: "1.0.0"
summary: Node.js Express Application.
description: |
  This is a description of your Node.js Express application.
confinement: devmode
grade: stable
base: core22
type: app

apps:
  node-express-app:
    command: node app.js
    restart-condition: always
    plugs:
          - network-bind

parts:
  node-express-app:
    source: .
    plugin: npm
    npm-include-node: true
    npm-node-version: 18.17.0
   
    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



Are you using the standard SDK examples? Can you try the "helloWord" example from the SDK? 🙂

Just to understand if you're all set or your Build ENvironment has some problems.

jawad
Long-established Member

I have used examples from ctrlx-automation-sdk folder. for helloworld cpp it works fine. but when i build snap for available helloworld examples of nodejs. it build successfully, but on uploading and installation on ctrlx i got this error 

jawad_0-1698302647764.png

 

Hello, 

Tha is perfectly fine, the message says that you need core22 app: the SDK is already on core22 but the the core is still on core20 and by default has no core22 installed. No problem you have 3 options:

- Get core22 from the collab room if you have the collab room
- Connect your core to interne, fix the time and then he should be able to get it automatically from google.
- Activate the possibility to install app from unknown sources (3 dots on the top right) and download it not signed from canonical: 
"UBUNTU_STORE_ARCH=arm64 snap download core22" and install it. 

GIve me a feedback. Then your setup is good. 

jawad
Long-established Member

how i can Connect your core to interne

Hello, 

Set the actual date correct and then you can connect it to a router :). Both interfaces have the DHCP client function active. If you have no possibility go for option 3.

Anyway if you packed the app that means that your setup is correct and that the problem is somwhere in your app.

Mauro

 

jawad
Long-established Member

jawad_0-1698313771497.pngi already checked this unknown resources tab.  and for point 2 , already connected to internet, i am running virtual machine through ip.

what does it means 
 not signed from canonical: 
"UBUNTU_STORE_ARCH=arm64 snap download core22" and install it. 

 

Hello, 

If you are using the virtual control you have to use UBUNTU_STORE_ARCH=amd64,

If you want to connect the virtual core to internet then depends by your setup. Here there is an example: https://developer.community.boschrexroth.com/t5/Store-and-How-to/Connect-ctrlX-COREvirtual-to-the-in...

More info about signed topic here here: https://snapcraft.io/docs/assertions

CodeShepherd
Community Moderator
Community Moderator

Please see various how tos from the how to collection:

  • Connect ctrlX COREvirtual to the Internet [DOCU]
  • Connect real ctrlX CORE via proxy to the Internet [DOCU]
  • Connect Notebook and Internet to a ctrlX CORE [DOCU]

 

jawad
Long-established Member

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

jawad_0-1700052447838.png

 

Hello @jawad ,
Just to confirm the issue was just the core 22?
Another question, in you snapcraft add that code that looks from Cmakelists.txt?
Thank you, I really appreciate your reply.
Best regards

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist