Jenkins Deployment Setup

From Origami_Wiki
Jump to navigation Jump to search

Purpose[edit]

This document describes how to configure Jenkins to deploy a Laravel application to a server using SSH, GitHub, and a Jenkins Pipeline.

Architecture Overview[edit]

GitHub (Repository)

       |
       |  Webhook
       v

Jenkins Pipeline Job

       |
       |  SSH
       v

Application Server (deploy user)

1. Server Preparation[edit]

1.1 Create Deploy User (Application Server)[edit]

Important: Never deploy using root. sudo adduser deploy sudo usermod -aG www-data deploy 1.2 Directory Ownership & Permissions sudo mkdir -p /opt/ksrtc_sandbox sudo chown -R deploy:www-data /opt/ksrtc_sandbox sudo chmod -R 775 /opt/ksrtc_sandbox


Laravel required writable directories:

sudo chown -R deploy:www-data storage bootstrap/cache sudo chmod -R 775 storage bootstrap/cache

1.3 Install Required Software sudo apt update sudo apt install -y git unzip


Install Composer:

curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer

2. Jenkins Server Preparation 2.1 Verify Jenkins User ps -ef | grep jenkins


Jenkins runs as:

jenkins

3. SSH Key Setup 3.1 Generate SSH Key for Jenkins sudo su - jenkins cd ~/.ssh ssh-keygen -t rsa -b 4096 -m PEM -f git-ssh-ksrtc-deploy


Generated files:

git-ssh-ksrtc-deploy (private key) git-ssh-ksrtc-deploy.pub (public key)

3.2 Add Public Key to Application Server su - deploy mkdir -p ~/.ssh nano ~/.ssh/authorized_keys


Paste the contents of:

git-ssh-ksrtc-deploy.pub


Set permissions:

chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys

3.3 Add Public Key to GitHub

GitHub → Repository Settings → Deploy Keys

Paste git-ssh-ksrtc-deploy.pub

Enable Read access

4. Jenkins Credentials Configuration

Jenkins → Manage Jenkins → Credentials → Global

Create credential:

Kind: SSH Username with private key

ID: git-ssh-ksrtc-deploy

Username: deploy

Private Key: Paste full private key

Save

5. Jenkins Job Creation 5.1 Create Pipeline Job

Jenkins Dashboard → New Item

Name: KSRTC-Ads

Type: Pipeline

Click OK

5.2 Job Configuration General

Enable Discard old builds (optional)

Disable Concurrent builds

5.3 GitHub Project

Enable GitHub Project and set:

git@github.com:origamitechnologies/ksrtc_bus_ad_platform_laravel.git

5.4 Triggers

Enable:

GitHub hook trigger for GITScm polling