npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nginx-0dtdeploy

v1.0.1

Published

This is a really simple script that covers the load balance switch for zero downtime deployments. It's designed to run on a server that load balance docker images with Nginx

Downloads

7

Readme

Nginx-0dtdeploy

TL;DR

This is a really simple script that covers the load balance switch for zero downtime deployments. It's designed to run on a server that load balance docker images with Nginx.

Configuration setup

In your nginx.conf you'll have to outsource the upstreams to a own file.

upstream backend {
	include /etc/nginx/upstreams/example.net.upstream.conf;
}
server {
    listen 192.168.0.10:443;
    server_name example.net;
    # SSL config
    # ....
    # SSL End
    location / {
        proxy_read_timeout 300;
        proxy_connect_timeout 300;
        proxy_pass http://backend;
    }
}

Command reference

The script will not tell you about these switches, so this is the only reference to them for now.

-f      Sets the upstreams.conf path.
-h      Hosts to enable. Syntax: localhost:8080
-c      Check the Nginx config (it will run nginx -t)
-r      Reload the Nginx config (it will run nginx -s reload)

Real usage example

Say you got two containers running your app, for load balancing. And your upstreams.conf has both of them configured.

Say that your environment looks like this:

# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                       NAMES
0ebfa6e3b8e1        ghost               "/entrypoint.sh npm s"   4 seconds ago       Up 2 seconds        0.0.0.0:8081->2368/tcp                      prod_ghost2
2c01b7916a9d        ghost               "/entrypoint.sh npm s"   21 seconds ago      Up 18 seconds       0.0.0.0:8080->2368/tcp                      prod_ghost1

upstreams.conf:

server localhost:8080;
server localhost:8081;

simple_deploy.sh:

#!/bin/bash

export CONTAINER_NAME1=prod_ghost1
export CONTAINER_NAME2=prod_ghost2
export CONTAINER_PORT1=8080
export CONTAINER_PORT2=8081

# Pull the latest image
docker pull ghost

# Disable prod_ghost1 and keeps prod_ghost2 in the file
nginx-0dtdeploy -f /etc/nginx/upstreams/example.net.upstream.conf -h localhost:$CONTAINER_PORT2 -c -r

# Stop and delete prod_ghost1
docker stop $CONTAINER_NAME1
docker rm $CONTAINER_NAME1
# Start a fresh container to replace prod_ghost1
docker run --name $CONTAINER_NAME1 -p $CONTAINER_PORT1:2368 -v /dockerdata/test:/var/lib/ghost -d ghost

# Enable prod_ghost1 and disable prod_ghost2
nginx-0dtdeploy -f /etc/nginx/upstreams/example.net.upstream.conf -h localhost:$CONTAINER_PORT1 -c -r

# Stop and delete prod_ghost2
docker stop $CONTAINER_NAME2
docker rm $CONTAINER_NAME2
# Start a fresh container to replace prod_ghost2
docker run --name $CONTAINER_NAME2 -p $CONTAINER_PORT2:2368 -v /dockerdata/test:/var/lib/ghost -d ghost

# Enable prod_ghost1 and prod_ghost2 again
nginx-0dtdeploy -f /etc/nginx/upstreams/example.net.upstream.conf -h localhost:$CONTAINER_PORT1 -h localhost:$CONTAINER_PORT2 -c -r