Atomic Deployment for JS Hipsters

Rate this content
Bookmark

Deploying an app is all but an easy process. You will encounter a lot of glitches and pain points to solve to have it working properly. The worst is: that now that you can deploy your app in production, how can't you also deploy all branches in the project to get access to live previews? And be able to do a fast-revert on-demand?

Fortunately, the classic DevOps toolkit has all you need to achieve it without compromising your mental health. By expertly mixing Git, Unix tools, and API calls, and orchestrating all of them with JavaScript, you'll master the secret of safe atomic deployments.

No more need to rely on commercial services: become the perfect tool master and netlifize your app right at home!

This talk has been presented at DevOps.js Conf 2024, check out the latest edition of this JavaScript Conference.

FAQ

In atomic deployment, you take two versions of an existing application and deploy only the changes between these two versions. Everything is self-contained, allowing you to take a whole archive of a version at any point in time without worrying about dependencies or build processes.

Netlify simplifies deployment by automatically deploying changes pushed to a branch on your version server, like GitHub. You get instant previews on staging URLs, and updates to branches automatically update the previews, making deployment a seamless process.

The key features include configurability for easy adaptation to different projects, compatibility with any hosting provider, integration with micro-CI for handling dependencies and builds, minimal downtime during deployment, and auto-publishing to update previews automatically.

Matt is a Developer Experience Engineer at Always Data, an independent hosting provider. He focuses on improving developer experience, particularly on the CLI and tools associated with the platform.

You configure a project for atomic deployment by initializing a bare repository on the server, linking it to your local project, and setting configuration variables using Git config. The deployment process is automated through Git hooks, specifically the post-receive hook.

Git hooks allow you to react to events in the Git repository's lifecycle. The post-receive hook is particularly useful for deployment as it triggers actions like building and deploying the application each time changes are pushed.

Hard links are used to copy only the changed files between versions, improving performance and maintaining self-containment. This ensures that each version of the application is complete and standalone without duplicating the entire content.

SSH remote access is crucial as it allows secure interaction with the server for tasks like initializing repositories, configuring projects, and automating deployments through Git hooks.

Yes, webhooks can be used to automate the process of pushing changes from the origin remote to the deploy remote, reducing friction and improving the developer experience.

Keep the process simple and maintainable by using Git config for storing variables, abstracting web hosting changes through API calls, and leveraging Node.js or Deno as CI engines for build processes. This ensures a smooth and adaptable deployment workflow.

m4dz
m4dz
25 min
15 Feb, 2024

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This Talk discusses atomic deployment for JavaScript and TypeScript, focusing on automated deployment processes, Git hooks, and using hard links to copy changes. The speaker demonstrates setting up a bare repository, configuring deployment variables, and using the post-receive hook to push changes to production. They also cover environment setup, branch configuration, and the build process. The Talk concludes with tips on real use cases, webhooks, and wrapping the deployment process.

1. Introduction to Atomic Deployment

Short description:

We're going to talk about atomic deployment for JavaScript and TypeScript Hipsters. In an atomic deployment, you take two versions of an existing application and deploy the changes between them. It's self-contained and eliminates the need to worry about dependencies and building. The goal is to have a functional, workable, and compatible solution with a simple developer experience.

Hi, folks. Welcome to this talk for us, DevOps JS Conference. We're going to talk about atomic deployment for JavaScript and TypeScript Hipsters.

Right before starting, a little bit of information about what atomic deployment and immutable deployment are. In an atomic deployment, you take two versions of an existing application and you're just deploying the changes between these two versions, but everything is self-contained. So you can take a whole archive of version at any point of time and everything is self-contained and you don't have to worry about anything about that. This is what makes Netlify so successful in the past because suddenly you just had to push a branch on your version server like GitHub or whatever, and it was automatically deployed on your production server in a staging URL like mybranch slash myapp.mydomain.com.

So it's really powerful because you just have to push some changes in any kind of branch, you automatically have a lot of previews directly accessible. And each time you update your branch like updating your PR, the preview updates itself as the same way. So it's definitely useful, especially when deployment is a painful process when you have to worry about dependencies and building and so on. So what is the hipster ways to do these kind of atomic or immutable deployments?

My idea is that I want to keep it working. I want to stick to this principles of atomic and immutable deployments. I want it to be functional, workable, and compatible with any hosting provider, whichever it was. And I want to stick to the simple developer experience. Like, I just want to push my branch and my preview is automatically deployed or updated, and that's all. And I don't care about how to use it and how to work with it and so on. So what are the expected features on these ones specifically?

So I want it to be configurable because I don't want to revamp the whole process for each project. I want to have some things that is easily deployable to any kind of repository and where I just have to tweak a few variables to configure it for this very specific project at a time. I want it to be band-lasting compatible, so working on any kind of hosting provider in the wild. I want some kind of micro-CI integrated like deployment dependencies and building and so on. Everything handled by the solution by itself. So I don't have to worry about anything about that. But without the tests you eat and so on, it doesn't care. I want no too minimal downtime on deployment to keep it really working. So I don't want to break something on the production just because I pushed a brand that suddenly didn't build or something else. So I want some kind of safeguards at some points to be sure that nothing can be down at some point. And I want it to be auto-publishable. So I just want to push it in a branch and boom, my branches, my preview associated to my branch is automatically updated. So I'm Matt, folks. I'm a developer experience engineer at Always Data, which is a hosting provider, an independent one.

2. Setting Up Automated Deployment

Short description:

I will show you the foundation of our automated deployment process with atomic and immutable deployment features. We will work on the server, have the web hosts and repositories in the same place, and rely on SSH remote access. I'll initialize a bare repository and link it to a new application.

So my responsibility at Always Data is working on the developer experience, most specifically on the CLI and the tools associated with the platform itself. What I will show you is the foundation of our automated deployment process with atomic and immutable deployment features. It's currently in development in CLI, but it will be available soon. I'm excited to share it with you because it's the result of my search. Let's dive into the code to see it in action.

For this talk, we will work on the server, whether it's a container, VPS, or bare metal. The idea is to have the web hosts and repositories responsible for atomic deployment in the same place. We will rely heavily on SSH remote access. Webhooks are not part of this talk, but I'll briefly mention them in the conclusion.

To get started, I'll SSH directly onto the server in my container with my hosting account. I'll ensure that I'm in the /var folder, where the www folder is located. This is the document root for our web server engine. I'll initialize a bare repository in /var/repo. A bare repository contains only the Git elements and not the source code itself. Back on my local computer, I'll create a new application and link it to the repository in the container using SSH.