laravel CI / CD Development - laravel

Can anyone point me in the right direction for the Laravel CI/CD Development in code commit AWS?
I have gone through a lot of tutorials but always fail to connect the Database to either elastic beanstalk or EC2,
Can someone recommend a good tutorial for this
This is my build Command.
version: 0.2
phases:
install:
runtime-versions:
php: 7.4
nodejs: 12.x
commands:
- apt-get update -y
- apt-get install -y libpq-dev libzip-dev
- apt-get install -y php-pgsql
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
pre_build:
commands:
- cp .env.beta .env
- composer install
- npm install
build:
commands:
- npm run production
- php artisan migrate --force
- php artisan db:seed
artifacts:
files:
- '**/*'
name: $(date +%Y-%m-%dT%H:%M:%S).zip
proxy:
upload-artifacts: yes
logs: yes
now i am getting ngnix 404 error,Even after adding " /public " in beanstalk

Related

Azure DevOps CI pipeline for standard Laravel 9 project

My team and I are familiarizing ourselves with Azure DevOps. I'd like to set up a CI pipeline for the standard Laravel 9 project as a proof of concept, but haven't been successful.
I also haven't been able to find a template.
All that needs to happen in our pipeline is for the new code to be built, tested and containerised as a docker container which can then be pushed to a repo for later deployment.
If anyone could help point me in the right direction, I'd greatly appreciate it!
Using the below YAML file, I've continously run into errors that I do not understand. With the version below, failing a unit test that only asserts whether true is true.
trigger:
- main
pool:
vmImage: 'Ubuntu-Latest'
variables:
PHP_VERSION: '8.0.2'
PHPUNIT_VERSION: '9.5.10'
steps:
- task: NodeTool#0
inputs:
versionSpec: '14.x'
- script: |
sudo apt-get update
sudo apt-get install -y php${{ variables.PHP_VERSION }} php${{ variables.PHP_VERSION }}-cli php${{ variables.PHP_VERSION }}-mbstring unzip
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
sudo composer global require "phpunit/phpunit:${{ variables.PHPUNIT_VERSION }}"
displayName: 'Install PHP and Composer'
- script: |
sudo apt-get install -y git
git clone https://github.com/RadicalRumin/fluffy-fiesta.git
cd /fluffy-fiesta
composer install
displayName: 'Clone and install dependencies'
- script: |
phpunit
displayName: 'Run PHPUnit tests'

The command '/bin/sh -c yum install yum-utils' returned a non-zero code: 1

i am trying to setup laravel php setup using docker.
Is something wrong with the docker file or the network configurations !!!!
Using DockerFile:
FROM centos:7
# Install some must-haves
RUN yum -y install vim wget sendmail
RUN yum -y install libtool make automake autoconf nasm libpng-static
RUN yum -y install git
RUN git --version
# Install PHP 7.1 on CentOS
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
RUN yum install yum-utils
RUN yum install epel-release
RUN yum-config-manager --enable remi-php73
RUN yum --enablerepo=remi-php73 -y install php php-bcmath php-cli php-common php-gd php-intl php-ldap php-mbstring \
php-mysqlnd php-pear php-soap php-xml php-xmlrpc php-zip php-fpm
RUN php -v
# Prepare PHP environment
COPY config/php/php-fpm.conf /etc/php-fpm.conf
COPY config/php/www.conf /etc/php-fpm.d/www.conf
COPY config/php/php.ini /usr/local/etc/php/php.ini
COPY config/php/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/bin/composer
RUN composer --version
# Install Node.js
RUN curl -sL https://rpm.nodesource.com/setup_7.x | bash -
RUN yum -y install nodejs
RUN yum list installed nodejs
RUN node -v
# Final update and clean up
RUN yum -y update --skip-broken
RUN yum clean all
# Define work directory
WORKDIR /var/www/laravel-boilerplate
# Expose ports
EXPOSE 9000
CMD ["php-fpm", "-F", "-O"]
# CMD ["/bin/sh", "-l", "-c", "php-fpm"]
# CMD ["php-fpm", "-F"]
Command which i had run to setup the instances are,
docker-compose up -d
any idea what went wrong?
Adding docker compose file
version: '2'
services:
mysql:
image: mysql:latest
volumes:
- "./data/db:/var/lib/mysql"
ports:
- "3306:3306"
restart: always
environment:
- MYSQL_ROOT_PASSWORD=test
- MYSQL_DATABASE=laravel_boilerplate
- MYSQL_USER=root
- MYSQL_PASSWORD=secret
laravel-env:
build: ./dockerfiles
depends_on:
- mysql
volumes:
- ".:/var/www/laravel-boilerplate"
- "./dockerfiles/config/php/php-fpm.conf:/etc/php-fpm.conf"
- "./dockerfiles/config/php/www.conf:/etc/php-fpm.d/www.conf"
- "./dockerfiles/config/php/php.ini:/usr/local/etc/php/php.ini"
- "./dockerfiles/config/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini"
nginx:
image: nginx:latest
depends_on:
- laravel-env
volumes:
- ".:/var/www/laravel-boilerplate"
- "./dockerfiles/config/nginx/default.conf:/etc/nginx/conf.d/default.conf"
ports:
- "80:80"
restart: always
Let me know if I missed anything!!!!
Is something has to get removed while building or is something had to deleted like cleanup, am pretty new setting up the code so. Your help is much appreciated.
Thanks folks.

Travis CI: Split Builds from PHPUnit and Laravel Dusk

I would like to set up a testing scenario where I can separate the test-builds for PHPUnit and Laravel Dusk. The reason why is, that this I would like to run different .env & phpunit.xml files for each test-approach.
Set the environment for PHPUnit
Test PHPUnit
Clean the Travis Build
Set the environment for Laravel Dusk
Test Laravel Dusk
I've gone through the Travis documentation about jobs and the matrix but I can't find a proper approach which I can follow.
My .travis.yml file:
sudo: true
dist: trusty
language: php
php:
- 7.3
addons:
chrome: stable
apt:
sources:
- mysql-5.7-trusty
packages:
- mysql-server
- mysql-client
services:
- mysql
install:
- composer self-update
- travis_retry composer install --no-interaction --prefer-dist --no-suggest
before_script:
- rm composer.lock
- echo -e "[server]\nmax_allowed_packet=64M" | sudo tee -a /etc/mysql/conf.d/drupal.cnf
- sudo service mysql restart
- mysql -e 'CREATE DATABASE testing;'
- mysql -e 'CREATE DATABASE business_external;'
- mysql business_external < /home/travis/build/StanBarrows/business/database/data/business_external
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
- cp .env.travis .env
- cp phpunit.travis.xml phpunit.xml
- php artisan key:generate
- php artisan storage:link
- php artisan serve &
script:
- vendor/bin/phpunit
- php artisan dusk
notifications:
email: false

How do I install composer in container of docker?

I am new at docker and docker-compose and I am developing a Laravel-project on docker and docker-compose with Laradock as following a tutorial(not sure whether It is a correct way or not to refer this situation though).
I want to install the composer in this environment to be able to use the composer command.
As a matter of fact, I wanted to do seeding to put data into DB that I made by php artisan make:migrate but this error appeared.
include(/var/www/laravel_practice/vendor/composer/../../database/seeds/AdminsTableSeeder.php): failed to open stream: No such file or directory
So I googled this script to find a solution that will solve the error then I found it.
It says, "Do composer dump-autoload and try seeding again", so I followed it then this error appeared.
bash: composer: command not found
Because I have not installed composer into docker-container.
My docker's condition is like this now.
・workspace
・mysql
・apache
・php-fpm
Since I have not installed the composer, I have to install it into docker-container to solve the problem, BUT I have no idea how to install it into docker-container.
So could anyone tell me how to install composer into docker-container?
Thank you.
here is the laradock/mysql/Dockerfile and laravelProject/docker-compose.yml.
ARG MYSQL_VERSION=5.7
FROM mysql:${MYSQL_VERSION}
LABEL maintainer="Mahmoud Zalt <mahmoud#zalt.me>"
#####################################
# Set Timezone
#####################################
ARG TZ=UTC
ENV TZ ${TZ}
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && chown -R mysql:root /var/lib/mysql/
COPY my.cnf /etc/mysql/conf.d/my.cnf
CMD ["mysqld"]
EXPOSE 3306
version: '2'
services:
db:
image: mysql:5.7
ports:
- "6603:3306"
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=true
- MYSQL_DATABASE=laravelProject
- LANG=C.UTF-8
volumes:
- db:/var/lib/mysql
command: mysqld --sql-mode=NO_ENGINE_SUBSTITUTION --character-set-server=utf8 --collation-server=utf8_unicode_ci
web:
image: arbiedev/php-nginx:7.1.8
ports:
- "8080:80"
volumes:
- ./www:/var/www
- ./nginx.conf:/etc/nginx/sites-enabled/default
volumes:
db:
You can build your own image and use it in your Docker compose file.
FROM php:7.2-alpine3.8
RUN apk update
RUN apk add bash
RUN apk add curl
# INSTALL COMPOSER
RUN curl -s https://getcomposer.org/installer | php
RUN alias composer='php composer.phar'
# INSTALL NGINX
RUN apk add nginx
I used the PHP alpine image as my base image because it's lightweight, so you might have to install other dependencies yourself. In your docker-compose file
web:
build: path/to/your/Dockerfile/directory
image: your-image-tag
ports:
- "8080:80"
volumes:
- ./www:/var/www
- ./nginx.conf:/etc/nginx/sites-enabled/default
You could do something like this:
FROM php:8.0.2-apache
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y mariadb-client libxml2-dev
RUN apt-get autoremove -y && apt-get autoclean
RUN docker-php-ext-install mysqli pdo pdo_mysql xml
COPY --from=composer /usr/bin/composer /usr/bin/composer
the argument COPY --from= should solve your problem.
FROM php:7.3-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
RUN apk update
RUN apk upgrade
RUN apk add bash
RUN alias composer='php /usr/bin/composer'

Docker build image for php apache

I am trying to create a docker image from ubuntu where I need ti install laravel. For that I am trying to run.
I have a docker file where I am using this code:
FROM ubuntu:latest
RUN apt-get update && apt-get upgrade -y\
&& apt-get install apache2\
&& apt-get install php libapache2-mod-php php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-mysql php-cli php-mcrypt php-zip\
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
EXPOSE 80 443
When I am running docker-coompose up I am getting error:
ERROR: Service 'web' failed to build: The command '/bin/sh -c apt-get update && apt-get upgrade -y && apt-get install apache2 && apt-get install php libapache2-mod-php php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-mysql php-cli php-mcrypt php-zip && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer' returned a non-zero code: 1
My docker-compose file is :
version: '3'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: .......
adminer:
image: adminer
restart: always
ports:
- 8080:8090
web:
build: .
working_dir: /var/www/html
volumes:
- .:/var/www/html
ports:
- "80:7000"
depends_on:
- db
What should I do if I need to create a docker image for my laravel application. I have a laravel application and I need to run it through docker.
I just used this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose#step-1-%E2%80%94-downloading-laravel-and-installing-dependencies to accomplish exactly this.
If you just need the end result check out my github repo: https://github.com/RyanFletcher86/LaravelDocker
I've managed to distill it down to 2 commands to get everything up and running.

Resources