conjur-debify 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62779275043b6c8ea024b9daacc6676e3360ea9c
4
- data.tar.gz: bf3df3918cd8b4d50677d9d2656ee019cd8d7e33
3
+ metadata.gz: 8855639443d69bd88b95e4c6ba08bf24f2b165ca
4
+ data.tar.gz: f3c6e6d781021d263caa26bdc1f15dbb5abc75d4
5
5
  SHA512:
6
- metadata.gz: 39daa1114f7198fa8502e42abd3a6724eb0f13371fc15347ccb0e38fa1309e1d09010a7cc4276d43a05c534d143ad366889c9e7af0ac910b4a5a37016e4b7d92
7
- data.tar.gz: 144d95e054af19588aa17fc3d9a4c36d2db305e1843a3ad7171bb160fc57377a9d6a1d00bbf0db875c471937547e60132a9145804d6f6588975c7e0a30a281fc
6
+ metadata.gz: 8efa8c22f09f29eaa660f96cb6313b35995774d01f4d735ddb65223fbb3e7e135348e5a9f91670a75e358f458fc63cc7d798c370e898ef1c9bc097c97b19461e
7
+ data.tar.gz: 9e67e5c2496368e1cfb09924263f7ed8adae19b19defc6444bdd3424aacddc1cccfac799c307ffae43c0ed1f14d77523b05c5242f45242ee6d6f876f35318082
data/.dockerignore CHANGED
@@ -1,2 +1 @@
1
- Dockerfile
2
1
  Gemfile.lock
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ features/reports
16
16
  results.html
17
17
  mkmf.log
18
18
  *.deb
19
+ *.gem
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 1.7.0
2
+
3
+ * Read artifactory credentials from the environment
4
+ (`ARTIFACTORY_USER`, `ARTIFACTORY_PASSWORD`), only contact Conjur if
5
+ they're not set.
6
+
7
+ # 1.6.1
8
+
9
+ * Buils a docker image to run debify, convert tests to use it, pipeline build
10
+
1
11
  # 1.6.0
2
12
 
3
13
  * When not on the master branch, `debify publish` uses the branch name as the component name, rather than always using
data/Dockerfile CHANGED
@@ -1,9 +1,42 @@
1
- FROM ruby:2.2.6
1
+ FROM ruby:2.2
2
2
 
3
- RUN mkdir -p /src
4
- WORKDIR /src
3
+ ### DockerInDocker support is take from
4
+ ### https://github.com/jpetazzo/dind/blob/master/Dockerfile . I
5
+ ### elected to base this image on ruby, then pull in the (slightly
6
+ ### outdated) support for DockerInDocker. Creation of the official
7
+ ### docker:dind image much more complicated and didn't lend itself to
8
+ ### also running ruby.
5
9
 
6
- COPY . /src/
7
- RUN bundle
10
+ RUN apt-get update -qq && apt-get install -qqy \
11
+ apt-transport-https \
12
+ ca-certificates \
13
+ curl \
14
+ lxc \
15
+ iptables
16
+
17
+ # Install Docker from Docker Inc. repositories.
18
+ RUN curl -sSL https://get.docker.com/ | sh
8
19
 
9
- ENTRYPOINT ["bundle", "exec", "debify"]
20
+ # Install the magic wrapper.
21
+ RUN curl -sSL -o /usr/local/bin/wrapdocker https://raw.githubusercontent.com/jpetazzo/dind/master/wrapdocker
22
+ RUN chmod +x /usr/local/bin/wrapdocker
23
+
24
+ # Define additional metadata for our image.
25
+ VOLUME /var/lib/docker
26
+
27
+ ### End of DockerInDocker support
28
+
29
+ RUN mkdir -p /debify
30
+ WORKDIR /debify
31
+
32
+ COPY . ./
33
+
34
+ RUN gem build debify.gemspec
35
+
36
+ ARG VERSION
37
+ RUN gem install -N conjur-debify-${VERSION}.gem
38
+
39
+ ARG CONJUR_APPLIANCE_URL
40
+ ENV CONJUR_APPLIANCE_URL ${CONJUR_APPLIANCE_URL:-https://conjur-master-v2.itp.conjur.net/api}
41
+
42
+ ENTRYPOINT ["/debify/distrib/entrypoint.sh"]
data/Jenkinsfile ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env groovy
2
+
3
+ pipeline {
4
+ agent { label 'executor-v2' }
5
+
6
+ options {
7
+ timestamps()
8
+ buildDiscarder(logRotator(daysToKeepStr: '30'))
9
+ skipDefaultCheckout()
10
+ }
11
+
12
+ stages {
13
+ stage('Checkout') {
14
+ steps {
15
+ // One of our cukes tests to see if debify can correctly
16
+ // determine the version for the package being created, based
17
+ // on the tags in the repo. By default, the Git SCM plugin
18
+ // doesn't pull tags, causing the cuke to fail.
19
+ //
20
+ // I couldn't find any way to configure the plugin, so I used
21
+ // the Snippet Generator to create this:
22
+ checkout([$class: 'GitSCM', branches: [[name: env.BRANCH_NAME]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'conjur-jenkins', url: 'git@github.com:conjurinc/debify.git']]])
23
+ }
24
+ }
25
+ stage('Build docker image') {
26
+ steps {
27
+ sh './build.sh'
28
+ }
29
+ }
30
+
31
+ stage('Run feature tests') {
32
+ steps {
33
+ sh './test.sh'
34
+ junit 'features/reports/*.xml'
35
+ }
36
+ }
37
+
38
+ stage('Push Docker image') {
39
+ when {
40
+ branch 'master'
41
+ }
42
+
43
+ steps {
44
+ sh './tag-image.sh'
45
+ sh './push-image.sh'
46
+ }
47
+ }
48
+
49
+ stage('Publish to RubyGems') {
50
+ agent { label 'releaser-v2' }
51
+ when {
52
+ branch 'master'
53
+ }
54
+
55
+ steps {
56
+ checkout scm
57
+ sh './publish-rubygem.sh'
58
+ deleteDir()
59
+ }
60
+ }
61
+ }
62
+
63
+ post {
64
+ always {
65
+ sh 'docker run -i --rm -v $PWD:/src -w /src alpine/git clean -fxd'
66
+ deleteDir()
67
+ }
68
+ failure {
69
+ slackSend(color: 'danger', message: "${env.JOB_NAME} #${env.BUILD_NUMBER} FAILURE (<${env.BUILD_URL}|Open>)")
70
+ }
71
+ unstable {
72
+ slackSend(color: 'warning', message: "${env.JOB_NAME} #${env.BUILD_NUMBER} UNSTABLE (<${env.BUILD_URL}|Open>)")
73
+ }
74
+ }
75
+ }
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## Installation
4
4
 
5
+ There are two different ways of installing debify: as a gem, or as a Docker image.
6
+
7
+ ### Installing the gem
5
8
  Add this line to your application's Gemfile:
6
9
 
7
10
  ```ruby
@@ -9,15 +12,74 @@ gem 'conjur-debify'
9
12
  ```
10
13
 
11
14
  And then execute:
15
+
12
16
  ```sh-session
13
17
  $ bundle
14
18
  ```
15
19
 
16
20
  Or install it yourself as a ruby gem:
21
+
17
22
  ```sh-session
18
23
  $ gem install conjur-debify
19
24
  ```
20
25
 
26
+ ### Installing the Docker image
27
+ Pull the Docker image:
28
+
29
+ ```sh-session
30
+ $ VERSION=1.7.0
31
+ $ docker pull registry.tld/conjurinc/debify:$VERSION
32
+ ```
33
+
34
+ Images are tagged with the version specified in [VERSION](./VERSION)
35
+
36
+ Use the `config` subcommand to get a copy of the wrapper script and the secret definitions for publishing:
37
+
38
+ ```sh-session
39
+ $ docker run --rm debify:$VERSION config script > docker-debify
40
+ $ chmod +x docker-debify
41
+ # Optionally, if publishing a deb
42
+ $ docker run --rm debify:$VERSION config secrets > publishing-secrets.yml
43
+ ```
44
+
45
+ Running `docker-debify` will then start a container configured to run debify:
46
+
47
+ ```sh-session
48
+ $ ./docker-debify help
49
+ NAME
50
+ debify - Utility commands for building and testing Conjur appliance Debian packages
51
+
52
+ SYNOPSIS
53
+ debify [global options] command [command options] [arguments...]
54
+
55
+ VERSION
56
+ 1.7.0
57
+
58
+
59
+ GLOBAL OPTIONS
60
+ --env=arg - Set an environment variable (e.g. TERM=xterm) when starting a container (may be used more than once, default:
61
+ none)
62
+ --help - Show this message
63
+ --[no-]local-bundle - Mount local bundle to reuse gems from previous installation
64
+ --version - Display the program version
65
+
66
+ COMMANDS
67
+ clean - Clean current working directory of non-Git-managed files
68
+ config - Show the given configuration
69
+ detect-version - Auto-detect and print the repository verison
70
+ help - Shows a list of commands or help for one command
71
+ initconfig - Initialize the config file using current global options
72
+ package - Build a debian package for a project
73
+ publish - Publish a debian package to apt repository
74
+ sandbox - Setup a development sandbox for a Conjur debian package in a Conjur appliance container
75
+ test - Test a Conjur debian package in a Conjur appliance container
76
+ ```
77
+
78
+
79
+ Note that debify itself creates images and starts containers, so it
80
+ needs access to the host's `docker.sock`. Additionally, it requires
81
+ that it be started in root directory of the project being packaged.
82
+
21
83
  ## Build a package
22
84
 
23
85
  Builds a Conjur Debian package from a Ruby gem.
@@ -29,7 +91,7 @@ NAME
29
91
 
30
92
  SYNOPSIS
31
93
  debify [global options] package [command options] project_name -- <fpm-arguments>
32
-
94
+ b
33
95
  DESCRIPTION
34
96
  The package is built using fpm (https://github.com/jordansissel/fpm).
35
97
 
@@ -109,43 +171,32 @@ NAME
109
171
  publish - Publish a debian package to apt repository
110
172
 
111
173
  SYNOPSIS
112
- debify [global options] publish [command options] package
174
+ debify [global options] publish [command options] distribution project-name
113
175
 
114
176
  DESCRIPTION
115
- Publishes a deb created with `debify package` to our private apt
116
- repository.
117
-
118
- You can use wildcards to select packages to publish, e.g., debify
119
- publish *.deb.
177
+ Publishes a deb created with `debify package` to our private apt repository.
120
178
 
121
- --distribution should match the major/minor version of the Conjur
122
- appliance you want to install to.
179
+ "distribution" should match the major/minor version of the Conjur appliance you want to install to.
123
180
 
124
- --component should be 'stable' if run after package tests pass or
125
- 'testing' if the package is not yet ready for release.
181
+ The package name is a required option. The package version can be specified as a CLI option, or it will be auto-detected from Git.
126
182
 
127
- ARTIFACTORY_USERNAME and ARTIFACTORY_PASSWORD must be available
128
- in the environment for upload to succeed.
183
+ --component should be 'stable' if run after package tests pass or 'testing' if the package is not yet ready for release. If you don't specify the component, it will be set to
184
+ 'testing' unless the current git branch is 'master' or 'origin/master'. The git branch is first detected from the env var GIT_BRANCH, and then by checking `git rev-parse
185
+ --abbrev-ref HEAD` (which won't give you the answer you want when detached).
129
186
 
130
187
  COMMAND OPTIONS
131
- -c, --component=arg - Maturity stage of the package, 'testing'
132
- or 'stable' (default: testing)
133
- -d, --distribution=arg - Lock packages to a Conjur appliance
134
- version (default: 4.6)
188
+ -c, --component=arg - Maturity stage of the package, 'testing' or 'stable' (default: none)
189
+ -d, --dir=arg - Set the current working directory (default: none)
190
+ -v, --version=arg - Specify the deb package version; by default, it's computed automatically (default: none)
135
191
  ```
136
192
 
137
193
  ### Example usage
138
194
 
139
- Assuming a `secrets.yml` like this exists in the source directory and that you have `summon` with the Conjur provider installed on the machine:
140
-
141
- ```yaml
142
- ARTIFACTORY_USERNAME: !var artifactory/users/jenkins/username
143
- ARTIFACTORY_PASSWORD: !var artifactory/users/jenkins/password
144
- ```
195
+ You will need read permission for the `ci/artifactory/users/jenkins/username` and `ci/artifactory/users/jenkins/password` variables in order to run this command from your local machine.
145
196
 
146
197
  ```sh-session
147
- $ summon debify publish -c stable conjur-example_0.0.1_amd64.deb
148
- [Thread 0] Uploading artifact: https://conjurinc.artifactoryonline.com/conjurinc/debian-local/test.deb;deb.distribution=4.6;deb.component=stable;deb.architecture=amd64
198
+ $ debify publish -c stable 0.0.1 example
199
+ [Thread 0] Uploading artifact: https://conjurinc.artifactoryonline.com/conjurinc/debian-local/conjur-example_0.1.1-c9fd618_amd64.deb;deb.distribution=0.1.1;deb.component=possum;deb.architecture=amd64
149
200
  [Thread 0] Artifactory response: 201 Created
150
201
  Uploaded 1 artifacts to Artifactory.
151
202
  ```
data/Rakefile CHANGED
@@ -10,6 +10,11 @@ rescue LoadError
10
10
  false
11
11
  end
12
12
 
13
+ def rspec?
14
+ require 'rspec/core/rake_task'
15
+ require 'ci/reporter/rake/rspec'
16
+ end
17
+
13
18
  Rake::RDocTask.new do |rd|
14
19
  rd.main = "README.rdoc"
15
20
  rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
@@ -22,12 +27,11 @@ Gem::PackageTask.new(spec) do |pkg|
22
27
  end
23
28
 
24
29
  if cucumber?
25
- CUKE_RESULTS = 'results.html'
26
- CLEAN << CUKE_RESULTS
30
+ CUKE_RESULTS = 'features/reports'
27
31
 
28
32
  desc 'Run features'
29
33
  Cucumber::Rake::Task.new(:features) do |t|
30
- opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
34
+ opts = "features --format junit -o #{CUKE_RESULTS} --format pretty -x"
31
35
  opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
32
36
  t.cucumber_opts = opts
33
37
  t.fork = false
@@ -37,7 +41,7 @@ if cucumber?
37
41
  Cucumber::Rake::Task.new('features:wip') do |t|
38
42
  tag_opts = ' --tags ~@pending'
39
43
  tag_opts = ' --tags @wip'
40
- t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
44
+ t.cucumber_opts = "features --format junit -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
41
45
  t.fork = false
42
46
  end
43
47
 
@@ -46,4 +50,8 @@ if cucumber?
46
50
  task :wip => 'features:wip'
47
51
  end
48
52
 
49
- task :default => [:features]
53
+ if rspec?
54
+ desc 'Run specs'
55
+ RSpec::Core::RakeTask.new(:spec)
56
+ task :spec => 'ci:setup:rspec'
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.7.0
data/build.sh ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/bash -ex
2
+
3
+ VERSION=$(< VERSION)
4
+ docker build --build-arg VERSION=$VERSION -t debify:$VERSION .
data/ci/test.sh ADDED
@@ -0,0 +1,8 @@
1
+ #!/bin/bash -ex
2
+
3
+ bundle
4
+
5
+ for target in spec cucumber; do
6
+ bundle exec rake $target || true
7
+ done
8
+
data/debify.gemspec CHANGED
@@ -19,10 +19,18 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency "gli"
21
21
  spec.add_dependency "docker-api", "~> 1.33"
22
- spec.add_dependency "conjur-cli"
22
+ spec.add_dependency "conjur-cli" , "~> 5"
23
+ spec.add_dependency "conjur-api", "~> 4"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.7"
25
26
  spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "cucumber"
27
+
28
+ # Pin to cucumbe v2. cucumber v3 changes (breaks) the behavior of
29
+ # unmatched capture groups with \(d+). In v3, the value of such a
30
+ # group is 0 instead of nil, which breaks aruba's "I successfully
31
+ # run...." steps.
32
+ spec.add_development_dependency "cucumber", '~> 2'
27
33
  spec.add_development_dependency "aruba"
34
+ spec.add_development_dependency 'rspec', '~> 3'
35
+ spec.add_development_dependency 'ci_reporter_rspec', '~> 1.0'
28
36
  end
@@ -0,0 +1,7 @@
1
+ require 'netrc'
2
+ Netrc.configure do |c|
3
+ c[:allow_permissive_netrc_file] = true
4
+ end
5
+
6
+ creds = Netrc.read('/root/.netrc')[ENV['CONJUR_APPLIANCE_URL'] + '/authn']
7
+ print "#{creds.login} #{creds.password}" if creds
@@ -0,0 +1,27 @@
1
+ #!/bin/bash -e
2
+
3
+ # If we're running in jenkins, there will be a conjur.identity file
4
+ # with Conjur creds in it. Otherwise, assume the user's netrc has
5
+ # them.
6
+ if [[ -f /etc/conjur.identity ]]; then
7
+ netrc=/etc/conjur.identity
8
+ else
9
+ netrc=$HOME/.netrc
10
+ fi
11
+
12
+ : ${CONJUR_APPLIANCE_URL=https://conjur-master-v2.itp.conjur.net/api}
13
+ export CONJUR_APPLIANCE_URL
14
+
15
+ [[ -f "$HOME/.debifyrc" ]] && rc_arg="-v $HOME/.debifyrc:/root/.debifyrc:ro"
16
+
17
+ # mounting docker socket is required because subcommands launch
18
+ # containers
19
+ tty=$(tty -s && echo "-t" || true)
20
+ docker run -i $tty --rm \
21
+ -e GLI_DEBUG -e DEBUG -e CONJUR_APPLIANCE_URL \
22
+ -v $PWD:$PWD -w $PWD \
23
+ -v /var/run/docker.sock:/var/run/docker.sock \
24
+ -v ${netrc}:/root/.netrc:ro \
25
+ ${rc_arg} \
26
+ ${DEBIFY_ENTRYPOINT+--entrypoint $DEBIFY_ENTRYPOINT} \
27
+ ${DEBIFY_IMAGE-registry.tld/conjurinc/debify:@@DEBIFY_VERSION@@} "$@"
@@ -0,0 +1,22 @@
1
+ #!/bin/bash -e
2
+
3
+ # Make sure we don't echo commands as executed, otherwise the user's
4
+ # Conjur API key will show up in the logs.
5
+ set +x
6
+
7
+ creds=( $(ruby /debify/distrib/conjur_creds.rb) )
8
+
9
+ # If there are creds, use them to log in to the registry. Then, run
10
+ # the magic DockerInDocker wrapper script so debify can interact with
11
+ # the Docker daemon.
12
+ #
13
+ # If there are no creds, just run debify itself. Any commands that do
14
+ # Docker stuff will fail, but the non-Docker commands (e.g. the config
15
+ # subcommands) will work fine.
16
+ if [[ ${#creds[*]} > 0 ]]; then
17
+ echo -n "${creds[1]}" | docker login registry.tld -u ${creds[0]} --password-stdin >/dev/null 2>&1
18
+ exec wrapdocker debify "$@"
19
+ else
20
+ exec debify "$@"
21
+ fi
22
+
data/distrib/script ADDED
@@ -0,0 +1 @@
1
+ distrib/docker-debify
data/distrib/secrets ADDED
@@ -0,0 +1 @@
1
+ distrib/secrets.yml
@@ -0,0 +1,2 @@
1
+ ARTIFACTORY_USER: !var ci/artifactory/users/jenkins/username
2
+ ARTIFACTORY_PASSWORD: !var ci/artifactory/users/jenkins/password
@@ -4,4 +4,4 @@ Feature: Automatic version string
4
4
  Scenario: 'example' project gets a default version
5
5
  When I run `env DEBUG=true GLI_DEBUG=true debify detect-version -d ../../example`
6
6
  Then the exit status should be 0
7
- And the output should match /\d.\d.\d-\d-.*/
7
+ And the output should match /\d+.\d+.\d+-\d+-.*/
@@ -16,6 +16,6 @@ Feature: Packaging
16
16
  @announce-output
17
17
  Scenario: 'example' project can be tested successfully
18
18
  Given I successfully run `env DEBUG=true GLI_DEBUG=true debify package -d ../../example -v 0.0.1 example -- --post-install /distrib/postinstall.sh`
19
- When I run `env DEBUG=true GLI_DEBUG=true debify test -t 4.8-stable -v 0.0.1 -d ../../example --no-pull example test.sh`
19
+ When I run `env DEBUG=true GLI_DEBUG=true debify test -t 4.9-stable -v 0.0.1 -d ../../example --no-pull example test.sh`
20
20
  Then the exit status should be 0
21
21
  And the stderr should contain "Test succeeded"
data/lib/conjur/debify.rb CHANGED
@@ -296,9 +296,6 @@ def container_command container, *args
296
296
  end
297
297
 
298
298
  def wait_for_conjur appliance_image, container
299
- # Add a hosts entry for now, get rid of it when wait_for_conjur no
300
- # longer requires it.
301
- system("docker exec #{container.id} /bin/bash -c 'echo 127.0.0.1 conjur >> /etc/hosts'")
302
299
  container_command container, '/opt/conjur/evoke/bin/wait_for_conjur'
303
300
  end
304
301
 
@@ -641,73 +638,13 @@ command "publish" do |c|
641
638
  c.flag [ :c, :component ]
642
639
 
643
640
  c.action do |global_options,cmd_options,args|
641
+ require 'conjur/debify/action/publish'
644
642
  raise "distribution is required" unless distribution = args.shift
645
643
  raise "project-name is required" unless project_name = args.shift
646
644
  raise "Received extra command-line arguments" if args.shift
647
645
 
648
- def detect_component
649
- branch = ENV['GIT_BRANCH'] || ENV['BRANCH_NAME'] || `git rev-parse --abbrev-ref HEAD`.strip
650
- if %w(master origin/master).include?(branch)
651
- 'stable'
652
- else
653
- branch.gsub('/', '.')
654
- end
655
- end
656
-
657
- dir = cmd_options[:dir] || '.'
658
- dir = File.expand_path(dir)
659
- raise "Directory #{dir} does not exist or is not a directory" unless File.directory?(dir)
660
-
661
- Dir.chdir dir do
662
- version = cmd_options[:version] || detect_version
663
- component = cmd_options[:component] || detect_component
664
- package_name = "conjur-#{project_name}_#{version}_amd64.deb"
665
-
666
- publish_image = Docker::Image.build_from_dir File.expand_path('publish', File.dirname(__FILE__)), tag: "debify-publish", &DebugMixin::DOCKER
667
- DebugMixin.debug_write "Built base publish image '#{publish_image.id}'\n"
668
-
669
- require 'conjur/cli'
670
- require 'conjur/authn'
671
- Conjur::Config.load
672
- Conjur::Config.apply
673
- conjur = Conjur::Authn.connect nil, noask: true
674
-
675
- username_var = 'artifactory/users/jenkins/username'
676
- password_var = 'artifactory/users/jenkins/password'
677
-
678
- if conjur.variable('ci/artifactory/users/jenkins/username').exists? # we're on new conjurops
679
- username_var.insert(0, 'ci/')
680
- password_var.insert(0, 'ci/')
681
- end
682
-
683
- art_username = conjur.variable(username_var).value
684
- art_password = conjur.variable(password_var).value
685
-
686
- options = {
687
- 'Image' => publish_image.id,
688
- 'Cmd' => [
689
- "art", "upload",
690
- "--url", "https://conjurinc.artifactoryonline.com/conjurinc",
691
- "--user", art_username,
692
- "--password", art_password,
693
- "--deb", "#{distribution}/#{component}/amd64",
694
- package_name, "debian-local/"
695
- ],
696
- 'Binds' => [
697
- [ dir, "/src" ].join(':')
698
- ]
699
- }
700
- options['Privileged'] = true if Docker.version['Version'] >= '1.10.0'
701
-
702
- container = Docker::Container.create(options)
703
- begin
704
- container.tap(&:start).streaming_logs(follow: true, stdout: true, stderr: true) { |stream, chunk| puts "#{chunk}" }
705
- status = container.wait
706
- raise "Failed to publish #{package_name}" unless status['StatusCode'] == 0
707
- ensure
708
- container.delete(force: true)
709
- end
710
- end
646
+ require 'pry'; binding.pry
647
+ Conjur::Debify::Action::Publish.new(distribution, project_name, cmd_options).run
711
648
  end
712
649
  end
713
650
 
@@ -729,6 +666,20 @@ command "detect-version" do |c|
729
666
  end
730
667
  end
731
668
 
669
+ desc 'Show the given configuration'
670
+ arg_name 'configuration'
671
+ command 'config' do |c|
672
+ c.action do |_,_,args|
673
+ raise 'no configuration provided' unless config = args.shift
674
+ raise "Received extra command-line arguments" if args.shift
675
+
676
+ File.open(File.join('distrib', config)).each do |line|
677
+ puts line.gsub(/@@DEBIFY_VERSION@@/, Conjur::Debify::VERSION)
678
+ end
679
+ end
680
+ end
681
+
682
+
732
683
  pre do |global,command,options,args|
733
684
  # Pre logic here
734
685
  # Return true to proceed; false to abort and not call the
@@ -0,0 +1,90 @@
1
+ module Conjur::Debify
2
+ module Action
3
+ class Publish
4
+
5
+ def detect_component
6
+ branch = ENV['GIT_BRANCH'] || ENV['BRANCH_NAME'] || `git rev-parse --abbrev-ref HEAD`.strip
7
+ if %w(master origin/master).include?(branch)
8
+ 'stable'
9
+ else
10
+ branch.gsub('/', '.')
11
+ end
12
+ end
13
+
14
+ attr_reader :distribution, :project_name, :cmd_options
15
+ def initialize(distribution, project_name, cmd_options)
16
+ @distribution = distribution
17
+ @project_name = project_name
18
+ @cmd_options = cmd_options
19
+ end
20
+
21
+ def run
22
+ dir = cmd_options[:dir] || '.'
23
+ dir = File.expand_path(dir)
24
+ raise "Directory #{dir} does not exist or is not a directory" unless File.directory?(dir)
25
+
26
+ Dir.chdir dir do
27
+ version = cmd_options[:version] || detect_version
28
+ component = cmd_options[:component] || detect_component
29
+ package_name = "conjur-#{project_name}_#{version}_amd64.deb"
30
+
31
+ publish_image = create_image
32
+ DebugMixin.debug_write "Built base publish image '#{publish_image.id}'\n"
33
+
34
+ art_user = ENV['ARTIFACTORY_USER']
35
+ art_password = ENV['ARTIFACTORY_PASSWORD']
36
+ unless art_user && art_password
37
+ art_user, art_password = fetch_art_creds
38
+ end
39
+
40
+ options = {
41
+ 'Image' => publish_image.id,
42
+ 'Cmd' => [
43
+ "art", "upload",
44
+ "--url", "https://conjurinc.artifactoryonline.com/conjurinc",
45
+ "--user", art_user,
46
+ "--password", art_password,
47
+ "--deb", "#{distribution}/#{component}/amd64",
48
+ package_name, "debian-local/"
49
+ ],
50
+ 'Binds' => [
51
+ [ dir, "/src" ].join(':')
52
+ ]
53
+ }
54
+ options['Privileged'] = true if Docker.version['Version'] >= '1.10.0'
55
+
56
+ publish(options)
57
+ end
58
+ end
59
+
60
+ def create_image
61
+ Docker::Image.build_from_dir File.expand_path('publish', File.dirname(__FILE__)), tag: "debify-publish", &DebugMixin::DOCKER
62
+ end
63
+
64
+ def fetch_art_creds
65
+ require 'conjur/cli'
66
+ require 'conjur/authn'
67
+ Conjur::Config.load
68
+ Conjur::Config.apply
69
+ conjur = Conjur::Authn.connect nil, noask: true
70
+
71
+ username_var = 'ci/artifactory/users/jenkins/username'
72
+ password_var = 'ci/artifactory/users/jenkins/password'
73
+
74
+ [conjur.variable(username_var).value, conjur.variable(password_var).value]
75
+ end
76
+
77
+ def publish(options)
78
+ container = Docker::Container.create(options)
79
+ begin
80
+ container.tap(&:start).streaming_logs(follow: true, stdout: true, stderr: true) { |stream, chunk| puts "#{chunk}" }
81
+ status = container.wait
82
+ raise "Failed to publish #{package_name}" unless status['StatusCode'] == 0
83
+ ensure
84
+ container.delete(force: true)
85
+ end
86
+ end
87
+
88
+ end
89
+ end
90
+ end
@@ -1,5 +1,5 @@
1
1
  module Conjur
2
2
  module Debify
3
- VERSION = "1.6.0"
3
+ VERSION = File.read(File.expand_path('../../../VERSION', __dir__))
4
4
  end
5
5
  end
@@ -0,0 +1,11 @@
1
+ #!/bin/bash -e
2
+
3
+ docker pull registry.tld/conjurinc/publish-rubygem
4
+
5
+ docker run -i --rm -v $PWD:/src -w /src alpine/git clean -fxd
6
+
7
+ summon --yaml "RUBYGEMS_API_KEY: !var rubygems/api-key" \
8
+ docker run --rm --env-file @SUMMONENVFILE -v "$(pwd)":/opt/src \
9
+ registry.tld/conjurinc/publish-rubygem debify
10
+
11
+ docker run -i --rm -v $PWD:/src -w /src alpine/git clean -fxd
data/push-image.sh ADDED
@@ -0,0 +1,6 @@
1
+ #!/bin/bash -ex
2
+
3
+ TAG=$(< VERSION)
4
+
5
+ docker push registry.tld/conjurinc/debify:$TAG
6
+ docker push registry.tld/conjurinc/debify:latest
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require 'conjur/debify/action/publish'
3
+
4
+ describe Conjur::Debify::Action::Publish do
5
+
6
+ let (:cmd_options) {
7
+ {
8
+ :version => '1.0.0',
9
+ :component => 'stable'
10
+ }
11
+ }
12
+
13
+ let (:action) { Conjur::Debify::Action::Publish.new('dist', 'proj', cmd_options) }
14
+
15
+ before do
16
+ allow(DebugMixin).to receive(:debug_write)
17
+
18
+ allow(action).to receive(:create_image).and_return(double('publish_image', :id => 'a1b2c3d4'))
19
+ end
20
+
21
+ context 'with artifactory creds in the environment' do
22
+
23
+ before do
24
+ ENV['ARTIFACTORY_USER'] = 'art_user'
25
+ ENV['ARTIFACTORY_PASSWORD'] = 'art_password'
26
+ end
27
+
28
+ after do
29
+ ENV.delete('ARTIFACTORY_USER')
30
+ ENV.delete('ARTIFACTORY_PASSWORD')
31
+ end
32
+
33
+ it 'runs' do
34
+ expect(action).to receive(:publish)
35
+
36
+ action.run
37
+ end
38
+
39
+ end
40
+
41
+ context 'without artifactory creds in the environment' do
42
+
43
+ it 'runs' do
44
+ expect(action).to receive(:fetch_art_creds)
45
+ expect(action).to receive(:publish)
46
+
47
+ action.run
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+
54
+
@@ -0,0 +1 @@
1
+ require 'conjur/debify'
data/tag-image.sh ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash -ex
2
+ TAG=$(< VERSION)
3
+
4
+ docker tag debify:$TAG registry.tld/conjurinc/debify:$TAG
5
+ docker tag debify:$TAG registry.tld/conjurinc/debify:latest
data/test.sh ADDED
@@ -0,0 +1,6 @@
1
+ #!/bin/bash -ex
2
+
3
+ VERSION=$(< VERSION)
4
+ docker run --rm debify:$VERSION config script > docker-debify
5
+ chmod +x docker-debify
6
+ DEBIFY_IMAGE=debify:$VERSION DEBIFY_ENTRYPOINT=ci/test.sh ./docker-debify
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conjur-debify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Gilpin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-25 00:00:00.000000000 Z
11
+ date: 2017-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -42,16 +42,30 @@ dependencies:
42
42
  name: conjur-cli
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '5'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: conjur-api
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +98,16 @@ dependencies:
84
98
  name: cucumber
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ">="
101
+ - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0'
103
+ version: '2'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ">="
108
+ - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0'
110
+ version: '2'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: aruba
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,34 @@ dependencies:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3'
139
+ - !ruby/object:Gem::Dependency
140
+ name: ci_reporter_rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.0'
111
153
  description:
112
154
  email:
113
155
  - kgilpin@conjur.net
@@ -123,11 +165,21 @@ files:
123
165
  - CHANGELOG.md
124
166
  - Dockerfile
125
167
  - Gemfile
168
+ - Jenkinsfile
126
169
  - LICENSE.txt
127
170
  - README.md
128
171
  - Rakefile
172
+ - VERSION
129
173
  - bin/debify
174
+ - build.sh
175
+ - ci/test.sh
130
176
  - debify.gemspec
177
+ - distrib/conjur_creds.rb
178
+ - distrib/docker-debify
179
+ - distrib/entrypoint.sh
180
+ - distrib/script
181
+ - distrib/secrets
182
+ - distrib/secrets.yml
131
183
  - example/Gemfile
132
184
  - example/Gemfile.lock
133
185
  - example/debify.sh
@@ -140,12 +192,19 @@ files:
140
192
  - jenkins.sh
141
193
  - lib/conjur/debify.rb
142
194
  - lib/conjur/debify/Dockerfile.fpm
195
+ - lib/conjur/debify/action/publish.rb
143
196
  - lib/conjur/debify/version.rb
144
197
  - lib/conjur/fpm/Dockerfile
145
198
  - lib/conjur/fpm/debify_utils.sh
146
199
  - lib/conjur/fpm/package.sh
147
200
  - lib/conjur/publish/Dockerfile
201
+ - publish-rubygem.sh
202
+ - push-image.sh
148
203
  - secrets.yml
204
+ - spec/action/publish_spec.rb
205
+ - spec/spec_helper.rb
206
+ - tag-image.sh
207
+ - test.sh
149
208
  homepage: https://github.com/conjurinc/debify
150
209
  licenses:
151
210
  - MIT
@@ -166,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
225
  version: '0'
167
226
  requirements: []
168
227
  rubyforge_project:
169
- rubygems_version: 2.4.5.2
228
+ rubygems_version: 2.6.14
170
229
  signing_key:
171
230
  specification_version: 4
172
231
  summary: Utility commands to build and package Conjur services as Debian packages
@@ -175,4 +234,5 @@ test_files:
175
234
  - features/package.feature
176
235
  - features/step_definitions/debify_steps.rb
177
236
  - features/support/env.rb
178
- has_rdoc:
237
+ - spec/action/publish_spec.rb
238
+ - spec/spec_helper.rb