loading...
Cover image for Ripping Out Node.js - Building SaaS #30

Ripping Out Node.js - Building SaaS #30

mblayman profile image Matt Layman Originally published at mattlayman.com ・2 min read

Building SaaS (48 Part Series)

1) Building SaaS with Python and Django #1 2) Reporting scraped data - Building SaaS #2 3 ... 46 3) Multiple Stripe plans - Building SaaS #3 4) Using a background scheduler - Building SaaS #4 5) Updating data models - Building SaaS #5 6) Third party integration modeling - Building SaaS #6 7) Displaying third party data - Building SaaS #7 8) Connecting third party services - Building SaaS #8 9) Finishing third party integration - Building SaaS #9 10) Admin dashboards - Building SaaS #10 11) Semi-automated tasks - Building SaaS #11 12) Automation aides - Building SaaS #12 13) Deploying with Ansible - Building SaaS #13 14) Ansible Cranked to 11 - Building SaaS #14 15) Feature Flags with Django Waffle - Building SaaS #15 16) Feature Flags in Action - Building SaaS #16 17) Canceling Stripe Subscriptions - Building SaaS #17 18) Completing Account Deactivation - Building SaaS #18 19) Pip-tools and App Packaging - Building SaaS #19 20) Making a Shiv App - Building SaaS #20 21) Shiv zipapps and CI - Building SaaS #21 22) Upload to S3 with CircleCI orbs - Building SaaS #22 23) It's Alive! A Django Shiv app - Building SaaS #23 24) In the Guts of a Shiv App - Building SaaS #24 25) It's Permissions, Dummy! - Building SaaS #25 26) Connecting Shiv Apps with Ansible - Building SaaS #26 27) Plug the Shiv App Into Nginx - Building SaaS #27 28) Webpack and collectstatic in CI - Building SaaS #28 29) Add Static Assets to Deployment - Building SaaS #29 30) Ripping Out Node.js - Building SaaS #30 31) Celery In A Shiv App - Building SaaS #31 32) wal-e Postgres Backups - Building SaaS #32 33) Get Out, Git! - Building SaaS #33 34) Bring in the WhiteNoise, Bring in Da Funk - Building SaaS #34 35) Deploying WhiteNoise - Building SaaS #35 36) Configurama - Building SaaS #36 37) Lessons From A Failed SaaS - Building SaaS #37 38) New Project, Who Dis? - Building SaaS #38 39) django-environ and django-debug-toolbar - Building SaaS #39 40) Make A Custom User Model - Building SaaS #40 41) User Accounts With django-allauth - Building SaaS #41 42) Add Styles To Templates - Building SaaS #42 43) Use Tailwind On A Template - Building SaaS #43 44) Fast Forms With UpdateView - Building SaaS #44 45) Templates and Logic - Building SaaS #45 46) A Week At A Time - Building SaaS #46 47) How To Style Sign Up - Building SaaS #47 48) Onboarding - Building SaaS #48

In this episode, we removed Node.js from deployment. We had to finish off an issue with permissions first, but the deployment got simpler. Then we continued on the steps to make deployment do even less.

Last episode, we got the static assets to the staging environment, but we ended the session with a permissions problem. The files extracted from the tarball had the wrong user and group permissions.

I fixed the permissions by running an Ansible task that ran chown to use the www-data user and group. To make sure that the directories had proper permissions, I used 755 to ensure they were executable.

Then we wrote another task to set the permission of non-directory files to 644. This change removes the executable bit from regular files and reduces their security risk.

We ran some tests to confirm the behavior of all the files, even running the test that destroyed all existing static files and starting from scratch.

With the permissions task complete, we could move onto the fun stuff of ripping out code. Since all the static files are now created in Continuous Integration, there is no need for Node.js on the actual server. We removed the Ansible galaxy role and any task that used Node.js to run JavaScript.

Once Node was out of the way, I moved on to other issues. I had to convert tasks that used manage.py from the Git clone to use the manage command that I bundled into the Shiv app. That work turned out to be very minimal.

The next thing that can be removed is the Python virtual environment that was generated on the server. The virtual environment isn't needed because all of the packages are baked into the Shiv app. That means that we must remove anything that still depends on the virtual environment and move them into the Shiv app.

There are two main tools that still depend on the virtual environment:

  1. Celery
  2. wal-e for Postgres backups

For the remainder of the stream, I worked on the main.py file, which is the entry point for Shiv, to make the file able to handle subcommands. This will pave the way for next time when we call Celery from a Python script instead of its stand-alone executable.

Show notes for this stream are at Episode 30 Show Notes.

To learn more about the stream, please check out Building SaaS with Python and Django.

Building SaaS (48 Part Series)

1) Building SaaS with Python and Django #1 2) Reporting scraped data - Building SaaS #2 3 ... 46 3) Multiple Stripe plans - Building SaaS #3 4) Using a background scheduler - Building SaaS #4 5) Updating data models - Building SaaS #5 6) Third party integration modeling - Building SaaS #6 7) Displaying third party data - Building SaaS #7 8) Connecting third party services - Building SaaS #8 9) Finishing third party integration - Building SaaS #9 10) Admin dashboards - Building SaaS #10 11) Semi-automated tasks - Building SaaS #11 12) Automation aides - Building SaaS #12 13) Deploying with Ansible - Building SaaS #13 14) Ansible Cranked to 11 - Building SaaS #14 15) Feature Flags with Django Waffle - Building SaaS #15 16) Feature Flags in Action - Building SaaS #16 17) Canceling Stripe Subscriptions - Building SaaS #17 18) Completing Account Deactivation - Building SaaS #18 19) Pip-tools and App Packaging - Building SaaS #19 20) Making a Shiv App - Building SaaS #20 21) Shiv zipapps and CI - Building SaaS #21 22) Upload to S3 with CircleCI orbs - Building SaaS #22 23) It's Alive! A Django Shiv app - Building SaaS #23 24) In the Guts of a Shiv App - Building SaaS #24 25) It's Permissions, Dummy! - Building SaaS #25 26) Connecting Shiv Apps with Ansible - Building SaaS #26 27) Plug the Shiv App Into Nginx - Building SaaS #27 28) Webpack and collectstatic in CI - Building SaaS #28 29) Add Static Assets to Deployment - Building SaaS #29 30) Ripping Out Node.js - Building SaaS #30 31) Celery In A Shiv App - Building SaaS #31 32) wal-e Postgres Backups - Building SaaS #32 33) Get Out, Git! - Building SaaS #33 34) Bring in the WhiteNoise, Bring in Da Funk - Building SaaS #34 35) Deploying WhiteNoise - Building SaaS #35 36) Configurama - Building SaaS #36 37) Lessons From A Failed SaaS - Building SaaS #37 38) New Project, Who Dis? - Building SaaS #38 39) django-environ and django-debug-toolbar - Building SaaS #39 40) Make A Custom User Model - Building SaaS #40 41) User Accounts With django-allauth - Building SaaS #41 42) Add Styles To Templates - Building SaaS #42 43) Use Tailwind On A Template - Building SaaS #43 44) Fast Forms With UpdateView - Building SaaS #44 45) Templates and Logic - Building SaaS #45 46) A Week At A Time - Building SaaS #46 47) How To Style Sign Up - Building SaaS #47 48) Onboarding - Building SaaS #48

Posted on Mar 5 by:

mblayman profile

Matt Layman

@mblayman

Matt Layman is a software engineer from Frederick, MD. He is an open source software maintainer and advocate for Python.

Discussion

markdown guide
 

Is Python really better than Node.js for backend, unless you want to use some specific library?

 

I like Python a lot, but Node.js is a good ecosystem too! I wasn't trying to make a value judgement about Node.js or its community. This stream was all about me removing Node.js from my production deployment process.

I needed npm packages to build my JavaScript for my project. Previous streams showed how I moved that JavaScript building into my CI system. This stream removed JavaScript building from the deployment to production to make deployment shorter, do less work, and safer.

So, both are great. :)