回答編集履歴
1
実際に開発環境で試した方法で再回答
test
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
開発環境で試したのでその方法を記載しておきます。
|
2
|
+
|
1
|
-
|
3
|
+
まず、エラーの意味についてですが、これはBitbucketのレポジトリにアクセスできないという意味です。
|
2
4
|
|
3
5
|
|
4
6
|
|
@@ -10,181 +12,263 @@
|
|
10
12
|
|
11
13
|
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
```
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
```
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
15
|
+
下記のWarningは気にする必要はありません。なんらかのエラーが出た時に私の環境でも出ていました。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```
|
20
|
+
|
21
|
+
Error Output:
|
22
|
+
|
23
|
+
================
|
24
|
+
|
25
|
+
Warning: Permanently added '111.111.111.xxx' (RSA) to the list of known hosts.
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
#### 下準備
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
下記が`~/.ssh/config`です。パーミッションも気をつける必要があります。SSHコマンドで接続できているようなので気にする必要はありません。
|
36
|
+
|
37
|
+
私の開発環境では`keychain`をインストールして試しました。実際のやり方は本回答下部の**SSHパスフレーズ対応**を参照してください。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
- **/home/user1**:`700`以下(750以下でも良いかもしれません)
|
42
|
+
|
43
|
+
- **~/.ssh**:`700`以下
|
44
|
+
|
45
|
+
- **~/.ssh/id_rsa**:`600`以下
|
46
|
+
|
47
|
+
- **~/.ssh/id_rsa.pub**:`644`以下
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```ssh
|
52
|
+
|
53
|
+
# ~/.ssh/config
|
54
|
+
|
55
|
+
Host bitbucket.org
|
56
|
+
|
57
|
+
HostName bitbucket.org
|
58
|
+
|
59
|
+
User git
|
60
|
+
|
61
|
+
identityFile ~/.ssh/bitbucket/id_rsa
|
62
|
+
|
63
|
+
Port 22
|
64
|
+
|
65
|
+
TCPKeepAlive yes
|
66
|
+
|
67
|
+
IdentitiesOnly yes
|
68
|
+
|
69
|
+
ForwardAgent yes
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
Host production
|
74
|
+
|
75
|
+
HostName 11.111.111.xxx
|
76
|
+
|
77
|
+
User linux
|
78
|
+
|
79
|
+
identityFile ~/.ssh/id_rsa
|
80
|
+
|
81
|
+
Port 22
|
82
|
+
|
83
|
+
TCPKeepAlive yes
|
84
|
+
|
85
|
+
IdentitiesOnly yes
|
86
|
+
|
87
|
+
ForwardAgent yes
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
下記のようなコマンドを実行して、パスフレーズなしでログインが成功すれば問題ありません。
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
```bash
|
98
|
+
|
99
|
+
ssh -T bitbucket.org
|
100
|
+
|
101
|
+
ssh production
|
102
|
+
|
103
|
+
```
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
また、Bitbucketへのアクセスを確認するために下記を実行して確認しました。パスフレーズなしで`git clone`できれば確認終了です。
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
```bash
|
112
|
+
|
113
|
+
mkdir /tmp/test
|
114
|
+
|
115
|
+
cd /tmp/test
|
116
|
+
|
117
|
+
git clone git@bitbucket.org:ユーザー名/レポジトリ.git
|
118
|
+
|
119
|
+
```
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
#### Deployer
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
下記が開発環境で試した`deployer-4.x`のインストール方法です。
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
```bash
|
132
|
+
|
133
|
+
curl -LO https://deployer.org/releases/v4.3.1/deployer.phar
|
134
|
+
|
135
|
+
sudo mv deployer.phar /usr/local/bin/dep
|
136
|
+
|
137
|
+
sudo chmod 755 /usr/local/bin/dep
|
138
|
+
|
139
|
+
composer require deployer/deployer --dev
|
140
|
+
|
141
|
+
dep init
|
142
|
+
|
143
|
+
#[common]を選択
|
144
|
+
|
145
|
+
```
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
下記は開発環境で試した`deployer-4.x`のスクリプトです。`deploy:lock`は何故か私の環境だと失敗してしまったのでコメントアウトしてあります。
|
38
150
|
|
39
151
|
|
40
152
|
|
41
153
|
```php
|
42
154
|
|
155
|
+
// deploy.php
|
156
|
+
|
157
|
+
<?php
|
158
|
+
|
159
|
+
namespace Deployer;
|
160
|
+
|
161
|
+
require 'recipe/common.php';
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
// Configuration
|
166
|
+
|
167
|
+
set('ssh_type', 'native');
|
168
|
+
|
169
|
+
set('ssh_multiplexing', false);
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
set('repository', 'git@bitbucket.org:ユーザー名/レポジトリ.git');
|
174
|
+
|
175
|
+
set('shared_files', []);
|
176
|
+
|
177
|
+
set('shared_dirs', []);
|
178
|
+
|
179
|
+
set('writable_dirs', []);
|
180
|
+
|
181
|
+
|
182
|
+
|
43
|
-
// v
|
183
|
+
// Servers
|
44
|
-
|
184
|
+
|
45
|
-
server('production', '11
|
185
|
+
server('production', '11.111.111.xxx', 22)
|
46
|
-
|
186
|
+
|
47
|
-
->user('u
|
187
|
+
->user('linux')
|
48
|
-
|
188
|
+
|
49
|
-
->
|
189
|
+
->configFile('~/.ssh/config')
|
190
|
+
|
191
|
+
->forwardAgent()
|
192
|
+
|
193
|
+
->set('branch', 'master')
|
50
194
|
|
51
195
|
->set('deploy_path', '/var/www/hogehoge/hogehoge');
|
52
196
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
```
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
```
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
最後に、BitbucketにSSH接続確認してみます。下記コメントのように表示されると成功です。
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
```bash
|
136
|
-
|
137
|
-
ssh -T git@bitbucket.org
|
138
|
-
|
139
|
-
#Enter passphrase for key '/home/user1/.ssh/bitbucket/id_rsa': ←ここにパスフレーズ入力
|
140
|
-
|
141
|
-
#logged in as Bitbucketユーザー名.
|
142
|
-
|
143
|
-
#
|
144
|
-
|
145
|
-
#You can use git or hg to connect to Bitbucket. Shell access is disabled.
|
146
|
-
|
147
|
-
```
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
#### デプロイ先サーバーSSH接続
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
デプロイ先のサーバーへSSH接続の確認を行います。既に確認が取れている場合はこの工程をスキップしてください。
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
```bash
|
160
|
-
|
161
|
-
ssh user1@111.111.111.xxx
|
162
|
-
|
163
|
-
#Enter passphrase for key '/home/user1/id_rsa': ←ここにパスフレーズ入力
|
164
|
-
|
165
|
-
```
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
最新バージョンを使っている場合は、`server()`は`host()`に変更されたので、下記のようにします。
|
170
|
-
|
171
|
-
[https://deployer.org/docs/hosts](https://deployer.org/docs/hosts)
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
```php
|
176
|
-
|
177
|
-
host('production')
|
178
|
-
|
179
|
-
->hostname('111.111.111.xxx')
|
180
|
-
|
181
|
-
->user('user1')
|
182
|
-
|
183
|
-
->identityFile('/home/user1/id_rsa') //デプロイ先サーバー秘密鍵
|
184
|
-
|
185
|
-
->forwardAgent(true)
|
186
|
-
|
187
|
-
->set('deploy_path', '/var/www/hogehoge/hogehoge');
|
197
|
+
|
198
|
+
|
199
|
+
// Tasks
|
200
|
+
|
201
|
+
desc('プロジェクト名');
|
202
|
+
|
203
|
+
task('deploy', [
|
204
|
+
|
205
|
+
'deploy:prepare',
|
206
|
+
|
207
|
+
// 'deploy:lock',
|
208
|
+
|
209
|
+
'deploy:release',
|
210
|
+
|
211
|
+
'deploy:update_code',
|
212
|
+
|
213
|
+
'deploy:shared',
|
214
|
+
|
215
|
+
'deploy:writable',
|
216
|
+
|
217
|
+
'deploy:vendors',
|
218
|
+
|
219
|
+
'deploy:clear_paths',
|
220
|
+
|
221
|
+
'deploy:symlink',
|
222
|
+
|
223
|
+
'deploy:unlock',
|
224
|
+
|
225
|
+
'cleanup',
|
226
|
+
|
227
|
+
'success'
|
228
|
+
|
229
|
+
]);
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
// [Optional] if deploy fails automatically unlock.
|
234
|
+
|
235
|
+
//after('deploy:failed', 'deploy:unlock');
|
236
|
+
|
237
|
+
```
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
下記は実際に実際にデプロイした時のコマンドです。
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
```bash
|
246
|
+
|
247
|
+
dep deploy
|
248
|
+
|
249
|
+
#OR
|
250
|
+
|
251
|
+
dep deploy production
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
#エラーが出る時は
|
256
|
+
|
257
|
+
dep deploy -vvv production
|
258
|
+
|
259
|
+
```
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
うまくいけば、デプロイ先サーバーの下記パスにソースが置かれます。
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
```
|
268
|
+
|
269
|
+
ls /var/www/hogehoge/hogehoge/current/ #下記のシンボリックリンク
|
270
|
+
|
271
|
+
ls /var/www/hogehoge/hogehoge/releases/1
|
188
272
|
|
189
273
|
```
|
190
274
|
|
@@ -194,7 +278,7 @@
|
|
194
278
|
|
195
279
|
|
196
280
|
|
197
|
-
ローカルのSSHに公開キー設定をしてパスフレーズなしでSSH接続できるように`ssh-agent`を使用するか、`keychain`をインストールして対応します。
|
281
|
+
ローカルのSSHに公開キー設定をしてパスフレーズなしでSSH接続できるように`ssh-agent`を使用するか、`keychain`をインストールして対応します。
|
198
282
|
|
199
283
|
|
200
284
|
|
@@ -302,17 +386,17 @@
|
|
302
386
|
|
303
387
|
|
304
388
|
|
305
|
-
if [ -
|
389
|
+
if [ -d "$HOME/.keychain" ]; then
|
306
390
|
|
307
391
|
#デプロイ先サーバー用SSH鍵
|
308
392
|
|
309
|
-
[ -f "
|
393
|
+
[ -f "$HOME/.ssh/id_rsa" ] && /usr/bin/keychain ~/.ssh/id_rsa
|
310
394
|
|
311
395
|
|
312
396
|
|
313
397
|
#Bitbucket用SSH鍵
|
314
398
|
|
315
|
-
[ -f "
|
399
|
+
[ -f "$HOME/.ssh/bitbucket/id_rsa" ] && /usr/bin/keychain ~/.ssh/bitbucket/id_rsa
|
316
400
|
|
317
401
|
|
318
402
|
|
@@ -334,8 +418,8 @@
|
|
334
418
|
|
335
419
|
```bash
|
336
420
|
|
337
|
-
ssh -T
|
421
|
+
ssh -T bitbucket.org
|
338
|
-
|
422
|
+
|
339
|
-
ssh u
|
423
|
+
ssh production
|
340
|
-
|
424
|
+
|
341
|
-
```
|
425
|
+
```
|