Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
docker-data
*.tar
ansible
sonar-project.properties
.git
docker-compose.yml
.env
vendor
15 changes: 9 additions & 6 deletions .env.example → .env.local
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
APP_ENV=local
APP_ENV=testlaravel
APP_DEBUG=true
APP_KEY=SomeRandomString
APP_KEY=base64:oPD/hrRXGvA1hydZp17JAQH2PnflMgp4P5OMWoldWTM=

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_HOST=db
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=your_mysql_root_password

CACHE_DRIVER=file
SESSION_DRIVER=file
Expand All @@ -21,3 +21,6 @@ MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

JAEGER_HOST: jaeger
JAEGER_PORT: 6831
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Homestead.yaml
Homestead.json
.env
public/images
storage/
.DS_Store
docker-data
67 changes: 67 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
FROM php:7.2-fpm

# Set working directory
WORKDIR /var/www

# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
mysql-client \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
libgmp-dev

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

## Opencensus
RUN pecl install opencensus-alpha

RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/

# Install extensions
RUN docker-php-ext-install pdo_mysql \
mbstring \
zip \
exif \
pcntl \
gd \
sockets \
gmp

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www

# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/

RUN composer install --prefer-source --no-dev --no-autoloader --no-scripts --no-progress --no-suggest

# Copy existing application directory contents
COPY . /var/www

RUN composer install --prefer-dist --no-dev -o

# Copy existing application directory permissions
COPY --chown=www:www . /var/www

ADD ./docker/php/local.ini /usr/local/etc/php/conf.d

# Change current user to www
USER www

# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
170 changes: 170 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
def getdockertag(){
return "${env.GIT_BRANCH}".replace("/",".") + "."+"${env.BUILD_ID}"
}
pipeline {
agent any
environment {
DOCKER_REGISTRY = "varunpalekar1/php-test"
DOCKER_TAG = getdockertag()
}
stages {
stage('Build') {
steps {
script {
echo "install compose.json"
sh 'composer install --prefer-source'
sh 'printenv'
dir('ansible') {
sh 'ansible-galaxy install -r requirements.yml'
}
}
}
}
stage('UnitTest') {
environment {
DB_HOST = "localhost"
DB_DATABASE = "laravel_test"
DB_USERNAME = "laravel_test"
DB_PASSWORD = "my_pass"
}
steps {
script {
try{
echo "Running Test cases"
sh './vendor/bin/phpunit --colors tests --log-junit reports/junit.xml'
}
catch(Exception e){
if ( GIT_BRANCH ==~ /.*master|.*hotfix\/.*|.*release\/.*/ )
error "Test case failed"
else
echo "Skipped test if from personal or feature branch"
}
try{
echo "Running Test code coverage"
sh './vendor/bin/phpunit --coverage-clover reports/codeCoverage.xml'
}
catch(Exception e){
if ( GIT_BRANCH ==~ /.*master|.*hotfix\/.*|.*release\/.*/ )
error "Code coverage failed"
else
echo "Skipped code coverage if from personal or feature branch"
}
}
}
}
stage('CodeAnalysis') {
when {
expression {
GIT_BRANCH ==~ /.*master|.*feature\/.*|.*develop|.*hotfix\/.*|.*release\/.*/
}
}
steps {
script {
scannerHome = tool name: 'sonar-scanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
}
withSonarQubeEnv('sonarqube.io') {
sh "${scannerHome}/bin/sonar-scanner -Dsonar.branch.name=${GIT_BRANCH} -Dsonar.projectKey=varunpalekar_php-test -Dsonar.organization=varunpalekar-github"
}
}
}
stage('DockerPush') {
when {
expression {
GIT_BRANCH ==~ /.*master|.*release\/.*|.*develop|.*hotfix\/.*/
}
}
steps {
script{
docker.withRegistry('', 'public-docker-hub') {

def customImage = docker.build("${env.DOCKER_REGISTRY}:${env.DOCKER_TAG}")
customImage.push()

if ( GIT_BRANCH ==~ /.*master|.*hotfix\/.*|.*release\/.*/ )
customImage.push('latest')
}
}
}
}
stage('Deploy_Dev') {
when {
expression {
GIT_BRANCH ==~ /.*develop/
}
}
steps {
script{
echo "Deploy application on developmment environment"
dir("ansible") {
ansiblePlaybook installation: 'ansible', inventory: 'hosts-dev', playbook: 'playbook.yml', extraVars: [
deployment_app_image: "${env.DOCKER_REGISTRY}:${env.DOCKER_TAG}"
]
}
}

input message: "Do you want to run migration?"

script{
echo "Deploy application on developmment environment"
dir("ansible") {
ansiblePlaybook installation: 'ansible', inventory: 'hosts-dev', playbook: 'playbook.yml', tags: 'migration'
}
}

input message: "Do you want to run seeding?"

script{
echo "Deploy application on developmment environment"
dir("ansible") {
ansiblePlaybook installation: 'ansible', inventory: 'hosts-dev', playbook: 'playbook.yml', tags: 'seeding'
}
}
}
}

stage('Undeploy_Dev'){
when {
expression {
GIT_BRANCH ==~ /.*develop/
}
}
// timeout(time:5, unit:'DAYS') {
// input message:'Approve deployment?', submitter: 'it-ops'
// }
steps {
input message: "Do you want to undeploy DEV?"
script {
echo "Undeploy application on developmment environment"
dir("ansible") {
ansiblePlaybook installation: 'ansible', inventory: 'hosts-dev', playbook: 'playbook.yml', tags: 'undeploy'
}
}
}
}
stage('Deploy_Prod') {
when {
expression {
GIT_BRANCH ==~ /.*master|.*release\/.*|.*hotfix\/.*/
}
}
steps {
input message: "Do you want to proceed for production deployment?"
script{
echo "Deploy application on stage environment"
dir("ansible") {
ansiblePlaybook installation: 'ansible', inventory: 'hosts-prod', playbook: 'playbook.yml', credentialsId: 'ansible-hospice-prod'
}
}

input message: "Do you want to proceed for production migration?"
script{
echo "Deploy application on stage environment"
dir("ansible") {
ansiblePlaybook installation: 'ansible', inventory: 'hosts-prod', playbook: 'playbook.yml', tags: 'migration', credentialsId: 'ansible-hospice-prod'
}
}
}
}

}
}
2 changes: 2 additions & 0 deletions ansible/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*-console.log
.vagrant
48 changes: 48 additions & 0 deletions ansible/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
servers=[
{
:hostname => "dev",
:ip => "192.168.94.41",
:box => "ubuntu/bionic64",
:ram => 1024,
:cpu => 1
},
{
:hostname => "prod",
:ip => "192.168.94.42",
:box => "ubuntu/bionic64",
:ram => 1024,
:cpu => 1
}
]

$initialize = <<-SCRIPT
cat /vagrant/vagrant/id_rsa.pub >> /home/vagrant/.ssh/authorized_keys
apt-get update && apt install -y python
SCRIPT

Vagrant.configure("2") do |config|

if Vagrant.has_plugin?("vagrant-hostmanager")
config.hostmanager.enabled = true
config.hostmanager.manage_guest = true
end

if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
end

config.vm.provision "shell", inline: $initialize

servers.each do |machine|
config.vm.define machine[:hostname] do |node|
node.vm.box = machine[:box]
node.vm.hostname = machine[:hostname]
node.vm.network "private_network", ip: machine[:ip]
node.vm.provider "virtualbox" do |vb|
vb.memory = machine[:ram]
vb.cpus = machine[:cpu]
vb.linked_clone = true
end
end
end
end
5 changes: 5 additions & 0 deletions ansible/hosts-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[hospice]
192.168.94.41 ansible_user=vagrant

[all:vars]
env=dev
5 changes: 5 additions & 0 deletions ansible/hosts-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[hospice]
192.168.94.42 ansible_user=vagrant

[all:vars]
env=prod
1 change: 1 addition & 0 deletions ansible/playbook.retry
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
192.168.94.41
11 changes: 11 additions & 0 deletions ansible/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- hosts: all
become: yes
vars_files:
- "vars/{{ env }}.yml"
roles:
- role: mysql
when: env == 'prod'
- role: docker
docker_install_compose: true
- role: deployment
7 changes: 7 additions & 0 deletions ansible/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

- name: docker
src: geerlingguy.docker

- name: mysql
src: geerlingguy.mysql
Loading
Loading