Skip to main content
Version: 4.7

Building a LAMP stack Application using Azure DevOps Custom Respository & Custom Agents: A Step-by-Step Guide

getting-started
This comprehensive guide provides step-by-step instructions for creating a custom pipeline to build a LAMP stack application using Linux, Apache, MySQL, and PHP (LAMP) within our SCALE DevOps platform. This guide covers the entire process, from setting up the environment to deploying the application.

Getting Started

Step 1: Register Your Application

  1. Go to Enterprise Service Portal within ServiceNow
  2. Click Service Catalog
  3. Search for "Application Registration"
  4. Fill in the details and click Submit. You will receive an email confirmation with a three-letter app code

Step 2: Onboard Your Application

  1. Navigate to NetApp ServiceNow DevOps
  2. Click Onboard Application in CloudOne DevOps to begin the onboarding process

This process kicks off a series of automation steps, typically taking 40-45 minutes, after which you will receive an email with links to:

  • Azure DevOps Project
  • SelfAssist Portal
  • Rancher environment
  • NEAT, JFrog Artifactory, and StorageGrid

Step 3: Setting Up Your Development Environment

  1. Go to Azure DevOps Org and choose your project (e.g., "hts-workspace")
  2. Navigate to Repos and create a new custom repo by selecting the option + New repository
  3. Name the repo as custom-lamp-stack
  4. Create a new branch feature/test, clone it locally, and make necessary changes.

Step 4: Building the Docker Image

The next step involves creating a Custom Docker Image that contains all the necessary tools and packages required to build and run the LAMP stack application. This Custom Container will be used to execute all pipeline tasks within Custom Agent Pool.

Dockerfile for Custom Docker Image

The Dockerfile for building custom Container begins with pulling Debian as the base image and includes the following steps:

  • Install essential packages such as wget, packages required to call HTTPS, and common CA certificates
  • Install Docker components including docker-ce, docker-ce-cli, and containerd
  • Ensure the Docker group exists and adds the current user to docker group
  1. Commit and push the changes to remote
  2. Run the pipeline azure-pipelines-builder-runner.yml

Step 5: Building the LAMP Stack Application

The Appication will have PHP running on an Apache Linux-based container. This front-end service will talk to a MySQL DB that runs as a separate container.

Dockerfile for PHP App

The Dockerfile for building PHP application begins with pulling php:apache as its base image and includes the following important steps:

  • Install necessary packages such as zip, unzip, and mysqli
  • Install Composer, a dependency manager for PHP, and use it to install PHP dependencies listed in composer.json
  • Update the port configuration from 80 to 8080
  • Expose port 8080.

Dockerfile for MySQL

The Dockerfile for the MySQL service includes the following steps:

  • Pull the MySQL base image
  • Execute database initialization scripts to create a database, a table, and insert some data into the Users table
  • Expose the MySQL service on port 3306

Application

The application is a basic "Hello World" application built using the LAMP stack (Linux, Apache, MySQL, PHP). It connects to a MySQL database, retrieves data from a database table, and displays the results on the user interface.

The azure-pipelines.yml file includes the following configurations:

  • Specify the Pool as Custom
  • Point to the container image created in the previous step
  • Define two tasks to create the PHP and MySQL Docker images
  • Push the images to JFrog Artifactory and tag them
  1. Commit and push the changes to remote
  2. Run the pipeline azure-pipelines.yml

Step 6: Deploying the Application

Use CAAS pipeline offering to deploy the front-end and back-end images to SCALE Kubernetes platform.

Ordering CAAS pipelines and Hostspaces

  1. Go to ServiceNow DevOps.
  2. Click Manage CloudOne DevOps Application.
  3. Search for your three-letter APP CODE and order:
    • CAAS for front-end (caaslampapi) and back-end (caaslampdb)
    • Hostspaces (lamphst and mysqlhst)

Step 7: Configuration changes for Stateful Applications

Since CAAS is built to deploy stateless applications, deploying MySQL requires some tweaks:

  1. Replace deployment.yml with statefulset.yml
  2. Add secrets.yml for handling environment variables
  3. Update values.workspace.yml and values.hostspace.yml

Note

Before proceeding with the changes, please note that this repository serves as a baseline for deploying MySQL. If you intend to deploy other open source databases through CAAS, additional changes may be necessary. It is recommended to collaborate with one of the SCALE team members for the required assistance.

Step 8: Managing Secrets with Azure DevOps Variable Groups

  1. Create a Variable Group lampstackdb-vars with DB connection details(Check Self Assist Documentation for more details)
  2. Within caas-lampstack-api repo,update azure-pipelines.yml and values.hostspace.yaml to reference Azure Variable Group variables

azure-pipelines.yml

variableGroups:
- lampstackdb-vars
secretVarKeys:
- mysqlServiceName
- mysqlUserName
- mysqlPassword
- mysqlDatabaseName

values.hostspace.yaml

DB_HOST: "$mysqlServiceName"
DB_USERNAME: "$mysqlUserName"
DB_PASSWORD: "$mysqlPassword"
DB_NAME: "$mysqlDatabaseName"
  1. Within custom-lamp-stack repo,update the application source code to reference above envirornment variables

Update index.php to use environment variables:

$dbHost = getenv('DB_HOST') ?: 'mysql-container';
$dbUser = getenv('DB_USERNAME') ?: 'root';
$dbPassword = getenv('DB_PASSWORD') ?: 'rootpassword';
$dbName = getenv('DB_NAME') ?: 'testdb';

Step 9: Running the CAAS Pipelines

Run the CAAS pipelines and verify your application is running.

Finalizing Deployment

Step 9: Deploying to Hostspace

  1. Modify azure-pipelines.yml within caas-lampstackapi to comment out the workspace section and enable the hostspace section.
      acceptanceSpace: hts-lamphst-dnt
spaces:
# workspace:
# helm:
# overrideFiles: hts-lampstackapi/values.workspace.yaml
hts-lamphst-dnt:
variableGroups:
- lampstackdb-vars
secretVarKeys:
- mysqlServiceName
- mysqlUserName
- mysqlPassword
- mysqlDatabaseName
helm:
overrideFiles: |
hts-lampstackapi/values.hostspace.yaml
  1. Commit the changes and push to remote.
  2. Run the CAAS pipelines and verify that the application is accessible via the kong ingress URL.

Step 10: Custom Domain Setup

  1. Register a custom domain
    1. Navigate to NetApp ServiceNow DevOps.
    2. Click Manage CloudOne DevOps Application.
    3. Search for your three-letter APP CODE.
    4. Click DNS as a Service and enter your preferred domain name to get the DNS Record created
  2. Update values.hostspace.yaml
- host: lampstackdemoapp.netapp.com
  1. Commit your changes and push to remote.
  2. Run the pipeline and verify that the application is accessible via the custom URL.

Need Assistance?

If you encounter any issues or require support, don't hesitate to reach out to one of the SCALE team members. We're here to help!