Created
July 4, 2020 14:29
-
-
Save swashata/235c886d94304b89d2b8a7c167f974cf to your computer and use it in GitHub Desktop.
Deploy WordPress Plugin with GitLab CI/CD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Our base image | |
image: registry.gitlab.com/wpquark/docker-containers/php-node:2.0.0-php-7.3-node-12.13.0 | |
# Select what we should cache | |
cache: | |
key: "$CI_COMMIT_REF_SLUG-$CI_JOB_NAME" | |
paths: | |
- .yarn-cache | |
- .composer-cache | |
# Our stages | |
stages: | |
- test | |
- build | |
- deploy | |
variables: | |
YARN_CACHE_FOLDER: "$CI_PROJECT_DIR/.yarn-cache" | |
COMPOSER_CACHE_DIR: "$CI_PROJECT_DIR/.composer-cache" | |
MYSQL_DATABASE: "wp_wpeform_test" | |
MYSQL_ROOT_PASSWORD: "12345678" | |
test:javascript: | |
stage: test | |
tags: | |
- wordpress | |
image: registry.gitlab.com/wpquark/docker-containers/php-node:2.0.0-php-7.3-node-12.13.0 | |
before_script: | |
- yarn install --frozen-lockfile | |
script: | |
- yarn lint | |
- yarn test | |
- php scripts/coverage-shouter.php -sjs | |
- bash <(curl -s https://codecov.io/bash) -F client | |
# We test on php7.1, php7.2 and php7.3, stripped down here | |
# We generate code-cverage here only | |
test:php73: | |
stage: test | |
tags: | |
- wordpress | |
image: registry.gitlab.com/wpquark/docker-containers/php-node:2.0.0-php-7.3-node-12.13.0 | |
services: | |
- mariadb:10.3 | |
before_script: | |
- yarn install --frozen-lockfile | |
- composer install | |
- vendor/bin/pcov clobber | |
script: | |
- yarn phpcs | |
- yarn phpunit:install "$MYSQL_DATABASE" root "$MYSQL_ROOT_PASSWORD" mariadb latest true | |
# - yarn phpunit | |
- yarn phpunit:ci | |
- php scripts/coverage-shouter.php -sphp | |
- bash <(curl -s https://codecov.io/bash) -F server | |
artifacts: | |
paths: | |
- coverage/phpunit | |
expire_in: 2 days | |
# Build WordPress plugin file | |
build: | |
stage: build | |
tags: | |
- wordpress | |
image: registry.gitlab.com/wpquark/docker-containers/php-node:1.1.0-php-7.3-node-10.15.3 | |
before_script: | |
- yarn install --frozen-lockfile | |
# install production dependency and optimize autoload | |
# https://getcomposer.org/doc/articles/autoloader-optimization.md | |
- composer install --no-dev --optimize-autoloader | |
script: | |
- yarn build | |
- yarn archive | |
artifacts: | |
paths: | |
- package/wp-eform.zip | |
expire_in: 1 week | |
only: | |
- master@wpquark/wp-eform.io/wp-eform | |
# And we do continuous deployment | |
deploy-staging: | |
stage: deploy | |
image: registry.gitlab.com/wpquark/docker-containers/php-node:1.1.0-php-7.3-node-10.15.3 | |
tags: | |
- wordpress | |
before_script: | |
- eval $(ssh-agent -s) | |
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' | |
script: | |
# Make sure we add the Staging Key so that we can SSH | |
- ssh-add <(cat "$STAGING_KEY") | |
# Delete and recreate the temporary directory for copying | |
- ssh -p<PORT> [email protected] "rm -rf ~/tmp_wpeform && mkdir -p ~/tmp_wpeform" | |
# Copy the distribution ZIP | |
- scp -P<PORT> package/wp-eform.zip [email protected]:~/tmp_wpeform | |
# SSH and Delete the current plugin and unzip the new build | |
- ssh -p<PORT> [email protected] "rm -rf ~/public_html/wp-content/plugins/wp-eform && unzip ~/tmp_wpeform/wp-eform.zip -d ~/public_html/wp-content/plugins" | |
environment: | |
name: staging | |
url: https://staging.wpeform.io/wp-admin/admin.php?page=wpeform#/dashboard | |
dependencies: | |
- build | |
only: | |
- master@wpquark/wp-eform.io/wp-eform | |
# Deploy to production but manually | |
deploy-production: | |
stage: deploy | |
image: registry.gitlab.com/wpquark/docker-containers/php-node:1.1.0-php-7.3-node-10.15.3 | |
tags: | |
- wordpress | |
before_script: | |
- eval $(ssh-agent -s) | |
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' | |
script: | |
# Make sure we add the Staging Key so that we can SSH | |
- ssh-add <(cat "$PRODUCTION_KEY") | |
# Delete and recreate the temporary directory for copying | |
- ssh -p<PORT> [email protected] "rm -rf ~/tmp_wpeform && mkdir -p ~/tmp_wpeform" | |
# Copy the distribution ZIP | |
- scp -P<PORT> package/wp-eform.zip [email protected]:~/tmp_wpeform | |
# SSH and Delete the current plugin and unzip the new build | |
- ssh -p<PORT> [email protected] "rm -rf ~/public_html/wp-content/plugins/wp-eform && unzip ~/tmp_wpeform/wp-eform.zip -d ~/public_html/wp-content/plugins" | |
environment: | |
name: production | |
url: https://wpeform.io/wp-admin/admin.php?page=wpeform#/dashboard | |
dependencies: | |
- build | |
when: manual | |
only: | |
- master@wpquark/wp-eform.io/wp-eform | |
# Just like above we can deploy to any server. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In GitLab Repository, go to Settings > CI/CD and add the following variable | |
- `STAGING_KEY`: Private key to ssh into your server. Configure your server with the public key to accept it. | |
- `PRODUCTION_KEY`: Same as before, but for your production server. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment