What happens when you Dockerize your Laravel testing environment and throw it at Gitlab CI?
This repository includes several files required to run the Gitlab CI for your Laravel. The Docker container is pre-packaged with Laravel vendor dependecies, which reduces the number of files required to be downloaded.
It pulls the PHP Laravel image from this repository.
- PHP 7.1/7.2
- Laravel 5.6
- MySQL 5.5
To switch between Laravel versions, change this repository's branch. Master branch will always have the latest image.
There are two ways which this can be used -- for continuous integration and continuous deployment.
Copy the following files and drop them in your Laravel base repository:
- .env.gitlab-testing
- .gitlab-ci.yml
- .gitlab-build.sh
- .gitlab-test.sh
Open up .gitlab-ci.yml and comment or remove the staging information:
before_script: # For more information, view https://docs.gitlab.com/ce/ci/ssh_keys/README.html # install ssh-agent - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' # run ssh-agent - eval $(ssh-agent -s) # add ssh key stored in SSH_PRIVATE_KEY variable to the agent store - ssh-add <(echo "$SSH_PRIVATE_KEY") # disable host key checking (NOTE: makes you susceptible to man-in-the-middle attacks) # WARNING: use only in docker container, if you use it with shell you will overwrite your user's ssh config - mkdir -p ~/.ssh - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config ... - staging_deploy ... stage_job: stage: staging_deploy script: - sh .gitlab-staging-deploy.sh environment: name: staging There are several deployment techniques available: SSH and Docker
Copy the following files and drop them in your Laravel base repository:
- .env.gitlab-testing
- .gitlab-ci.yml
- .gitlab-build.sh
- .gitlab-test.sh
- .gitlab-staging-deploy.sh
Ensure that your repository has set a Git deployment remote and you have created a SSH key for access to this remote.
Open up .gitlab-ci.yml and set the variables for the following:
GIT_DEPLOYMENT_URL: git@gitlab.com:woohuiren/test-laravel-project.git GIT_DEPLOYMENT_REMOTE: staging GIT_DEPLOYMENT_BRANCH: master SSH_PRIVATE_KEY: somethingsomethingblahblah # Recommended to put into GitLab secret variables instead