Moving to Sculpin post

Preamble

A long while (5 years!) ago I wrote about moving my blog from a database backend to flatfiles and some php libs for parsing.

Well I was bored this last weekend and decided to work on modernizing that toolchain a bit, only to find Sculpin, which did it all and more without being a pile of bloat.

So I set my sights on the great migration from outdated crap > fancy static site builder, and cloned the Scuplin Blog Skeleton

Moving posts

I had been storing all of my posts in markdown, so all I had to do here is convert the filenames from my format to Sculpins

ours: 1476265410][New Blog System.md theirs: 2016-10-12-New-Blog-System.md

# PowerShell

# iterate markdown files
gci *.md | %{
    # split filename by ']['
    $fInfo = $_.Name.split("][");
    # get the first half, timestamp
    $oldTimestamp = $fInfo[0];
    # convert to Y-M-D
    $newTimeStamp = ((Convert-FromUnixDate -UnixDate $oldTimestamp).ToString("yyyy-MM-dd"));
    # Rename
    move-item -LiteralPath "$($_.FullName)" "$($_.FullName.Replace("$oldTimestamp][","$newTimeStamp-"))".Replace(" ","-");
}

Moving Theme

I wasn't using any external CSS so this was easy enough.

To begin with I just ripped all the Bootstrap and jQuery references from the skeleton project, and updated the js and css files with the contents of my old site. Similar deal for the default template.

Deployment

I wanted this to be simple, I just want a merge to master = deploy to production, and for this I chose GitLab.

GitLab supports YAML based CI/CD, so this too was pretty simple. I managed to cobble a working deploy script after a couple of hours, you can view it in the repo but I have a pretty generic outline of the steps below.

  1. First I had to set up the deployment credentials (FTP in this case), and have them stored somewhere safe.
    • for a simple project, we can just use GitLab variables
      • https://docs.gitlab.com/ee/ci/variables/README.html
    • we can then access these variables during the CI/CD process
  2. I then added a composer script entry called 'build-production'
    • runs yarn to build webpack assets
    • runs sculpin to generate the static site itself
  3. One more composer script: 'deploy-production'
    • runs composer package dg/ftp-deployment which uses the native PHP FTP libary 'ext-ftp' to manage deployments
    • this step also requires configuration file (deployment.ini)
  4. Finally to tie this together, you just need valid credentials in the deployment.ini file
    • During a pipeline, the variables we saved earlier are exposed as environment variables
    • Now we can use a simple bash command to update the placeholders in our deployment file
    • i.e. find deployment.ini -type f -exec sed -i "s/DEPLOYMENT_FTP_SERVER/$DEPLOYMENT_FTP_SERVER/g" {} \;

Now we have our full deployment steps:

# Install composer packages
composer install
# Run composer script 'build-production'
composer build-production
# Create ftp-deployment project
composer create-project dg/ftp-deployment
# Update deployment placeholders
find deployment.ini -type f -exec sed -i "s/DEPLOYMENT_FTP_SERVER/$DEPLOYMENT_FTP_SERVER/g" {} \;
find deployment.ini -type f -exec sed -i "s/DEPLOYMENT_FTP_USER/$DEPLOYMENT_FTP_USER/g" {} \;
find deployment.ini -type f -exec sed -i "s/DEPLOYMENT_FTP_PASSWORD/$DEPLOYMENT_FTP_PASSWORD/g" {} \;
# Run composer script 'deploy-production'
composer deploy-production

Summary

I'm pretty happy with how this all turned out, I have less excuses not to post here now :D

Thanks!

Categories: ancient

Tags: php, webdev