Skip to content

RFC Proposal for deploy.sh curl bash deployment script (Ubuntu VM Target) #6

Description

@christopherkeim

deploy.sh Deployment Script (Ubuntu VM Target)

Purpose

The purpose of this RFC proposal is discussion of requirements and any suggestions that can be made for design and development.

Concept

To build out more scalable DevOps infrastructure for ourselves we'll need a deploy.sh script that can be used to install and deploy our site onto a machine in a fully automated, non-interactive way. The design framework should be idempotent. For the moment we are explicitly targeting a Ubuntu VM as our deploy target.

This script should:

  1. Ensure that Node version >= v18.x.x and < v19 is installed

  2. Ensure that git is installed

  3. Clone the relativepath.tech repository

  4. npm install the dependencies for the site

  5. npm run build the static assets for the site

  6. Ensure that the site works

  7. Deploy the site

First iteration minimum viable deploy.sh

The first draft of this deploy.sh script is:

#! /bin/bash

# This script deploys the site onto a Ubuntu machine

# Check if Node.js is in the apt-cache
if (apt-cache show nodejs > /dev/null)
then
  echo "nodejs is already in cache"
else
  sudo apt update
fi

# Install Node.js runtime environment
if [[ $(node --version | cut -d "v" -f2 | cut -d "." -f1) == 18 ]]
then
  echo "Node >= v18.x.x is installed."
else
  echo "Installing Node v18.x.x"
  curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
  sudo apt install -y nodejs
fi

# Check if git is in the apt-cache
if (apt-cache show git > /dev/null)
then
  echo "git is already in cache"
else
  sudo apt update
fi

# Install git
if $(git --version > /dev/null)
then
  echo "git is installed"
else
  echo "Installing git..."
  sudo apt install -y git
fi

# Clone the repository
if [ -d ./relativepath.tech ]
then
  echo "Repository is already cloned."
else
  echo "Cloning relativepath.tech..."
  git clone https://github.com/kensonjohnson/relativepath.tech.git
  cd ./relativepath.tech
fi

# Move into the local repo and install depedencies
if (pwd | grep relativepath.tech > /dev/null)
then
  echo "Already in relativepath.tech"
else
  cd ./relativepath.tech
fi

# npm install will check if requirements have been installed, if so do nothing, 
# and if not install them
npm install

# npm run build will build our the site's static assets
npm run build

# Test that our server is able to run
if [ $(curl -o /dev/null -s -w "%{http_code}" http://localhost:4173/ | grep 200) ]
then
  echo "Looking great! Fire up your browser and head over to http://localhost:4173"
else
  echo "Testing our site." 
  npm run preview & \
    sleep 5 && \
    sh -c "curl -o /dev/null -s -w "%{http_code}" http://localhost:4173/ | grep 200"
fi

# Deploy the server [NODE HTTP SERVER GOES HERE - not implemented yet]
npm run preview

This can also be viewed at https://github.com/kensonjohnson/relativepath.tech/blob/chris/deploy/deploy.sh

Usage

This script could be used to curl bash deploy our site onto a machine:

curl -fsSL https://raw.githubusercontent.com/kensonjohnson/relativepath.tech/chris/deploy/deploy.sh | bash -

In Progress

  1. node command for direct HTTP server invocation for production
  2. Implementation of absolute paths using pushd and popd
  3. Any other suggestions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions