loading...
Cover image for Get Out, Git! - Building SaaS #33

Get Out, Git! - Building SaaS #33

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

Building SaaS (52 Part Series)

1) Building SaaS with Python and Django #1 2) Reporting scraped data - Building SaaS #2 3 ... 50 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 49) Starting the Onboarding Flow - Building SaaS #49 50) Onboarding Continuity - Building SaaS #50 51) Onboarding Forms - Building SaaS #51 52) Consistent Onboarding - Building SaaS #52

In this episode, I removed the Git clone from the server. This is some of the final cleanup to streamline the deployment process.

Before we could remove the clone completely, we had to decouple the final remaining connections that still depended on the repository clone.

The first thing to clean up was the Let's Encrypt certificate fetching process. The load balancer's Ansible playbook had this task:

- name: Create cert
  become: yes
  command: >
    /usr/bin/letsencrypt certonly --webroot
    --email "{{ secrets.conductor.email }}"
    --agree-tos
    --webroot-path "{{ client_root }}"
    -d "{{ root_domain }}"
    -d "{{ client_domain }}"
  when: deployment == "production" and certdir.stat.isdir is not defined
  notify:
    - Restart Nginx

The trouble was that this client_root pointed at a directory within the repository. This was for historical reasons related to hosting my long-since-gone Ember client app. We changed the client_root, but then had the challenge of how to test the change.

My staging environment doesn't use actual Let's Encrypt certificates. You can observe in the Ansible task above that the task only runs when the deployment is "production". To get some confidence that the change would work, I deployed, the logged into the server and ran the letsencrypt command above, but used the --dry-run option to test things out.

Along the way of making this client_root change, I explained how Let's Encrypt works to fetch TLS certificates for your domain. It's a really great service!

The other big change that I made centered around getting the Git SHA of the master branch. Since this process is removing the clone, we needed a way to get the SHA because that is used as the version to pull the application from S3.

Getting the SHA from a local clone is a side effect of using the Git module in Ansible. Without that clone, I needed another command. Ultimately, I crafted this task:

- name: Get the latest SHA from GitHub
  become: yes
  shell: "git ls-remote https://github.com/mblayman/conductor.git \
    refs/heads/master | cut -f1"
  register: gitsha

ls-remote lets you inspect the branches of a remote repository. The output include more information than I needed, but the trusty old cut command let me extract the SHA quickly.

With the Git clone removed, I can remove the ssh deployment key for my system which will tighten up the security of my deployment process.

On the next stream, I'm thinking of using WhiteNoise to make my static asset management even simpler and continue cleaning up deployment.

This article first appeared on mattlayman.com.

Building SaaS (52 Part Series)

1) Building SaaS with Python and Django #1 2) Reporting scraped data - Building SaaS #2 3 ... 50 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 49) Starting the Onboarding Flow - Building SaaS #49 50) Onboarding Continuity - Building SaaS #50 51) Onboarding Forms - Building SaaS #51 52) Consistent Onboarding - Building SaaS #52

Posted on 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