rabbit-slide-znz-rubykansai78-gitlab-dokku 2017.07.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rabbit +1 -0
- data/README.md +23 -0
- data/Rakefile +17 -0
- data/config.yaml +21 -0
- data/gitlab-dokku.md +313 -0
- data/pdf/rubykansai78-gitlab-dokku-gitlab-dokku.pdf +0 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6aaa7602f8bac66add9f23a896531864a244f35
|
4
|
+
data.tar.gz: e6f4a17a1cc56c069960c291eb48bc88bc3abc4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 685c3a0bdfb4f12752e956b25e6cbc4483a5638873d21b9a92348dc3377b1d88b941cae5900bd95a8aa38cf2787694c331a3d877a31e94fd4514ac1c042049dd
|
7
|
+
data.tar.gz: 02e2bcf63fa976ff740457e7460e42b09266778abaeca18738b043b332e630ce8a015ed3b82bd2c096dd39729a3e98a65b04f2ab652f24496de7c0a547141cf9
|
data/.rabbit
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gitlab-dokku.md
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# GitLab + Dokku で作る CI/CD 環境
|
2
|
+
|
3
|
+
GitLab と Dokku を組み合わせて CI/CD 環境を作成する例を紹介します。
|
4
|
+
|
5
|
+
## 作者向け
|
6
|
+
|
7
|
+
### 表示
|
8
|
+
|
9
|
+
rake
|
10
|
+
|
11
|
+
### 公開
|
12
|
+
|
13
|
+
rake publish
|
14
|
+
|
15
|
+
## 閲覧者向け
|
16
|
+
|
17
|
+
### インストール
|
18
|
+
|
19
|
+
gem install rabbit-slide-znz-rubykansai78-gitlab-dokku
|
20
|
+
|
21
|
+
### 表示
|
22
|
+
|
23
|
+
rabbit rabbit-slide-znz-rubykansai78-gitlab-dokku.gem
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rabbit/task/slide"
|
2
|
+
|
3
|
+
# Edit ./config.yaml to customize meta data
|
4
|
+
|
5
|
+
spec = nil
|
6
|
+
Rabbit::Task::Slide.new do |task|
|
7
|
+
spec = task.spec
|
8
|
+
# spec.files += Dir.glob("doc/**/*.*")
|
9
|
+
# spec.files -= Dir.glob("private/**/*.*")
|
10
|
+
# spec.add_runtime_dependency("YOUR THEME")
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Tag #{spec.version}"
|
14
|
+
task :tag do
|
15
|
+
sh("git", "tag", "-a", spec.version.to_s, "-m", "Publish #{spec.version}")
|
16
|
+
sh("git", "push", "--tags")
|
17
|
+
end
|
data/config.yaml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
id: rubykansai78-gitlab-dokku
|
3
|
+
base_name: gitlab-dokku
|
4
|
+
tags:
|
5
|
+
- gitlab
|
6
|
+
- dokku
|
7
|
+
presentation_date: 2017/07/29
|
8
|
+
version: 2017.07.29
|
9
|
+
licenses: []
|
10
|
+
slideshare_id: gitlab-dokku-cicd
|
11
|
+
speaker_deck_id: cd-huan-jing
|
12
|
+
ustream_id:
|
13
|
+
vimeo_id:
|
14
|
+
youtube_id:
|
15
|
+
author:
|
16
|
+
markup_language: :markdown
|
17
|
+
name: Kazuhiro NISHIYAMA
|
18
|
+
email: zn@mbf.nifty.com
|
19
|
+
rubygems_user: znz
|
20
|
+
slideshare_user: znzjp
|
21
|
+
speaker_deck_user: znz
|
data/gitlab-dokku.md
ADDED
@@ -0,0 +1,313 @@
|
|
1
|
+
# GitLab + Dokku で作る CI/CD 環境
|
2
|
+
|
3
|
+
author
|
4
|
+
: Kazuhiro NISHIYAMA
|
5
|
+
|
6
|
+
content-source
|
7
|
+
: 第78回 Ruby関西 勉強会
|
8
|
+
|
9
|
+
date
|
10
|
+
: 2017/07/29
|
11
|
+
|
12
|
+
allotted-time
|
13
|
+
: 50m
|
14
|
+
|
15
|
+
theme
|
16
|
+
: lightning-simple
|
17
|
+
|
18
|
+
# 自己紹介
|
19
|
+
|
20
|
+
- 西山和広
|
21
|
+
- id:znz (github, twitter など)
|
22
|
+
- Ruby コミッター
|
23
|
+
|
24
|
+
# GitLab + Dokku
|
25
|
+
|
26
|
+
- GitLab
|
27
|
+
- GitLab CI
|
28
|
+
- Dokku
|
29
|
+
- (+ Heroku)
|
30
|
+
|
31
|
+
# GitLab とは?
|
32
|
+
|
33
|
+
- 簡単にいえば OSS の GitHub クローンのようなもの
|
34
|
+
- Git ホスティング
|
35
|
+
- Merge Request (GitHub の Pull Request)
|
36
|
+
- Issue 管理など色々
|
37
|
+
- GitHub にない機能もある
|
38
|
+
- https://about.gitlab.com/features/
|
39
|
+
|
40
|
+
# GitLab CI とは?
|
41
|
+
|
42
|
+
- Continuous Integration/Continuous Delivery (CI/CD)
|
43
|
+
- Jenkins のジョブを実行しないマスターのようなものが GitLab に組み込み
|
44
|
+
- GitLab Runner (Jenkins の slave のようなもの) を動かすマシンが別途必要
|
45
|
+
- repository の .gitlab-ci.yml で設定 (.travis.yml などと同様)
|
46
|
+
- https://about.gitlab.com/features/gitlab-ci-cd/
|
47
|
+
|
48
|
+
# GitLab Runner とは?
|
49
|
+
|
50
|
+
- マシン上で直接実行する (Shell executor)
|
51
|
+
- Docker の中で実行する (Docker executor)
|
52
|
+
- これを使用
|
53
|
+
- その他
|
54
|
+
- https://docs.gitlab.com/runner/
|
55
|
+
|
56
|
+
# Dokku とは?
|
57
|
+
|
58
|
+
- Docker を使った OSS のミニ Heroku (PaaS)
|
59
|
+
- ssh 経由の git で deploy できる
|
60
|
+
- http://dokku.viewdocs.io/dokku/
|
61
|
+
|
62
|
+
# 組み合わせた状態
|
63
|
+
|
64
|
+
- ブランチに push → Dokku に Review App を deploy
|
65
|
+
- Merge Request をマージ → Review App を停止
|
66
|
+
- master に push → Staging に deploy
|
67
|
+
- 確認後、クリックで Production に deploy
|
68
|
+
- https://about.gitlab.com/features/review-apps/
|
69
|
+
|
70
|
+
# deploy 例
|
71
|
+
|
72
|
+
- https://docs.gitlab.com/ce/ci/examples/deployment/README.html では dpl gem で heroku に deploy する例がある
|
73
|
+
- Dokku との組み合わせは独自研究
|
74
|
+
|
75
|
+
# 組み合わせ方
|
76
|
+
|
77
|
+
- .gitlab-ci.yml で設定する
|
78
|
+
- deploy 用の ssh 秘密鍵などは secret variables に設定
|
79
|
+
|
80
|
+
# .gitlab-ci.yml の設定例
|
81
|
+
|
82
|
+
使用する docker image を指定
|
83
|
+
|
84
|
+
image: ruby:2.3.3
|
85
|
+
|
86
|
+
Rails アプリなので https://hub.docker.com/r/_/ruby/ を使用
|
87
|
+
|
88
|
+
# cache
|
89
|
+
|
90
|
+
per-branch caching:
|
91
|
+
|
92
|
+
cache:
|
93
|
+
key: "$CI_COMMIT_REF_NAME"
|
94
|
+
untracked: true
|
95
|
+
|
96
|
+
https://docs.gitlab.com/ce/ci/yaml/#cache-key
|
97
|
+
|
98
|
+
# テスト用 variables
|
99
|
+
|
100
|
+
services で指定する postgres image で使用
|
101
|
+
(`DATABASE_URL` は Rails で使用)
|
102
|
+
|
103
|
+
variables:
|
104
|
+
# for test
|
105
|
+
POSTGRES_DB: dbname
|
106
|
+
POSTGRES_USER: dbuser
|
107
|
+
POSTGRES_PASSWORD: dbpass
|
108
|
+
DATABASE_URL: "postgres://dbuser:dbpass@postgres:5432/dbname"
|
109
|
+
|
110
|
+
https://hub.docker.com/r/_/postgres/
|
111
|
+
|
112
|
+
# deploy 用 variables
|
113
|
+
|
114
|
+
# for deploy
|
115
|
+
DOKKU: ssh dokku@$DOKKU_HOST
|
116
|
+
APP_NAME: $CI_ENVIRONMENT_SLUG
|
117
|
+
DB_NAME: $CI_ENVIRONMENT_SLUG-database
|
118
|
+
|
119
|
+
- DOKKU はあとで短く表記するため
|
120
|
+
- APP_NAME は Dokku でのアプリ名 (サブドメイン名)
|
121
|
+
- DB_NAME はデータベースコンテナ名 (内部用なので識別できれば何でも良い)
|
122
|
+
|
123
|
+
# stages
|
124
|
+
|
125
|
+
stages:
|
126
|
+
- test
|
127
|
+
- review
|
128
|
+
- staging
|
129
|
+
- production
|
130
|
+
|
131
|
+
- ブランチに push → test → review
|
132
|
+
- master に push → test → staging → production (後述の例 (1))
|
133
|
+
- master に push → test → staging / タグを push → test → production (後述の例 (2))
|
134
|
+
|
135
|
+
# before_script
|
136
|
+
|
137
|
+
before_script:
|
138
|
+
- 'apt-get update -qq && apt-get -o dir::cache::archives="/cache/apt"
|
139
|
+
install -y -qq sqlite3 libsqlite3-dev nodejs'
|
140
|
+
- gem install bundler --no-ri --no-rdoc
|
141
|
+
- bundle install --jobs $(nproc) --path=/cache/bundler
|
142
|
+
- ln -nfs .test.env .env
|
143
|
+
|
144
|
+
- 開発環境に合わせてテスト環境でも sqlite3 が必要
|
145
|
+
- js runtime も必要なので nodejs
|
146
|
+
- インストール時に /cache を使用
|
147
|
+
- dotenv (dotenv-rails) でテスト用環境変数設定
|
148
|
+
|
149
|
+
# .before_ssh
|
150
|
+
|
151
|
+
.before_ssh: &before_ssh
|
152
|
+
# https://docs.gitlab.com/ce/ci/ssh_keys/README.html
|
153
|
+
- 'which ssh-agent || ( apt-get update -y && apt-get -o
|
154
|
+
dir::cache::archives="/cache/apt" install -y openssh-client )'
|
155
|
+
- eval $(ssh-agent -s)
|
156
|
+
- ssh-add <(echo "$SSH_PRIVATE_KEY")
|
157
|
+
- mkdir -p ~/.ssh
|
158
|
+
# Set `ssh-keyscan $DOKKU_HOST` to SSH_SERVER_HOSTKEYS
|
159
|
+
- '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'
|
160
|
+
- '[[ -f /.dockerenv ]] && echo "$SSH_CONFIG" > ~/.ssh/config'
|
161
|
+
|
162
|
+
- .で始まるキーは後で参照する用途に使える
|
163
|
+
- Dokku や Heroku に ssh で git push するときの前処理
|
164
|
+
- secret variables から ssh-agent に秘密鍵と known_hosts と ssh config を設定
|
165
|
+
|
166
|
+
# .deploy_script
|
167
|
+
|
168
|
+
.deploy_script: &deploy_script
|
169
|
+
- $DOKKU apps:create $APP_NAME || echo $?
|
170
|
+
# require `sudo dokku plugin:install https://github.com/dokku/dokku-postgres`
|
171
|
+
- $DOKKU postgres:create $DB_NAME || echo $?
|
172
|
+
- $DOKKU postgres:link $DB_NAME $APP_NAME || echo $?
|
173
|
+
- $DOKKU config:set --no-restart $APP_NAME TZ=Asia/Tokyo
|
174
|
+
RAILS_SERVE_STATIC_FILES=1 NO_FORCE_SSL=1 RACK_DEV_MARK_ENV=review
|
175
|
+
- git push dokku@$DOKKU_HOST:$APP_NAME HEAD:refs/heads/master
|
176
|
+
- $DOKKU -tt run $APP_NAME bundle exec rake db:seed
|
177
|
+
|
178
|
+
- app と db がなければ作成
|
179
|
+
- TZ などの環境変数設定
|
180
|
+
- HEAD:refs/heads/master という指定で push
|
181
|
+
- -tt で強制的に tty を確保して rake db:seed
|
182
|
+
|
183
|
+
# rake test
|
184
|
+
|
185
|
+
rake:
|
186
|
+
stage: test
|
187
|
+
services:
|
188
|
+
- postgres:latest
|
189
|
+
script:
|
190
|
+
- bundle exec rake db:setup RAILS_ENV=test
|
191
|
+
- bundle exec rake
|
192
|
+
|
193
|
+
- services に指定した postgres image とリンクした状態で実行
|
194
|
+
- データベースの初期設定をしてテスト実行
|
195
|
+
|
196
|
+
# staging deploy (1)
|
197
|
+
|
198
|
+
staging:
|
199
|
+
stage: staging
|
200
|
+
variables:
|
201
|
+
APP_NAME: hello-app-staging.example.jp
|
202
|
+
before_script: *before_ssh
|
203
|
+
script:
|
204
|
+
- git push dokku@$PRODUCTION_DOKKU_HOST:$APP_NAME HEAD:refs/heads/master
|
205
|
+
environment:
|
206
|
+
name: staging
|
207
|
+
url: https://hello-app-staging.example.jp/
|
208
|
+
only:
|
209
|
+
- master
|
210
|
+
|
211
|
+
- before_script は sqlite3 のインストールなどの代わりに ssh 設定
|
212
|
+
- Pipelines の Environments からリンク
|
213
|
+
- master に push したときのみ
|
214
|
+
|
215
|
+
# production deploy (1)
|
216
|
+
|
217
|
+
production:
|
218
|
+
stage: production
|
219
|
+
variables:
|
220
|
+
APP_NAME: hello-app.example.jp
|
221
|
+
before_script: *before_ssh
|
222
|
+
script:
|
223
|
+
- git push dokku@$PRODUCTION_DOKKU_HOST:$APP_NAME HEAD:refs/heads/master
|
224
|
+
environment:
|
225
|
+
name: production
|
226
|
+
url: https://hello-app.example.jp/
|
227
|
+
when: manual
|
228
|
+
only:
|
229
|
+
- master
|
230
|
+
|
231
|
+
- staging の後に手動実行
|
232
|
+
- master に push したときのみ
|
233
|
+
|
234
|
+
# staging deploy (2)
|
235
|
+
|
236
|
+
staging:
|
237
|
+
stage: staging
|
238
|
+
variables:
|
239
|
+
APP_NAME: hello-app-staging
|
240
|
+
script:
|
241
|
+
- gem install dpl
|
242
|
+
- dpl --provider=heroku --app=$APP_NAME --api-key=$HEROKU_STAGING_API_KEY
|
243
|
+
environment:
|
244
|
+
name: staging
|
245
|
+
url: https://$APP_NAME.herokuapp.com/
|
246
|
+
only:
|
247
|
+
- master
|
248
|
+
|
249
|
+
- master に push したときのみ
|
250
|
+
- dpl で heroku に deploy
|
251
|
+
|
252
|
+
# production deploy (2)
|
253
|
+
|
254
|
+
production:
|
255
|
+
stage: production
|
256
|
+
variables:
|
257
|
+
APP_NAME: hello-app
|
258
|
+
script:
|
259
|
+
- gem install dpl
|
260
|
+
- dpl --provider=heroku --app=$APP_NAME --api-key=$HEROKU_PRODUCTION_API_KEY
|
261
|
+
environment:
|
262
|
+
name: production
|
263
|
+
url: https://$APP_NAME.herokuapp.com/
|
264
|
+
only:
|
265
|
+
- tags
|
266
|
+
|
267
|
+
- タグを push したときのみ
|
268
|
+
- dpl で heroku に deploy
|
269
|
+
|
270
|
+
# review deploy
|
271
|
+
|
272
|
+
review:
|
273
|
+
stage: review
|
274
|
+
before_script: *before_ssh
|
275
|
+
script: *deploy_script
|
276
|
+
environment:
|
277
|
+
name: review/$CI_COMMIT_REF_NAME
|
278
|
+
url: http://$CI_ENVIRONMENT_SLUG.$DOKKU_DOMAIN
|
279
|
+
on_stop: stop_review
|
280
|
+
only:
|
281
|
+
- branches
|
282
|
+
except:
|
283
|
+
- master
|
284
|
+
|
285
|
+
- review 用の Dokku アプリを deploy
|
286
|
+
- master 以外のブランチに push したときのみ
|
287
|
+
|
288
|
+
# stop review
|
289
|
+
|
290
|
+
stop_review:
|
291
|
+
stage: review
|
292
|
+
variables:
|
293
|
+
GIT_STRATEGY: none
|
294
|
+
before_script: *before_ssh
|
295
|
+
script:
|
296
|
+
- $DOKKU apps:destroy $CI_ENVIRONMENT_SLUG --force || echo $?
|
297
|
+
- $DOKKU postgres:destroy $CI_ENVIRONMENT_SLUG-database --force || echo $?
|
298
|
+
environment:
|
299
|
+
name: review/$CI_COMMIT_REF_NAME
|
300
|
+
action: stop
|
301
|
+
when: manual
|
302
|
+
only:
|
303
|
+
- branches
|
304
|
+
except:
|
305
|
+
- master
|
306
|
+
|
307
|
+
- postgres は使用中だとエラーになるので apps から停止
|
308
|
+
- リンクも消える
|
309
|
+
|
310
|
+
# まとめ
|
311
|
+
|
312
|
+
- GitLab と Dokku を組み合わせて CI/CD 環境を作成する例を紹介
|
313
|
+
- 環境構築に使っている Ansible Playbook は https://github.com/znz/ansible-playbook-gitlab-dokku
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rabbit-slide-znz-rubykansai78-gitlab-dokku
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2017.07.29
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kazuhiro NISHIYAMA
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rabbit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.2
|
27
|
+
description: GitLab と Dokku を組み合わせて CI/CD 環境を作成する例を紹介します。
|
28
|
+
email:
|
29
|
+
- zn@mbf.nifty.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rabbit"
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- config.yaml
|
38
|
+
- gitlab-dokku.md
|
39
|
+
- pdf/rubykansai78-gitlab-dokku-gitlab-dokku.pdf
|
40
|
+
homepage: http://slide.rabbit-shocker.org/authors/znz/rubykansai78-gitlab-dokku/
|
41
|
+
licenses: []
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.5.2
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: GitLab + Dokku で作る CI/CD 環境
|
63
|
+
test_files: []
|