Using Docker-compose

Standard
Reading Time: < 1 minute

Commands for docker-compose

You will need a YAML file that contains your stack.

Stack file

A little more complex example: https://gist.github.com/mfung/9b0fd65ccc793c7b1ec44dfb2deb370d

Install & Using Docker (OSX, CoreOS, Docker-CM, Alpine Linux, Docker-Compose)

Standard
Reading Time: 2 minutes
I recently decided to consolidate some of my websites onto one server. I also wanted to https (SSL) most if not all my websites. Before I would use CentOS or Ubuntu and Nginx as a reverse proxy with Nginx/Passenger serving my Rails apps and Apache/PHP serving my WordPress/PHP sites. Here’s how I installed docker, docker-cm and started using containers on my production servers.

I’ve known about Docker and I’ve used it indirectly, a Rails app i worked on used it in production but it was abstracted from us software engineers. So I installed Docker-CM on both CentOS, Ubuntu, and Docker on OSX to experiment.

OSX: https://docs.docker.com/docker-for-mac/install/

 

After spinning up some containers and learning some Docker commands.

Docker Commands

 

I started to research minimalist Linux distros for the host OS. I only need to be able to run Docker-CM, maybe a firewall, and some other minimal software on it because the heavy lifting would be done in each of the containers. While doing that I learned about Alpine Linux for the container image. I was using CentOS and Ubuntu images at first and while looking at host images and file sizes I realized I can be more efficient with the containers as well.

Docker Images

REPOSITORY TAG SIZE (MB)
alpine latest 4.15
centos latest 207.0
ubuntu latest 111.0
busybox latest 1.14

Now why I didn’t use BusyBox instead of Alpine. I just found alpine and apk easy and familiar. And their motto is “Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busy box.” I like security, I like lightweight, and I like Linux.

With all this playing around and researching, I found docker-compose and read up on creating a Dockerfile. I also ran across some important images:

postgres:10.1-alpine
nginx:alpine
jrcs/letsencrypt-nginx-proxy-companion
jwilder/docker-gen
WordPress (there are different flavors of alpine, apache, and different versions of PHP)

What I wanted in my ecosystem is Postgres (Phoenix, Rails, and my goto DB), MySQL (for my WordPress sites), Redis, MongoDB + R, Nginx Proxy, Apache Virtual Hosting not just 1 instance of WordPress per container.

Next

Setup Jenkins and BitBucket without plugins

Standard
Reading Time: < 1 minute
Standard

This was pretty straight forward since BitBucket has hooks ready for Jenkins.

I usually create 2 Jenkins projects, 1 to build and 1 to deploy.

Jenkins Server

Make sure you have a Jenkins user that can Read Overall and Read Job. I use “Project-based Matrix Authorization Strategy” you can find that under “Configure Global Security”

So I have a user called automated-user and it has Read Overall and Read Job checked. It also has an API Token you will need that you will find here: Jenkins >> Manage Jenkins >> Manage Users >> Select your user, in my case ‘automated-user’ >> Configure >> “Show API Token”. I get eadefe23232121232sdasdfadf as an example.

Build Project

Give the project a name: project-name-build
Source Code Management: Select “Git Repositories” >> Repository URL = https://username@bitbucket.org/username/git-repo.git >> Add credentials & Select it.
Build Triggers: Check, “Trigger builds remotely (e.g., from scripts)” >> Authenticated Token, enter a token SecureRandom.urlsafe_base64 works well for this. Lets say we got this: wtOhS3d4TV1MRX_bVn_lAA

Deploy Project

Source Code Management: Select “Git Repositories” >> Repository URL = https://username@bitbucket.org/username/git-repo.git >> Add credentials & Select it.
Build Triggers: Check, “Build after other projects are built”

BitBucket

Go to: Your Repo >> Settings >> Hooks >> Select Jenkins

Enter: 
Endpoint: http://automated-user:eadefe23232121232sdasdfadf@ci-server-address.com
Project Name: project-name-build
Token: wtOhS3d4TV1MRX_bVn_lAA

Save.

You should be good to go minus some settings you’ll need to configure based on your needs.

Learn how to use top command in linux

Standard
Reading Time: < 1 minute

I find myself using this often while debugging errors or trying to figure why a server is slow or unresponsive.

 

Vagrant Boxes / VMWare Fusion / CentOS 7

Standard
Reading Time: 4 minutes

Use one found here: http://www.vagrantbox.es you can use one of those to build upon or you can create one.

These steps are if you want to to create a fresh box.
Grab the latest CentOS image here:
http://www.centos.org/download/

I use the minimal image http://ftp.usf.edu/pub/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-Minimal.iso

First you need to create a VM using Fusion.

  1. Select “Install from disc or image” >> Continue
  2. “Use another disc or disc image” >> Find your iso >> Continue
  3. Uncheck “Use Easy Install” make sure “Make your home folder accessible to the virtual machine is unchecked. >> Continue
  4. Click “Customize Settings” >> Rename your vm and place it somewhere safe.

Continue reading

Nginx / Comodo PositiveSSL / CentOS 7

Standard
Reading Time: < 1 minute

1. Before you purchase your SSL

Before any purchase of an SSL you’ll need a key file and a csr (Certificate Signing Request).

The certificate registrar is going to ask for the contents of your csr file, just cut and paste whats inside the file into the webform. Make sure you register with the domain name you plan on using. Purchase your SSL, they’ll send your administrator an email validate that. Then wait for an email from Comodo with a zip file.

Within this zip file you’ll receive 4 files:

  • AddTrustExternalCARoot.crt – Root Cert
  • COMODORSAAddTrustCA.crt – Intermediate Cert
  • COMODORSADomainValidationSecureServerCA.crt – Intermediate Cert
  • server_name.crt – Your Positive Cert

2. Prep for installing SSL Cert

3. Installing the SSL Certificate

Now to configure Nginx.

4. Restart Nginx

To test your ssl: https://www.ssllabs.com/ssltest/

Jenkins 1.59 / CentOS 7 / GitHub / Rails / RSpec / Rbenv

Standard
Reading Time: 2 minutes

As this is for personal use the system I configured has 1 64bit CPU, 1GB of RAM, and 30GB SSD HDD (the $10/mo DigitalOcean plan). I first tried it with the $5 plan, that kept giving me memory issues as Jenkins/Hudson runs on a JavaVM so for my needs 1GB of ram was needed. I won’t be running multiple builds with multiple nodes, pretty much whenever I push code to GitHub/BitBucket I want Jenkins to build and deploy code. If I push to master and it passes deploy to production, If I push to development and it passes deploy to staging.

My setup: 1 VM production server, 1 Physical staging server (in my office), 1 JenkinsCI VM server, and numerous repositories on GitHub and BitBucket.

Setting up Jenkins on CentOS 7

Setup for Rails / Rbenv

Adding EPEL to CentOS 7

Standard
Reading Time: < 1 minute

 

CentOS 7 and PostgreSQL 9.3

Standard
Reading Time: < 1 minute

Process to install and initialize.