magellan-log-funnel 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.jenkins/gcscache.groovy +165 -0
- data/.jenkins/slack.groovy +25 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +24 -23
- data/Jenkinsfile +83 -0
- data/lib/magellan/log_funnel/version.rb +1 -1
- data/magellan-log-funnel.gemspec +1 -5
- metadata +7 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8ba4aa26ed4f28020b44558d4a9b9aebb8ea2693fef7011634206bb49e027333
|
4
|
+
data.tar.gz: bd4800ceb493f251df099fb230b8c95f8c674260699b7f0e8f854b57260b9c87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0daf4374a8e920c6b15d8ba779ace279f692bd64adfa6b0de6036762f7a9a441c5805da247f790207df81b95ef81457df81cefcce10ec18c4fc2af04940e98c1
|
7
|
+
data.tar.gz: cef2f2d522abf28c7d5a147e3c89a9a8df7c07666cd59080f7d4b5cc3e8606a851f805506c572406241dda76f6f4573ae5cd36cf3360040c274c57178b2ff6df
|
data/.gitignore
CHANGED
@@ -0,0 +1,165 @@
|
|
1
|
+
import groovy.transform.Field
|
2
|
+
|
3
|
+
// ビルドキャッシュ用のバケット
|
4
|
+
// https://console.cloud.google.com/storage/browser/magellan-ci-jenkins-cache?project=magellan-ci&organizationId=77670238700
|
5
|
+
@Field def bucket_name = 'magellan-ci-jenkins-cache'
|
6
|
+
|
7
|
+
def cache_dir(){
|
8
|
+
// gcsfuse でマウントされた GCS バケットの、Jenkins のジョブごとに分けられたディレクトリ。
|
9
|
+
// 各ジョブのキャッシュファイルはこのディレクトリ以下に置く。
|
10
|
+
// キャッシュファイルのフルパスは gen_cache_file() で生成する。
|
11
|
+
return "/gcs/${bucket_name}/jobs/${job_name()}/files"
|
12
|
+
}
|
13
|
+
|
14
|
+
def job_name(){
|
15
|
+
if (env.BRANCH_NAME && env.JOB_BASE_NAME) {
|
16
|
+
// Multi-Branch Pipeline の場合
|
17
|
+
// JOB_NAME には "magellan-maneuvers/xxx/features%2Fjenkins-cache-gcs" のような
|
18
|
+
// Jenkins の絶対プロジェクト名が入っているので、"magellan-maneuvers/xxx" を返します。
|
19
|
+
return env.JOB_NAME - ('/' + env.JOB_BASE_NAME)
|
20
|
+
} else {
|
21
|
+
// Multi-Branch Pipeline 以外の場合
|
22
|
+
// Jenkins の絶対プロジェクト名をそのまま返します。
|
23
|
+
return env.JOB_NAME
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
// キャッシュファイルのフルパスを返す
|
28
|
+
def gen_cache_file(Map params = [:]){
|
29
|
+
def prefix = params.prefix
|
30
|
+
def lockfile = params.lockfile
|
31
|
+
def suffix = params.suffix ?: 'tar.gz'
|
32
|
+
|
33
|
+
if (lockfile){
|
34
|
+
def checksum = sha1(lockfile)
|
35
|
+
return "${cache_dir()}/${prefix}_${checksum}.${suffix}"
|
36
|
+
} else {
|
37
|
+
return "${cache_dir()}/${prefix}.${suffix}"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
def cache_exist(cache_file){
|
42
|
+
// gcsfuse 経由でファイルを作成すると、ファイルが存在するが 0 バイト、という状況がありえるので、
|
43
|
+
// -f ではなく -s (ファイルが存在し、かつ大きさが 0 より大きい) を使います。
|
44
|
+
def ret = sh(
|
45
|
+
script: "[ -s ${cache_file} ]",
|
46
|
+
returnStatus: true
|
47
|
+
)
|
48
|
+
return ret == 0
|
49
|
+
}
|
50
|
+
|
51
|
+
// (汎用) キャッシュを展開する
|
52
|
+
def restore_cache(Map params = [:]){
|
53
|
+
def prefix = params.prefix
|
54
|
+
def lockfile = params.lockfile
|
55
|
+
def suffix = params.suffix ?: 'tar.gz'
|
56
|
+
|
57
|
+
if (lockfile) {
|
58
|
+
lockfile = lockfile_in_git(lockfile)
|
59
|
+
}
|
60
|
+
def cache_file = gen_cache_file(prefix: prefix, lockfile: lockfile, suffix: suffix)
|
61
|
+
|
62
|
+
if (cache_exist(cache_file)){
|
63
|
+
switch(suffix){
|
64
|
+
case 'tar.zst':
|
65
|
+
// TODO: tar コマンドが zstd をサポートすると不要になる。具体的には debian-10 buster では不要になる
|
66
|
+
sh "zstdcat ${cache_file} | tar xf -"
|
67
|
+
break
|
68
|
+
default:
|
69
|
+
sh "tar xf ${cache_file}"
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
// (汎用) キャッシュを作成する
|
75
|
+
def save_cache(Map params = [:]){
|
76
|
+
def prefix = params.prefix
|
77
|
+
def lockfile = params.lockfile
|
78
|
+
def targets = params.targets
|
79
|
+
def suffix = params.suffix ?: 'tar.gz'
|
80
|
+
|
81
|
+
if (lockfile) {
|
82
|
+
lockfile = lockfile_in_git(lockfile)
|
83
|
+
}
|
84
|
+
def cache_file = gen_cache_file(prefix: prefix, lockfile: lockfile, suffix: suffix)
|
85
|
+
|
86
|
+
// キャッシュが存在しない場合だけでなく、lockfile が git リポジトリに含まれていない場合もキャッシュを作成(or更新)します。
|
87
|
+
if (!lockfile || !cache_exist(cache_file)) {
|
88
|
+
// cache_file は cache_dir 直下のファイルとは限らないので、cache_file の dirname に対して mkdir します。
|
89
|
+
sh "mkdir -p \$(dirname ${cache_file})"
|
90
|
+
switch(suffix){
|
91
|
+
case 'tar.zst':
|
92
|
+
// TODO: tar コマンドが zstd をサポートすると不要になる。具体的には debian-10 buster では不要になる
|
93
|
+
sh "tar cf - ${targets.join(' ')} | zstd - -o ${cache_file} -f"
|
94
|
+
break
|
95
|
+
default:
|
96
|
+
sh "tar cf ${cache_file} -a ${targets.join(' ')}"
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
// lockfile が git リポジトリ内にあるファイルならファイル名を返し、
|
102
|
+
// git リポジトリ内になければ null を返します。
|
103
|
+
def lockfile_in_git(lockfile){
|
104
|
+
def git_ls_files = sh(
|
105
|
+
script: "git ls-files ${lockfile}",
|
106
|
+
returnStdout: true
|
107
|
+
).trim()
|
108
|
+
return lockfile == git_ls_files ? lockfile : null
|
109
|
+
}
|
110
|
+
|
111
|
+
// bundler 用のキャッシュを展開する
|
112
|
+
def restore_bundler_cache(Map params = [:]){
|
113
|
+
def prefix = params.prefix ?: 'bundler'
|
114
|
+
def lockfile = params.lockfile ?: 'Gemfile.lock'
|
115
|
+
def suffix = params.suffix ?: 'tar.gz'
|
116
|
+
|
117
|
+
prefix = "${prefix}_ruby-${ruby_api_version()}"
|
118
|
+
|
119
|
+
restore_cache(prefix: prefix, lockfile: lockfile, suffix: suffix)
|
120
|
+
}
|
121
|
+
|
122
|
+
// bundler 用のキャッシュを作成する
|
123
|
+
def save_bundler_cache(Map params = [:]){
|
124
|
+
def prefix = params.prefix ?: 'bundler'
|
125
|
+
def lockfile = params.lockfile ?: 'Gemfile.lock'
|
126
|
+
def targets = params.targets ?: ['vendor/bundle']
|
127
|
+
def suffix = params.suffix ?: 'tar.gz'
|
128
|
+
|
129
|
+
prefix = "${prefix}_ruby-${ruby_api_version()}"
|
130
|
+
|
131
|
+
save_cache(prefix: prefix, lockfile: lockfile, targets: targets, suffix: suffix)
|
132
|
+
}
|
133
|
+
|
134
|
+
// Ruby の API バージョンを返します。
|
135
|
+
def ruby_api_version(){
|
136
|
+
if (is_in_docker_container()){
|
137
|
+
// Docker コンテナ上の場合
|
138
|
+
return sh(
|
139
|
+
script: '''
|
140
|
+
ruby -e "puts RbConfig::CONFIG[%(ruby_version)]"
|
141
|
+
''',
|
142
|
+
returnStdout: true
|
143
|
+
).trim()
|
144
|
+
} else {
|
145
|
+
// VM 上の場合 (rbenv でインストールした ruby を使う)
|
146
|
+
return sh(
|
147
|
+
script: '''
|
148
|
+
bash -lc 'ruby -e "puts RbConfig::CONFIG[%(ruby_version)]"'
|
149
|
+
''',
|
150
|
+
returnStdout: true
|
151
|
+
).trim()
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
// Docker コンテナ内かどうかを判定します。
|
156
|
+
def is_in_docker_container(){
|
157
|
+
// 参考: https://github.com/chef/ohai/blob/15.1.0/lib/ohai/plugins/linux/virtualization.rb#L190-L228
|
158
|
+
def ret = sh(
|
159
|
+
script: '[ -f /.dockerenv -o -f /.dockerinit ]',
|
160
|
+
returnStatus: true
|
161
|
+
)
|
162
|
+
return ret == 0
|
163
|
+
}
|
164
|
+
|
165
|
+
return this
|
@@ -0,0 +1,25 @@
|
|
1
|
+
def slackNotify(){
|
2
|
+
// BUILD_NUMBER が 1 のとき(つまり新しいブランチをpushしたとき、Pull Requestを作ったときのビルド)で、
|
3
|
+
// currentBuild.currentResult が SUCCESS のときは通知しない
|
4
|
+
if (env.BUILD_NUMBER == '1' && currentBuild.currentResult == 'SUCCESS') {
|
5
|
+
return
|
6
|
+
}
|
7
|
+
// https://github.com/jenkinsci/slack-plugin/issues/327
|
8
|
+
def durationString = currentBuild.durationString.replace(' and counting', '')
|
9
|
+
// Slack 通知するときのメッセージ
|
10
|
+
def notificationMessage = "${env.JOB_NAME} - ${currentBuild.displayName} ${currentBuild.currentResult} after ${durationString} (<${env.RUN_DISPLAY_URL}|Open>)"
|
11
|
+
// Slack 通知するときの色 (ref: https://api.slack.com/docs/message-attachments)
|
12
|
+
def notificationColor = 'warning'
|
13
|
+
switch(currentBuild.currentResult){
|
14
|
+
case 'SUCCESS':
|
15
|
+
notificationColor = 'good'
|
16
|
+
break
|
17
|
+
case ['FAILURE', 'UNSTABLE']:
|
18
|
+
notificationColor = 'danger'
|
19
|
+
break
|
20
|
+
}
|
21
|
+
// Slack 通知
|
22
|
+
slackSend color: notificationColor, message: notificationMessage
|
23
|
+
}
|
24
|
+
|
25
|
+
return this
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,37 +1,38 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
magellan-log-funnel (1.
|
5
|
-
fluent-logger
|
4
|
+
magellan-log-funnel (1.2.0)
|
5
|
+
fluent-logger
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
diff-lcs (1.
|
11
|
-
fluent-logger (0.
|
12
|
-
msgpack (>=
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
rspec-
|
18
|
-
rspec-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
rspec-expectations (3.0.4)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
fluent-logger (0.8.2)
|
12
|
+
msgpack (>= 1.0.0, < 2)
|
13
|
+
msgpack (1.3.3)
|
14
|
+
rake (13.0.1)
|
15
|
+
rspec (3.9.0)
|
16
|
+
rspec-core (~> 3.9.0)
|
17
|
+
rspec-expectations (~> 3.9.0)
|
18
|
+
rspec-mocks (~> 3.9.0)
|
19
|
+
rspec-core (3.9.1)
|
20
|
+
rspec-support (~> 3.9.1)
|
21
|
+
rspec-expectations (3.9.0)
|
23
22
|
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
-
rspec-support (~> 3.
|
25
|
-
rspec-mocks (3.
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
rspec-support (~> 3.9.0)
|
24
|
+
rspec-mocks (3.9.1)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.9.0)
|
27
|
+
rspec-support (3.9.2)
|
29
28
|
|
30
29
|
PLATFORMS
|
31
30
|
ruby
|
32
31
|
|
33
32
|
DEPENDENCIES
|
34
|
-
bundler (~> 1.6)
|
35
33
|
magellan-log-funnel!
|
36
|
-
rake
|
37
|
-
rspec
|
34
|
+
rake
|
35
|
+
rspec
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
1.17.3
|
data/Jenkinsfile
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
def slack
|
2
|
+
def gcscache
|
3
|
+
|
4
|
+
pipeline {
|
5
|
+
agent none
|
6
|
+
options {
|
7
|
+
// 古いビルドを破棄 (daysToKeepStr: ビルドの保存日数, numToKeepStr: ビルドの保存最大数)
|
8
|
+
buildDiscarder(logRotator(numToKeepStr: '30'))
|
9
|
+
}
|
10
|
+
stages {
|
11
|
+
stage('load groovy scripts'){
|
12
|
+
agent any
|
13
|
+
steps {
|
14
|
+
script {
|
15
|
+
slack = load('.jenkins/slack.groovy')
|
16
|
+
gcscache = load('.jenkins/gcscache.groovy')
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
stage('test') {
|
21
|
+
agent {
|
22
|
+
// docker でテストするしDBは使わないので、ビルド環境は unittest でも functest でもいい
|
23
|
+
docker {
|
24
|
+
image 'ruby:2.4'
|
25
|
+
label 'unittest||functest'
|
26
|
+
args "-v ${gcscache.cache_dir()}:${gcscache.cache_dir()}"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
environment {
|
30
|
+
// docker を使うと HOME=/ になって、bundler が以下の警告を出すので対策
|
31
|
+
// `/` is not writable.
|
32
|
+
// Bundler will use `/tmp/bundler/home/unknown' as your home directory temporarily.
|
33
|
+
HOME = "${env.WORKSPACE}"
|
34
|
+
}
|
35
|
+
steps {
|
36
|
+
// ビルド環境の確認
|
37
|
+
sh '''
|
38
|
+
export -p
|
39
|
+
gem env
|
40
|
+
bundle --version
|
41
|
+
'''
|
42
|
+
|
43
|
+
sh 'rm -rf vendor/bundle'
|
44
|
+
|
45
|
+
script {
|
46
|
+
// GCS から vendor/bundle を展開
|
47
|
+
gcscache.restore_bundler_cache()
|
48
|
+
}
|
49
|
+
|
50
|
+
// bundle install
|
51
|
+
sh '''
|
52
|
+
bundle check --path=vendor/bundle || \
|
53
|
+
bundle install --jobs=4 --deployment --path=vendor/bundle
|
54
|
+
bundle config
|
55
|
+
bundle show --paths
|
56
|
+
'''
|
57
|
+
|
58
|
+
script {
|
59
|
+
// GCS 上に vendor/bundle を格納
|
60
|
+
gcscache.save_bundler_cache()
|
61
|
+
}
|
62
|
+
|
63
|
+
// テスト
|
64
|
+
sh 'bundle exec rake spec'
|
65
|
+
}
|
66
|
+
post {
|
67
|
+
cleanup {
|
68
|
+
cleanWs()
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
post {
|
74
|
+
changed {
|
75
|
+
// Slack にビルド結果を通知
|
76
|
+
script {
|
77
|
+
slack.slackNotify()
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
/* vim:set ft=groovy: */
|
data/magellan-log-funnel.gemspec
CHANGED
@@ -19,9 +19,5 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_runtime_dependency "fluent-logger"
|
23
|
-
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
-
spec.add_development_dependency "rspec"
|
22
|
+
spec.add_runtime_dependency "fluent-logger"
|
27
23
|
end
|
metadata
CHANGED
@@ -1,65 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magellan-log-funnel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- t-chikanaga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluent-logger
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.4.9
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.4.9
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.6'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.6'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '10.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '10.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
15
|
requirement: !ruby/object:Gem::Requirement
|
58
16
|
requirements:
|
59
17
|
- - ">="
|
60
18
|
- !ruby/object:Gem::Version
|
61
19
|
version: '0'
|
62
|
-
type: :
|
20
|
+
type: :runtime
|
63
21
|
prerelease: false
|
64
22
|
version_requirements: !ruby/object:Gem::Requirement
|
65
23
|
requirements:
|
@@ -75,8 +33,11 @@ extensions: []
|
|
75
33
|
extra_rdoc_files: []
|
76
34
|
files:
|
77
35
|
- ".gitignore"
|
36
|
+
- ".jenkins/gcscache.groovy"
|
37
|
+
- ".jenkins/slack.groovy"
|
78
38
|
- Gemfile
|
79
39
|
- Gemfile.lock
|
40
|
+
- Jenkinsfile
|
80
41
|
- LICENSE.txt
|
81
42
|
- README.md
|
82
43
|
- Rakefile
|
@@ -106,8 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
67
|
- !ruby/object:Gem::Version
|
107
68
|
version: '0'
|
108
69
|
requirements: []
|
109
|
-
|
110
|
-
rubygems_version: 2.4.6
|
70
|
+
rubygems_version: 3.1.2
|
111
71
|
signing_key:
|
112
72
|
specification_version: 4
|
113
73
|
summary: log collector for magellanic cloud service.
|