Skip to content

Commit 237b9b7

Browse files
committed
[TASK] Add deployment
1 parent 4401640 commit 237b9b7

File tree

2 files changed

+147
-1
lines changed

2 files changed

+147
-1
lines changed

.github/workflows/ci.yml

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
jobs:
1212
build:
13-
name: Build PHP
13+
name: Build
1414
runs-on: ubuntu-latest
1515
steps:
1616

@@ -59,3 +59,82 @@ jobs:
5959

6060
- name: Yarn build
6161
run: yarn build
62+
63+
deployment:
64+
name: Deployment
65+
runs-on: ubuntu-latest
66+
environment:
67+
name: production
68+
url: https://sitepackagebuilder.com
69+
needs: [build]
70+
if: (github.ref == 'refs/heads/master') && github.event_name != 'pull_request' && (github.repository == 'benjaminkott/packagebuilder')
71+
steps:
72+
73+
- name: Checkout Code
74+
uses: actions/checkout@v2
75+
76+
- name: Set up PHP 7.4
77+
uses: shivammathur/setup-php@v2
78+
with:
79+
php-version: 7.4
80+
tools: composer:v2
81+
82+
- name: Download Deployer
83+
run: |
84+
curl -LO https://github.com/deployphp/deployer/releases/download/v7.0.0-beta.37/deployer.phar
85+
sudo mv deployer.phar /usr/local/bin/dep;
86+
sudo chmod +x /usr/local/bin/dep;
87+
dep self-update;
88+
89+
- name: Get Composer cache directory path
90+
id: composer-cache
91+
run: |
92+
echo "::set-output name=dir::$(composer config cache-files-dir)"
93+
94+
- uses: actions/cache@v2
95+
with:
96+
path: ${{ steps.composer-cache.outputs.dir }}
97+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
98+
restore-keys: |
99+
${{ runner.os }}-composer-
100+
101+
- name: Set ENV
102+
run: "echo \"APP_ENV=prod\" >> .env.local"
103+
104+
- name: Build PHP
105+
run: composer install --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader
106+
107+
- name: Get yarn cache directory path
108+
id: yarn-cache-dir-path
109+
run: echo "::set-output name=dir::$(yarn cache dir)"
110+
111+
- uses: actions/cache@v2
112+
id: yarn-cache
113+
with:
114+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
115+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
116+
restore-keys: |
117+
${{ runner.os }}-yarn-
118+
119+
- name: Build Frontend
120+
run: yarn install --silent && yarn build
121+
122+
- name: Setup SSH Key
123+
env:
124+
SSH_AUTH_SOCK: /tmp/ssh-auth.sock
125+
run: |
126+
mkdir -p ~/.ssh
127+
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_rsa
128+
chmod 0600 ~/.ssh/deploy_rsa
129+
ssh-keygen -p -P "${{ secrets.SSH_PASSPHRASE }}" -N "" -f ~/.ssh/deploy_rsa
130+
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
131+
ssh-add ~/.ssh/deploy_rsa
132+
ssh-keyscan ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
133+
134+
- name: Deploy
135+
env:
136+
SSH_HOST: ${{ secrets.SSH_HOST }}
137+
SSH_USER: ${{ secrets.SSH_USER }}
138+
SSH_AUTH_SOCK: /tmp/ssh-auth.sock
139+
run: |
140+
dep deploy;

deploy.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the package bk2k/packagebuilder.
5+
* For the full copyright and license information, please read the
6+
* LICENSE file that was distributed with this source code.
7+
*/
8+
9+
namespace Deployer;
10+
11+
require 'recipe/symfony.php';
12+
require 'contrib/rsync.php';
13+
require 'contrib/cachetool.php';
14+
15+
// Project name
16+
set('application', 'sitepackagebuilder');
17+
set('writable_mode', 'chmod');
18+
set('rsync_src', __DIR__);
19+
set('cachetool_args', '--web --web-path=./public --web-url=https://{{hostname}}');
20+
21+
set('rsync', [
22+
'exclude' => [
23+
'.ddev',
24+
'.git',
25+
'.github',
26+
'.gitattributes',
27+
'.gitignore',
28+
'node_modules',
29+
'.editorconfig',
30+
'.env.local',
31+
'deploy.php',
32+
],
33+
'exclude-file' => false,
34+
'include' => [],
35+
'include-file' => false,
36+
'filter' => [],
37+
'filter-file' => false,
38+
'filter-perdir'=> false,
39+
'flags' => 'rzcE',
40+
'options' => ['links', 'delete'],
41+
'timeout' => 60,
42+
]);
43+
44+
// Hosts
45+
host(getenv('SSH_HOST'))
46+
->setRemoteUser(getenv('SSH_USER'))
47+
->set('deploy_path', '~/html/application/{{application}}')
48+
->set('rsync_dest', '{{release_path}}')
49+
->set('keep_releases', '2');
50+
51+
task('project:cache', function () {
52+
run('{{bin/console}} cache:clear {{console_options}}');
53+
run('{{bin/console}} cache:warmup {{console_options}}');
54+
});
55+
56+
task('deploy', [
57+
'deploy:lock',
58+
'deploy:release',
59+
'rsync',
60+
'deploy:shared',
61+
'deploy:symlink',
62+
'cachetool:clear:opcache',
63+
'cachetool:clear:apcu',
64+
'project:cache',
65+
'deploy:unlock',
66+
'deploy:cleanup',
67+
]);

0 commit comments

Comments
 (0)