{"id":81,"date":"2023-06-13T09:28:41","date_gmt":"2023-06-13T01:28:41","guid":{"rendered":"https:\/\/www.haoxiaokai.com\/?p=81"},"modified":"2023-06-13T09:28:42","modified_gmt":"2023-06-13T01:28:42","slug":"%e4%bd%bf%e7%94%a8gitlab-runner%e4%b8%ba%e5%9f%ba%e4%ba%8elaravel%e7%9a%84php%e9%a1%b9%e7%9b%ae%e8%bf%9b%e8%a1%8c%e9%83%a8%e7%bd%b2","status":"publish","type":"post","link":"https:\/\/www.haoxiaokai.com\/?p=81","title":{"rendered":"\u4f7f\u7528GitLab Runner\u4e3a\u57fa\u4e8eLaravel\u7684PHP\u9879\u76ee\u8fdb\u884c\u90e8\u7f72"},"content":{"rendered":"\n<p>\u5f53\u4f7f\u7528GitLab Runner\u4e3a\u57fa\u4e8eLaravel\u7684PHP\u9879\u76ee\u8fdb\u884c\u90e8\u7f72\u65f6\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a<code>.gitlab-ci.yml<\/code>\u6587\u4ef6\u6765\u914d\u7f6eCI\/CD\u6d41\u6c34\u7ebf\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u914d\u7f6e\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u4f60\u7684\u9879\u76ee\u9700\u6c42\u8fdb\u884c\u9002\u5f53\u7684\u4fee\u6539\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>stages:\n  - build\n  - deploy\n\nvariables:\n  APP_ENV: production\n  DB_HOST: your_database_host\n  DB_DATABASE: your_database_name\n  DB_USERNAME: your_database_username\n  DB_PASSWORD: your_database_password\n\ncache:\n  paths:\n    - vendor\/\n\nbefore_script:\n  - apt-get update\n  - apt-get install -y unzip\n  - curl -sS https:\/\/getcomposer.org\/installer | php -- --install-dir=\/usr\/local\/bin --filename=composer\n  - cp .env.example .env\n  - composer install --no-interaction --prefer-dist --no-suggest\n  - php artisan key:generate\n  - php artisan config:cache\n\nbuild:\n  stage: build\n  script:\n    - php artisan route:cache\n    - php artisan view:cache\n    - php artisan optimize\n\ndeploy_production:\n  stage: deploy\n  script:\n    - ssh deploy@your_server 'cd \/var\/www\/html &amp;&amp; git pull origin master'\n    - ssh deploy@your_server 'cd \/var\/www\/html &amp;&amp; composer install --no-dev --optimize-autoloader'\n    - ssh deploy@your_server 'cd \/var\/www\/html &amp;&amp; php artisan migrate --force'\n    - ssh deploy@your_server 'cd \/var\/www\/html &amp;&amp; php artisan config:cache'\n    - ssh deploy@your_server 'cd \/var\/www\/html &amp;&amp; php artisan route:cache'\n    - ssh deploy@your_server 'cd \/var\/www\/html &amp;&amp; php artisan view:cache'<\/code><\/pre>\n\n\n\n<p>\u8bf7\u6ce8\u610f\uff0c\u4e0a\u8ff0\u914d\u7f6e\u5047\u8bbe\u4f60\u5df2\u7ecf\u5728\u670d\u52a1\u5668\u4e0a\u8bbe\u7f6e\u4e86\u9002\u5f53\u7684\u90e8\u7f72\u7528\u6237\uff08<code>deploy<\/code>\uff09\u548c\u76f8\u5173\u6743\u9650\u3002\u786e\u4fdd\u5c06<code>your_database_host<\/code>\u3001<code>your_database_name<\/code>\u3001<code>your_database_username<\/code>\u548c<code>your_database_password<\/code>\u66ff\u6362\u4e3a\u5b9e\u9645\u7684\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f\u3002<\/p>\n\n\n\n<p>\u6b64\u914d\u7f6e\u6587\u4ef6\u7684\u5173\u952e\u70b9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5728<code>before_script<\/code>\u9636\u6bb5\uff0c\u6211\u4eec\u5b89\u88c5\u4f9d\u8d56\u3001\u751f\u6210\u5bc6\u94a5\u5e76\u8fdb\u884c\u914d\u7f6e\u7f13\u5b58\u3002<\/li>\n\n\n\n<li><code>build<\/code>\u9636\u6bb5\u7528\u4e8e\u4f18\u5316Laravel\u9879\u76ee\u3002<\/li>\n\n\n\n<li><code>deploy_production<\/code>\u9636\u6bb5\u8fde\u63a5\u5230\u4f60\u7684\u670d\u52a1\u5668\uff0c\u6267\u884c\u5fc5\u8981\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982\u4eceGit\u62c9\u53d6\u4ee3\u7801\u3001\u5b89\u88c5\u4f9d\u8d56\u3001\u8fd0\u884c\u6570\u636e\u5e93\u8fc1\u79fb\uff0c\u5e76\u7f13\u5b58\u914d\u7f6e\u3001\u8def\u7531\u548c\u89c6\u56fe\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u8bf7\u6839\u636e\u4f60\u7684\u5177\u4f53\u8981\u6c42\u8fdb\u884c\u9002\u5f53\u7684\u8c03\u6574\u548c\u81ea\u5b9a\u4e49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u4f7f\u7528GitLab Runner\u4e3a\u57fa\u4e8eLaravel\u7684PHP\u9879\u76ee\u8fdb\u884c\u90e8\u7f72\u65f6\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a.gitlab-ci &hellip; <a href=\"https:\/\/www.haoxiaokai.com\/?p=81\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">\u201c\u4f7f\u7528GitLab Runner\u4e3a\u57fa\u4e8eLaravel\u7684PHP\u9879\u76ee\u8fdb\u884c\u90e8\u7f72\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-81","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.haoxiaokai.com\/index.php?rest_route=\/wp\/v2\/posts\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.haoxiaokai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.haoxiaokai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.haoxiaokai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.haoxiaokai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=81"}],"version-history":[{"count":1,"href":"https:\/\/www.haoxiaokai.com\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":82,"href":"https:\/\/www.haoxiaokai.com\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions\/82"}],"wp:attachment":[{"href":"https:\/\/www.haoxiaokai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.haoxiaokai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.haoxiaokai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}