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:
-
Ensure that Node version >= v18.x.x and < v19 is installed
-
Ensure that git is installed
-
Clone the relativepath.tech repository
-
npm install the dependencies for the site
-
npm run build the static assets for the site
-
Ensure that the site works
-
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
node command for direct HTTP server invocation for production
- Implementation of absolute paths using
pushd and popd
- Any other suggestions
deploy.shDeployment 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.shscript 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:
Ensure that Node version >= v18.x.x and < v19 is installed
Ensure that git is installed
Clone the relativepath.tech repository
npm installthe dependencies for the sitenpm run buildthe static assets for the siteEnsure that the site works
Deploy the site
First iteration minimum viable
deploy.shThe first draft of this
deploy.shscript is: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
nodecommand for direct HTTP server invocation for productionpushdandpopd