citasks 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/citasks/ci_lib.rb +27 -9
  3. data/lib/citasks.rb +43 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68e80bae84d161e9ec3395316758e1e24c3295cc
4
- data.tar.gz: ad54f1b7d33346ca68d22a3de1e327c81710f2ff
3
+ metadata.gz: 957bcedfb3611c100ccab26a6d4f4b568f81e239
4
+ data.tar.gz: 41d396cf38779faa1140efce7fb14e8a872b718d
5
5
  SHA512:
6
- metadata.gz: 2023994cd9fc1842d026939c64c0ae94b24ede895ff15a31cd3e39c0e473b11e76f01e1ddec64b5b5817518f0a943b633856ebf1eb5c63f96290adb2c549cfad
7
- data.tar.gz: 713d0e13accb077b129a33514cb312c56a1675e08be3ee3f327abd6db1797fa921830c1380ca071fae9b6c96e6b6c83d5502441fcd28c2cdffb0244a2ed0274c
6
+ metadata.gz: 7b2221814042be344743e0adb8510b75ba99446c434bf4bce40340fe582f39cf7ce2296acd63eac5580517a22e38ea0d6960204580c9756d12326f91780746fe
7
+ data.tar.gz: 1f5b95da5d069ab0c8def0825e245441d2180c159daa52284d4aa10e4a2100a14d74ef97e7ce506940a7bc2d29fa5a0589265091ea83539d69d9185be3b44a68
@@ -8,6 +8,20 @@ def _write fullpath, content
8
8
  end
9
9
  end
10
10
 
11
+ def token_shared_persistently
12
+ #create a shared token across tasks
13
+ secret_token_file = ".token"
14
+ if File.exists? secret_token_file
15
+ token = File.read secret_token_file
16
+ else
17
+ token = SecureRandom.uuid
18
+ File.open secret_token_file, "w" do |fh|
19
+ fh.puts token
20
+ end
21
+ end
22
+ token
23
+ end
24
+
11
25
  module JenkinsTools
12
26
  WORKFLOW_PLUGIN = ENV["WORKFLOW_PLUGIN"] || "workflow-job@2.14.1"
13
27
  GITLAB_PLUGIN = ENV["GITLAB_PLUGIN"] || "gitlab-plugin@1.4.7"
@@ -15,8 +29,10 @@ module JenkinsTools
15
29
  GIT_PLUGIN = ENV["GIT_PLUGIN"] || "git@3.4.0"
16
30
 
17
31
  # git_repo_url = http://virtuous-porcupine-gitlab-ce/wenzm/icp-static-web.git, gitlab-wenzm-password
18
- def self.gen_job_xml job_name, xml_file_name, git_repo_url, repo_credential_id_in_jenkins,token_to_trigger_build_remotely = SecureRandom.uuid
19
- secret_token = "{AQAAABAAAAAQ76W/e/wjLSZ6yxDaU6oaB3rUABFZ/jw6NVzpJkLGL/8=}" #empty??? TODO
32
+ def self.gen_job_xml job_name, xml_file_name, git_repo_url, repo_credential_id_in_jenkins, secret_token=nil
33
+ secret_token = token_shared_persistently if secret_token.nil?
34
+
35
+ token_to_trigger_build_remotely = SecureRandom.uuid
20
36
  _write xml_file_name, <<~EOF
21
37
  <?xml version='1.0' encoding='UTF-8'?>
22
38
  <flow-definition plugin="#{WORKFLOW_PLUGIN}">
@@ -45,7 +61,7 @@ module JenkinsTools
45
61
  <includeBranchesSpec></includeBranchesSpec>
46
62
  <excludeBranchesSpec></excludeBranchesSpec>
47
63
  <targetBranchRegex></targetBranchRegex>
48
- <!-- <secretToken>#{secret_token}</secretToken> -->
64
+ <secretToken>#{secret_token}</secretToken>
49
65
  </com.dabsquared.gitlabjenkins.GitLabPushTrigger>
50
66
  </triggers>
51
67
  </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
@@ -163,14 +179,16 @@ module GitlabTools
163
179
  Gitlab.create_project repo_name
164
180
  end
165
181
 
166
- def self.setup_hook repo_name, gitlab_url, token, hooked_url, secret_token_for_hooked_url=nil
182
+ def self.setup_hook repo_name, gitlab_url, token, hooked_url, secret_token=nil
167
183
  _setup_gitlab gitlab_url, token
168
184
 
169
185
  project = Gitlab.projects.find do |p|
170
186
  p.name== repo_name
171
187
  end
188
+
189
+ secret_token = token_shared_persistently if secret_token.nil?
172
190
 
173
- Gitlab.add_project_hook project.id, hooked_url, :push_events => 1,:enable_ssl_verification=>0, :token=> secret_token_for_hooked_url
191
+ Gitlab.add_project_hook project.id, hooked_url, :push_events => 1,:enable_ssl_verification=>0, :token=> secret_token
174
192
 
175
193
  end
176
194
 
@@ -219,7 +237,7 @@ module Builder
219
237
  sprintf("%02d", @task_index)
220
238
  end
221
239
 
222
- def rest_task_index
240
+ def reset_task_index
223
241
  @task_index = 0
224
242
  end
225
243
  EOF
@@ -323,7 +341,7 @@ module Builder
323
341
  tag=ENV["BUILD_NUMBER"]||"B1"
324
342
 
325
343
  namespace "docker" do
326
- rest_task_index
344
+ reset_task_index
327
345
 
328
346
  desc "build docker image"
329
347
  task "\#{next_task_index}_build_image" do
@@ -333,12 +351,12 @@ module Builder
333
351
  desc "push to ICp registry"
334
352
  task "\#{next_task_index}_push_to_ICp_registry" do
335
353
  DockerTools.add_etc_hosts
336
- DockerTools.push_to_registry image_name, tag_name
354
+ DockerTools.push_to_registry image_name, tag
337
355
  end
338
356
  end
339
357
 
340
358
  namespace "k8s" do
341
- rest_task_index
359
+ reset_task_index
342
360
 
343
361
  desc "deploy into k8s"
344
362
  task "\#{next_task_index}_deploy_to_k8s" do
data/lib/citasks.rb CHANGED
@@ -1,6 +1,49 @@
1
1
  require_relative "citasks/ci_lib"
2
2
  require_relative "citasks/task_index"
3
3
 
4
+ namespace "init" do
5
+ @task_index = 0
6
+ desc "create initial .env file"
7
+ task "#{next_task_index}_env", [:project_name] do |t, args|
8
+ project =args.project_name
9
+ File.open ".env", "w" do |fh|
10
+ content = <<~EOF
11
+ GITLAB_USER = wenzm
12
+
13
+ #URL to access out side of k8s cluster
14
+ GITLAB_BASE_URL = http://localhost:30139
15
+ GITLAB_IN_CLUSTER_BASE_URL = http://hopping-marsupial-gitlab-ce
16
+ GITLAB_API_TOKEN = KDbJwWZxXYkKVmGhFSN3
17
+
18
+ JENKINS_URL = http://localhost:30003
19
+ JENKINS_IN_CLUSTER_URL = http://interesting-orangutan-jenkins:8080
20
+ JENKINS_GIT_USER_CREDENTIAL_ID = gitlab-wenzm-password
21
+
22
+ JENKINS_USER = wenzm
23
+ JENKINS_USER_API_TOKEN = f432de6a2fbeaaf58757f76194dcd825
24
+
25
+ JOB_NAME=#{project}
26
+ REPO_NAME=#{project}
27
+
28
+ COMPILER_DOCKER_IMAGE=maven:3.5-jdk-8
29
+
30
+ #for private docker registry
31
+ ICP_MASTER_IP=192.168.10.100
32
+ EOF
33
+
34
+ fh.puts content
35
+ end
36
+
37
+ File.open ".gitignore", "w" do |fh|
38
+ content =<<~EOF
39
+ .token
40
+ EOF
41
+
42
+ fh.puts content
43
+ end
44
+ end
45
+ end
46
+
4
47
  namespace "Jenkins" do
5
48
  @task_index = 0
6
49
  job_name = ENV["JOB_NAME"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: citasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zhimin Wen