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

CtrlX Python Web Server

CtrlX Python Web Server

Deniz
Member

Hello all,

I did a simple web server with Python Flask but when I create a .snap file, it does not include the static files (html, css, etc.). My question is how can I add external folders to my snapcraft yaml file ?

5 REPLIES 5

nickH
Community Moderator
Community Moderator

Hello,

You can use a part in the snapcraft.yaml to dump the files you need into your snap. 

This is an excerpt from the snapcraft.yaml of the python-sample webserver in the SDK (see it on GitHub) :

 

parts:
  webserver:
    plugin: python
    source: .

  configs:
    plugin: dump
    source: ./configs
    organize:
      'package-assets/*': package-assets/${SNAPCRAFT_PROJECT_NAME}/

  www:
    plugin: dump
    source: ./www

 

 

 

Due to the last three lines snapcraft packs everything whats in the folder /www into your snap. 

For more detailed information see:

 

Best regards, 

Nick

 

Hi,

Thank you for the quick answer.

Yes, I actually tried this by taking this sample as a reference but it did not work. I am still getting an error "File not found". Here is the related part of my "snapcraft.yaml" file:

 

parts:
  flask-app:
    plugin: python
    source: .
    python-version: python3
    requirements: [requirements.txt]

  configs:
    source: ./configs
    plugin: dump
    organize:
      'package-assets/*': package-assets/${SNAPCRAFT_PROJECT_NAME}/   

  templates:
    source: ./templates
    plugin: dump
  
  static:
    source: ./static
    plugin: dump

 

"templates" and "static" are the folders that I would like to include

Best, Deniz

 

 

nickH
Community Moderator
Community Moderator

Hello, 

I just modified the webserver example with the snapcraft.yaml you send me and added the two folder with two test text files inside. And in my test the files get dumped into the snap. 

Are you really sure, the files in the folders "templates" and "static" get not packed into your snap?

You can check that by unpacking the snap like a .zip archive. Maybe the path you are using in your application is not correct. 

 

Best regards, 

Nick

Hi,

I added the folders manually by unzipping the .snap file and zip it again. However, it still did not work 🙂

I realized that the CtrlX core is serving the application from the different root directory ("/var/snap") and did not copy my files and folders to that directory

nickH
Community Moderator
Community Moderator

Hi,

to clarify some things:

  1. Unzipping your snap is just a proposed debug method from me to check what's inside of your snap. Just zip it again after unpacking will not work!
  2. A snap always runs in it's own sandbox with no access to system resources outside of the snap itself. This default security policy can be extended through the use of interfaces. A interface which could be used to store and access data from different snaps can be the active solution interface (see this thread for more information). 

 

But to have the files inside of your snap should work for you. And the way to do it is with parts in the snapcraft.yaml, like I mentioned above. 

If this still doesn't work for you, you can write me a private message with your contact data and we can find a way how I can give you personal support. 

 

Best regards,

Nick

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