How to Setup CI/CD of Jigsaw Site to Digital Ocean Droplet Using Bitbucket Pipelines
I created a new personal resume site and decided I wanted to build a static site since it wouldn’t be frequently updated. I evaluated Nuxt, Gatsby, and a few others but settled on Jigsaw, a static site generator based on Laravel. I had never used it before and figured this would be a good learning experience while building something I needed. I was pleasantly surprised by how easy it is to use and setup, so kudos to the Tighten team for putting together such an elegant solution.
I wanted to get a CI/CD pipeline configured to handle the site’s deployment but couldn’t find any working tutorials, so I’m sharing my solution in case it helps others. I’m using Bitbucket for this since it’s a personal private repo, so I’m using Bitbucket Pipelines.
Instructions
After you enable pipelines for your project, you’ll need to configure a Pipelines Repository Variable in your project. Go to the settings tab in your repo, and then select Repository variables:
Add 3 variables:
- USER_NAME – The SSH user name you want Bitbucket to use to connect to your server.
- PRODUCTION_HOST – Your domain that Bitbucket should connect to
- FOLDER – Folder Path where the site should be deployed to
Generate an SSH key (or use your own) and add it to your server under the SSH Keys tab in Pipelines:
I generated a new key and then added it to ~/.ssh/authorized_keys for the account.
Add this YAML snippet to your bitbucket-pipelines.yml in your root. This will use PHP 7.4, install rsync, node + npm, composer, and build the production version of the site to deploy to the specified folder.
The -aVP switch for rsync is to give me verbose progress feedback so I can see what’s happening. If you don’t need the detail, switch it to -a.
image: php:7.4-fpm
pipelines:
branches:
master:
- step:
name: Jigsaw Build
script:
- apt-get update && apt-get install -y unzip
- apt-get install rsync openssh-client nodejs npm -y
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- composer install
- npm install
- npm run production
- rsync -avP build_production/ $USER_NAME@$PRODUCTION_HOST:$FOLDER --exclude=bitbucket-pipelines.yml --chown=www-data:www-data
I received a few errors when rsync ran. In case you run into them as well, here’s the list and fixes. The first was:
rsync: failed to set times on "$FOLDER": Operation not permitted (1)
I added --no-t
to resolve that and then got a new error:
rsync: failed to set permissions on "$FOLDER": Operation not permitted (1)
which was fixed with adding the switch --no-perms
. My final rsync command became:
rsync -avP --no-t --no-perms build_production/ $USER_NAME@$PRODUCTION_HOST:$FOLDER --exclude=bitbucket-pipelines.yml --chown=www-data:www-data
One-line snippet to update linux and apps on Ubuntu using apt-get
I find myself using this command on Digitalocean droplets fairly often and am sharing in case anyone else finds it useful. Use this one line to install all updates, security fixes, and system upgrades.
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
How to stop CouchDB on Mac OS
I have been working on a proof of concept using CouchDB. After getting the proof of concept working, I spun up a digital ocean droplet and proceeded to setup CouchDB on the server. I went to enable the SSH tunnel so I could access the CouchDB Futon instance and promptly ran into an error because my local instance of CouchDB was using the same port, 5984. I had a lot of trouble finding out an easy way to stop CouchDB because the documentation in the Wiki wasn’t accurate:
sudo launchctl unload \ /usr/local/Library/LaunchDaemons/org.apache.couchdb.plist
As a workaround, in Terminal, run
launchctl list | grep couchdb
This will output something like:
99093 0 org.apache.couchdb.288008
Grab the highlighted portion and run
launchctl stop "org.apache.couchdb.288008"
Substitute the process name accordingly and you should be able to run the ‘launchctl list’ command again and see the process is no longer present.
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80 – error
IÂ recently got handed a new Ubuntu droplet at work to setup and work on. I was going through the typical configuration to lock down the server and go to installing Apache when I suddenly ran into the error
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80 – error
I was a little surprised considering I had only run 4 commands total on a brand new installation. If you’re getting this error like me, you’ll need to find out what’s being bound to port 80 and then stop it. Use this command to get a list of anything that’s running on port 80.
sudo lsof -i:80
For me, it turned out nginx was running and bound to port 80. If you have the same problem, run this command to stop it:
sudo service nginx stop
Now you should be able to start apache.
How to Copy and Paste into the Digital Ocean VNC Console
I recently signed up for Digital Ocean to test droplets for my development and linux management testing. I was securing the server and setup fail2ban, disabled the root login, and created a user account but forgot to change the user name from root to the user name I selected in my SSH client profile. I ended up locking myself out of the server and had to resort to logging into the admin panel on Digital Ocean’s website and use their browser embedded VNC client to restore my access. I quickly discovered that one of the downsides of using this panel is that you can’t copy and paste commands. Luckily there’s a workaround and you can use the browser console to do sendkeys through Javascript.
Bring up the console in the browser developer tools. Here’s a cheat sheet for keyboard shortcuts:
Browser | Description | Windows | Mac |
---|---|---|---|
Chrome | Open Developer Tools and bring focus to the console | Ctrl + Shift + J | Cmd + Opt + J |
Firefox | Open Console | Ctrl + Shift + K | Cmd + Opt + K |
Internet Explorer | After hitting F12, you have to click the console tab. There’s no direct shortcut to the console tab. | F12 | N/A |
!function(){function t(){window.rfb.sendKey(e.shift().charCodeAt()),e.length>0&&setTimeout(t,10)}var e=prompt("Enter text to be sent to console").split("");t()}();
Update 9-21-16
Ruden and Sebastiaan’s pointed out there was a bug in the code above. This updated snippet has support for characters when using shift characters like !@#$%^&*()_+
!function(){function t(){function n(t,e){s=s.concat(RFB.messages.keyEvent(t,e))}var o=e.shift(),s=[],i=o.charCodeAt(),c=-1!=='!@#$%^&*()_+{}:"<>?~|'.indexOf(o),r=XK_Shift_L;c&&n(r,1),n(i,1),n(i,0),c&&n(r,0),rfb._sock.send(s),e.length>0&&setTimeout(t,10)}var e=prompt("Enter text to be sent to console").split("");t()}();
You’ll receive a dialog prompt to enter the copy to paste in. Please note that you need to click on the VNC console and hit enter to execute the command.
If you need to enter more than one command, just hit the up arrow on your keyboard in the console to get the script again for easy reuse.