├── .gitignore
├── .idea
├── .gitignore
├── gitlabby-dockerish-laravel.iml
├── modules.xml
└── vcs.xml
├── LICENSE
├── README.md
├── cloudfoundry
└── 5.7
│ ├── .env.gitlab-testing
│ ├── .gitlab-build.sh
│ ├── .gitlab-ci.yml
│ └── .gitlab-test.sh
└── ssh
├── 5.6
├── .env.gitlab-testing
├── .gitlab-build.sh
├── .gitlab-ci.yml
├── .gitlab-staging-pull-deploy.sh
└── .gitlab-test.sh
└── 8.0
├── .env.gitlab-testing
├── .gitlab-build.sh
├── .gitlab-ci.yml
├── .gitlab-staging-pull-deploy.sh
└── .gitlab-test.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### JetBrains template
3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
5 |
6 | # User-specific stuff
7 | .idea/**/workspace.xml
8 | .idea/**/tasks.xml
9 | .idea/**/dictionaries
10 | .idea/**/shelf
11 |
12 | # Sensitive or high-churn files
13 | .idea/**/dataSources/
14 | .idea/**/dataSources.ids
15 | .idea/**/dataSources.local.xml
16 | .idea/**/sqlDataSources.xml
17 | .idea/**/dynamic.xml
18 | .idea/**/uiDesigner.xml
19 | .idea/**/dbnavigator.xml
20 |
21 | # Gradle
22 | .idea/**/gradle.xml
23 | .idea/**/libraries
24 |
25 | # CMake
26 | cmake-build-debug/
27 | cmake-build-release/
28 |
29 | # Mongo Explorer plugin
30 | .idea/**/mongoSettings.xml
31 |
32 | # File-based project format
33 | *.iws
34 |
35 | # IntelliJ
36 | out/
37 |
38 | # mpeltonen/sbt-idea plugin
39 | .idea_modules/
40 |
41 | # JIRA plugin
42 | atlassian-ide-plugin.xml
43 |
44 | # Cursive Clojure plugin
45 | .idea/replstate.xml
46 |
47 | # Crashlytics plugin (for Android Studio and IntelliJ)
48 | com_crashlytics_export_strings.xml
49 | crashlytics.properties
50 | crashlytics-build.properties
51 | fabric.properties
52 |
53 | # Editor-based Rest Client
54 | .idea/httpRequests
55 |
56 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/.idea/gitlabby-dockerish-laravel.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Huiren Woo
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Gitlabby Dockerish Laravel
2 |
3 | What happens when you Dockerize your Laravel testing environment and throw it at Gitlab CI?
4 |
5 | This repository includes several files required to run the Gitlab CI for your Laravel. The Docker container is
6 | pre-packaged with Laravel vendor dependecies, which reduces the number of files required to be downloaded.
7 |
8 | It pulls the PHP Laravel image from [this repository](https://github.com/GIANTCRAB/php-laravel-env).
9 |
10 | ## Support
11 |
12 | ### Laravel 5.6
13 |
14 | * PHP 7.1/7.2/7.3
15 | * MySQL
16 | * Redis (Your Laravel will require `predis/predis` composer package)
17 | * Laravel Dusk (UI automated testing)
18 |
19 | ### Laravel 5.7
20 |
21 | * PHP 7.1/7.2/7.3
22 | * MySQL
23 | * Redis (Your Laravel will require `predis/predis` composer package)
24 | * Laravel Dusk (UI automated testing)
25 |
26 | ### Laravel Latest (8.0)
27 |
28 | * [PHP 8.0](https://github.com/GIANTCRAB/php-laravel-env/tree/8.0)
29 | * MySQL
30 | * Redis
31 | * Laravel Dusk
32 |
33 | # Usage
34 |
35 | There are several deployment techniques available: SSH and Cloudfoundry
36 |
37 | ## SSH Deployment
38 |
39 | Copy the files in the ssh directory and drop them to the base of your GitLab repo.
40 |
41 | Ensure that your repository has set a Git deployment remote and you have created a SSH key for access to this remote.
42 |
43 | Open up `.gitlab-ci.yml` and set the variables for the following:
44 |
45 | ```
46 | GIT_DEPLOYMENT_URL: git@gitlab.com:woohuiren/test-laravel-project.git
47 | GIT_DEPLOYMENT_REMOTE: staging
48 | GIT_DEPLOYMENT_BRANCH: master
49 | SSH_PRIVATE_KEY: somethingsomethingblahblah # Recommended to put into GitLab secret variables instead
50 | ```
51 |
52 | ## Cloudfoundry
53 |
54 | Copy the files in the cloudfoundry directory and drop them to the base of your GitLab repo.
55 |
56 | Set the secret variables accordingly.
--------------------------------------------------------------------------------
/cloudfoundry/5.7/.env.gitlab-testing:
--------------------------------------------------------------------------------
1 | APP_ENV=local
2 | APP_KEY=
3 | APP_DEBUG=true
4 | APP_LOG_LEVEL=debug
5 | APP_URL=http://localhost
6 |
7 | LOG_CHANNEL=stack
8 |
9 | DB_CONNECTION=mysql
10 | DB_HOST=mysql
11 | DB_PORT=3306
12 | DB_DATABASE=laravel
13 | DB_USERNAME=root
14 | DB_PASSWORD=secret
15 |
16 | BROADCAST_DRIVER=log
17 | CACHE_DRIVER=redis
18 | QUEUE_CONNECTION=redis
19 | SESSION_DRIVER=redis
20 | SESSION_LIFETIME=120
21 |
22 | REDIS_HOST=redis
23 | REDIS_PASSWORD=null
24 | REDIS_PORT=6379
25 |
26 |
27 | MAIL_DRIVER=smtp
28 | MAIL_HOST=smtp.mailtrap.io
29 | MAIL_PORT=2525
30 | MAIL_USERNAME=null
31 | MAIL_PASSWORD=null
32 | MAIL_ENCRYPTION=null
33 |
34 | PUSHER_APP_ID=
35 | PUSHER_APP_KEY=
36 | PUSHER_APP_SECRET=
37 | PUSHER_APP_CLUSTER=mt1
38 |
39 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
40 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
--------------------------------------------------------------------------------
/cloudfoundry/5.7/.gitlab-build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Ensure we fail fast if there is a problem.
3 | set -eo pipefail
4 |
5 | # Move the files over to current directory
6 | mv /root/composer.phar .
7 |
8 | # Ensure that php is working
9 | php -v
10 |
11 | # Update project dependencies.
12 | php composer.phar install
13 |
14 | # Copy over testing configuration. This configuration is used for Gitlab CI unit testing
15 | cp -v .env.gitlab-testing .env
16 |
17 | # Generate an application key. Clear config and cache route
18 | php artisan key:generate
19 | php artisan config:clear
20 | #php artisan route:cache # Uncomment this if you do not use closures in your route files as this helps to improve performance
21 |
--------------------------------------------------------------------------------
/cloudfoundry/5.7/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | image: woohuiren/laravel-pcf:latest
2 |
3 | # Recommended to put into GitLab secret variables instead
4 | variables:
5 | CF_API_ENDPOINT: woohuiren.me
6 | CF_USERNAME: woohuiren
7 | CF_PASSWORD: somepassword
8 | CF_ORGANIZATION: woohuiren
9 | CF_SPACE: secret-project
10 | CF_APP: secret-app-ui
11 |
12 | stages:
13 | - build
14 | - test
15 | - staging_deploy
16 |
17 | build_job:
18 | stage: build
19 | script:
20 | - sh .gitlab-build.sh
21 | artifacts:
22 | paths:
23 | - vendor/
24 | - bootstrap/
25 | - composer.phar
26 | - .env
27 | tags:
28 | - docker
29 |
30 | test_job:
31 | stage: test
32 | services:
33 | - mysql:latest
34 | - redis:latest
35 | dependencies:
36 | - build_job
37 | script:
38 | - sh .gitlab-test.sh
39 | tags:
40 | - docker
41 |
42 | stage_job:
43 | stage: staging_deploy
44 | dependencies:
45 | - build_job
46 | script:
47 | - cf login -a $CF_API_ENDPOINT -u $CF_USERNAME -p $CF_PASSWORD -o $CF_ORGANIZATION -s $CF_SPACE
48 | - cf check-manifest $CF_APP -f manifest.yml
49 | - cf blue-green-deploy $CF_APP -f manifest.yml --delete-old-apps
50 | environment:
51 | name: staging
52 |
--------------------------------------------------------------------------------
/cloudfoundry/5.7/.gitlab-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Ensure we fail fast if there is a problem.
3 | set -eo pipefail
4 |
5 | # Ensure that php is working
6 | php -v
7 |
8 | # Ensure that mysql server is up and running
9 | ping -c 3 mysql
10 |
11 | # Run database migrations and seed the data
12 | php artisan migrate --seed
13 |
14 | # Run unit testing with PHPUnit
15 | php vendor/bin/phpunit --coverage-text --colors=never
--------------------------------------------------------------------------------
/ssh/5.6/.env.gitlab-testing:
--------------------------------------------------------------------------------
1 | APP_ENV=local
2 | APP_KEY=
3 | APP_DEBUG=true
4 | APP_LOG_LEVEL=debug
5 | APP_URL=http://localhost
6 |
7 | LOG_CHANNEL=stack
8 |
9 | DB_CONNECTION=mysql
10 | DB_HOST=mysql
11 | DB_PORT=3306
12 | DB_DATABASE=laravel
13 | DB_USERNAME=root
14 | DB_PASSWORD=secret
15 |
16 | BROADCAST_DRIVER=log
17 | CACHE_DRIVER=redis
18 | SESSION_DRIVER=redis
19 | QUEUE_DRIVER=redis
20 |
21 | REDIS_HOST=redis
22 | REDIS_PASSWORD=null
23 | REDIS_PORT=6379
24 |
25 | MAIL_DRIVER=smtp
26 | MAIL_HOST=mailtrap.io
27 | MAIL_PORT=2525
28 | MAIL_USERNAME=null
29 | MAIL_PASSWORD=null
30 | MAIL_ENCRYPTION=null
31 |
32 | PUSHER_APP_ID=
33 | PUSHER_KEY=
34 | PUSHER_SECRET=
35 |
36 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
37 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
--------------------------------------------------------------------------------
/ssh/5.6/.gitlab-build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Ensure we fail fast if there is a problem.
3 | set -eo pipefail
4 |
5 | # Move the files over to current directory
6 | mv /root/composer.phar .
7 |
8 | # Ensure that php is working
9 | php -v
10 |
11 | # Update project dependencies.
12 | php composer.phar install
13 |
14 | # Copy over testing configuration. This configuration is used for Gitlab CI unit testing
15 | cp -v .env.gitlab-testing .env
16 |
17 | # Generate an application key. Clear config and cache route
18 | php artisan key:generate
19 | php artisan config:clear
20 | #php artisan route:cache # Uncomment this if you do not use closures in your route files as this helps to improve performance
21 |
--------------------------------------------------------------------------------
/ssh/5.6/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | image: woohuiren/php-laravel-env:5.6
2 |
3 | before_script:
4 | # For more information, view https://docs.gitlab.com/ce/ci/ssh_keys/README.html
5 | # install ssh-agent
6 | - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
7 | # run ssh-agent
8 | - eval $(ssh-agent -s)
9 | # add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
10 | - ssh-add <(echo "$SSH_PRIVATE_KEY")
11 | - echo "$SSH_PRIVATE_KEY" > ~/.ssh/staging_deploy_private_key
12 | - chmod 400 ~/.ssh/staging_deploy_private_key
13 | # disable host key checking (NOTE: makes you susceptible to man-in-the-middle attacks)
14 | # WARNING: use only in docker container, if you use it with shell you will overwrite your user's ssh config
15 | - mkdir -p ~/.ssh
16 | - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
17 |
18 | variables:
19 | MYSQL_DATABASE: laravel
20 | MYSQL_ROOT_PASSWORD: secret
21 | SSH_PRIVATE_KEY: somethingsomethingblahblah # Recommended to put into GitLab secret variables instead
22 | GIT_DEPLOYMENT_REMOTE: origin
23 | GIT_DEPLOYMENT_BRANCH: master
24 | STAGING_SERVER_HOSTNAME: admin@localhost
25 | STAGING_SERVER_DIRECTORY: /home/admin/laravel-project/public
26 |
27 | stages:
28 | - build
29 | - test
30 | - staging_deploy
31 |
32 | build_job:
33 | stage: build
34 | script:
35 | - sh .gitlab-build.sh
36 | artifacts:
37 | paths:
38 | - vendor/
39 | - bootstrap/
40 | - composer.phar
41 | - .env
42 | tags:
43 | - docker
44 |
45 | test_job:
46 | stage: test
47 | services:
48 | - mysql:latest
49 | - redis:latest
50 | dependencies:
51 | - build_job
52 | script:
53 | - sh .gitlab-test.sh
54 | tags:
55 | - docker
56 |
57 | stage_job:
58 | stage: staging_deploy
59 | script:
60 | - sh .gitlab-staging-pull-deploy.sh
61 | environment:
62 | name: staging
63 |
--------------------------------------------------------------------------------
/ssh/5.6/.gitlab-staging-pull-deploy.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Ensure we fail fast if there is a problem.
3 | set -eo pipefail
4 |
5 | # SSH into the staging server and execute the git pull
6 | ssh -i ~/.ssh/staging_deploy_private_key "$STAGING_SERVER_HOSTNAME" "cd $STAGING_SERVER_DIRECTORY; git reset --hard HEAD; git checkout $GIT_DEPLOYMENT_BRANCH; git pull $GIT_DEPLOYMENT_REMOTE; composer install; composer update; php artisan optimize; php artisan migrate --seed"
7 |
--------------------------------------------------------------------------------
/ssh/5.6/.gitlab-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Ensure we fail fast if there is a problem.
3 | set -eo pipefail
4 |
5 | # Ensure that php is working
6 | php -v
7 |
8 | # Ensure that mysql server is up and running
9 | ping -c 3 mysql
10 |
11 | # Run database migrations and seed the data
12 | php artisan migrate --seed
13 |
14 | # Run unit testing with PHPUnit
15 | php vendor/bin/phpunit --coverage-text --colors=never
--------------------------------------------------------------------------------
/ssh/8.0/.env.gitlab-testing:
--------------------------------------------------------------------------------
1 | APP_ENV=local
2 | APP_KEY=
3 | APP_DEBUG=true
4 | APP_LOG_LEVEL=debug
5 | APP_URL=http://localhost
6 |
7 | LOG_CHANNEL=stack
8 |
9 | DB_CONNECTION=mysql
10 | DB_HOST=mysql
11 | DB_PORT=3306
12 | DB_DATABASE=laravel
13 | DB_USERNAME=root
14 | DB_PASSWORD=secret
15 |
16 | BROADCAST_DRIVER=log
17 | CACHE_DRIVER=redis
18 | SESSION_DRIVER=redis
19 | QUEUE_DRIVER=redis
20 |
21 | REDIS_HOST=redis
22 | REDIS_PASSWORD=null
23 | REDIS_PORT=6379
24 |
25 | MAIL_DRIVER=smtp
26 | MAIL_HOST=mailtrap.io
27 | MAIL_PORT=2525
28 | MAIL_USERNAME=null
29 | MAIL_PASSWORD=null
30 | MAIL_ENCRYPTION=null
31 |
32 | PUSHER_APP_ID=
33 | PUSHER_KEY=
34 | PUSHER_SECRET=
35 |
36 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
37 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
--------------------------------------------------------------------------------
/ssh/8.0/.gitlab-build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Ensure we fail fast if there is a problem.
3 | set -eo pipefail
4 |
5 | # Ensure that php is working
6 | php -v
7 |
8 | # Install project dependencies based on composer lock file info
9 | composer install
10 |
11 | # Copy over testing configuration. This configuration is used for Gitlab CI unit testing
12 | cp -v .env.gitlab-testing .env
13 |
14 | # Generate an application key. Clear config and cache route
15 | php artisan key:generate
16 | php artisan config:clear
17 | #php artisan route:cache # Uncomment this if you do not use closures in your route files as this helps to improve performance
18 |
--------------------------------------------------------------------------------
/ssh/8.0/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | image: woohuiren/php-laravel-env:8.0
2 |
3 | before_script:
4 | # For more information, view https://docs.gitlab.com/ce/ci/ssh_keys/README.html
5 | # install ssh-agent
6 | - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
7 | # run ssh-agent
8 | - eval $(ssh-agent -s)
9 | # add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
10 | - ssh-add <(echo "$SSH_PRIVATE_KEY")
11 | - echo "$SSH_PRIVATE_KEY" > ~/.ssh/staging_deploy_private_key
12 | - chmod 400 ~/.ssh/staging_deploy_private_key
13 | # disable host key checking (NOTE: makes you susceptible to man-in-the-middle attacks)
14 | # WARNING: use only in docker container, if you use it with shell you will overwrite your user's ssh config
15 | - mkdir -p ~/.ssh
16 | - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
17 |
18 | variables:
19 | MYSQL_DATABASE: laravel
20 | MYSQL_ROOT_PASSWORD: secret
21 | SSH_PRIVATE_KEY: somethingsomethingblahblah # Recommended to put into GitLab secret variables instead
22 | GIT_DEPLOYMENT_REMOTE: origin
23 | GIT_DEPLOYMENT_BRANCH: master
24 | STAGING_SERVER_HOSTNAME: admin@localhost
25 | STAGING_SERVER_DIRECTORY: /home/admin/laravel-project/public
26 |
27 | stages:
28 | - build
29 | - test
30 | - staging_deploy
31 |
32 | build_job:
33 | stage: build
34 | script:
35 | - sh .gitlab-build.sh
36 | artifacts:
37 | paths:
38 | - vendor/
39 | - bootstrap/
40 | - .env
41 | tags:
42 | - docker
43 |
44 | test_job:
45 | stage: test
46 | services:
47 | - mysql:latest
48 | - redis:latest
49 | dependencies:
50 | - build_job
51 | script:
52 | - sh .gitlab-test.sh
53 | tags:
54 | - docker
55 |
56 | stage_job:
57 | stage: staging_deploy
58 | script:
59 | - sh .gitlab-staging-pull-deploy.sh
60 | environment:
61 | name: staging
62 |
--------------------------------------------------------------------------------
/ssh/8.0/.gitlab-staging-pull-deploy.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Ensure we fail fast if there is a problem.
3 | set -eo pipefail
4 |
5 | # SSH into the staging server and execute the git pull
6 | ssh -i ~/.ssh/staging_deploy_private_key "$STAGING_SERVER_HOSTNAME" "cd $STAGING_SERVER_DIRECTORY; git reset --hard HEAD; git checkout $GIT_DEPLOYMENT_BRANCH; git pull $GIT_DEPLOYMENT_REMOTE; composer install; composer update; php artisan optimize; php artisan migrate --seed"
7 |
--------------------------------------------------------------------------------
/ssh/8.0/.gitlab-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Ensure we fail fast if there is a problem.
3 | set -eo pipefail
4 |
5 | # Ensure that php is working
6 | php -v
7 |
8 | # Ensure that mysql server is up and running
9 | ping -c 3 mysql
10 |
11 | # Run database migrations and seed the data
12 | php artisan migrate --seed
13 |
14 | # Run unit testing with PHPUnit
15 | php vendor/bin/phpunit --coverage-text --colors=never
--------------------------------------------------------------------------------