dpl 1.10.17.travis.6637.6 → 2.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +74 -0
- data/CONTRIBUTING.md +392 -0
- data/Gemfile +17 -3
- data/Gemfile.lock +373 -0
- data/LICENSE +16 -19
- data/NOTES.md +275 -0
- data/README.md +1977 -707
- data/Rakefile +2 -2
- data/bin/dpl +7 -3
- data/lib/dpl.rb +20 -0
- data/lib/dpl/assets/atlas/install +19 -0
- data/lib/dpl/assets/dpl/README.erb.md +133 -0
- data/lib/dpl/assets/dpl/git_ssh +2 -0
- data/lib/dpl/assets/git/detect_private_key +8 -0
- data/lib/dpl/assets/hephy/filter_log +3 -0
- data/lib/dpl/assets/pypi/install +4 -0
- data/lib/dpl/assets/scalingo/install +6 -0
- data/lib/dpl/cli.rb +36 -48
- data/lib/dpl/ctx.rb +2 -0
- data/lib/dpl/ctx/bash.rb +543 -0
- data/lib/dpl/ctx/test.rb +242 -0
- data/lib/dpl/helper/assets.rb +36 -0
- data/lib/dpl/helper/cmd.rb +167 -0
- data/lib/dpl/helper/config_file.rb +47 -0
- data/lib/dpl/helper/env.rb +39 -0
- data/lib/dpl/helper/interpolate.rb +126 -0
- data/lib/dpl/helper/memoize.rb +20 -0
- data/lib/dpl/helper/squiggle.rb +22 -0
- data/lib/dpl/helper/zip.rb +69 -0
- data/lib/dpl/provider.rb +562 -234
- data/lib/dpl/provider/dsl.rb +369 -0
- data/lib/dpl/provider/examples.rb +128 -0
- data/lib/dpl/provider/status.rb +59 -0
- data/lib/dpl/providers.rb +40 -0
- data/lib/dpl/providers/anynines.rb +65 -0
- data/lib/dpl/providers/atlas.rb +49 -0
- data/lib/dpl/providers/azure_web_apps.rb +59 -0
- data/lib/dpl/providers/bintray.rb +313 -0
- data/lib/dpl/providers/bluemixcloudfoundry.rb +92 -0
- data/lib/dpl/providers/boxfuse.rb +48 -0
- data/lib/dpl/providers/cargo.rb +19 -0
- data/lib/dpl/providers/chef_supermarket.rb +128 -0
- data/lib/dpl/providers/cloud66.rb +40 -0
- data/lib/dpl/providers/cloudfiles.rb +56 -0
- data/lib/dpl/providers/cloudfoundry.rb +81 -0
- data/lib/dpl/providers/codedeploy.rb +179 -0
- data/lib/dpl/providers/datica.rb +60 -0
- data/lib/dpl/providers/elasticbeanstalk.rb +195 -0
- data/lib/dpl/providers/engineyard.rb +107 -0
- data/lib/dpl/providers/firebase.rb +41 -0
- data/lib/dpl/providers/gae.rb +74 -0
- data/lib/dpl/providers/gcs.rb +105 -0
- data/lib/dpl/providers/hackage.rb +47 -0
- data/lib/dpl/providers/hephy.rb +101 -0
- data/lib/dpl/providers/heroku.rb +111 -0
- data/lib/dpl/providers/heroku/api.rb +119 -0
- data/lib/dpl/providers/heroku/git.rb +50 -0
- data/lib/dpl/providers/lambda.rb +202 -0
- data/lib/dpl/providers/launchpad.rb +74 -0
- data/lib/dpl/providers/netlify.rb +30 -0
- data/lib/dpl/providers/npm.rb +88 -0
- data/lib/dpl/providers/openshift.rb +46 -0
- data/lib/dpl/providers/opsworks.rb +142 -0
- data/lib/dpl/providers/packagecloud.rb +190 -0
- data/lib/dpl/providers/pages.rb +17 -0
- data/lib/dpl/providers/pages/api.rb +102 -0
- data/lib/dpl/providers/pages/git.rb +251 -0
- data/lib/dpl/providers/puppetforge.rb +44 -0
- data/lib/dpl/providers/pypi.rb +120 -0
- data/lib/dpl/providers/releases.rb +214 -0
- data/lib/dpl/providers/rubygems.rb +89 -0
- data/lib/dpl/providers/s3.rb +243 -0
- data/lib/dpl/providers/scalingo.rb +63 -0
- data/lib/dpl/providers/script.rb +28 -0
- data/lib/dpl/providers/snap.rb +59 -0
- data/lib/dpl/providers/surge.rb +55 -0
- data/lib/dpl/providers/testfairy.rb +93 -0
- data/lib/dpl/providers/transifex.rb +66 -0
- data/lib/dpl/support/aws_sdk_patch.rb +23 -0
- data/lib/dpl/support/gems.rb +69 -0
- data/lib/dpl/support/gstore_patch.rb +6 -0
- data/lib/dpl/support/version.rb +83 -0
- data/lib/dpl/version.rb +2 -2
- metadata +98 -169
- data/.coveralls.yml +0 -1
- data/.github/CONTRIBUTING.md +0 -173
- data/.github/stale.yml +0 -53
- data/.gitignore +0 -13
- data/.rspec +0 -2
- data/.travis.yml +0 -56
- data/dpl-anynines.gemspec +0 -3
- data/dpl-atlas.gemspec +0 -3
- data/dpl-azure_webapps.gemspec +0 -3
- data/dpl-bintray.gemspec +0 -3
- data/dpl-bitballoon.gemspec +0 -3
- data/dpl-bluemix_cloud_foundry.gemspec +0 -3
- data/dpl-boxfuse.gemspec +0 -3
- data/dpl-cargo.gemspec +0 -3
- data/dpl-catalyze.gemspec +0 -3
- data/dpl-chef_supermarket.gemspec +0 -20
- data/dpl-cloud66.gemspec +0 -3
- data/dpl-cloud_files.gemspec +0 -3
- data/dpl-cloud_foundry.gemspec +0 -3
- data/dpl-code_deploy.gemspec +0 -3
- data/dpl-deis.gemspec +0 -3
- data/dpl-elastic_beanstalk.gemspec +0 -3
- data/dpl-engine_yard.gemspec +0 -3
- data/dpl-firebase.gemspec +0 -3
- data/dpl-gae.gemspec +0 -3
- data/dpl-gcs.gemspec +0 -3
- data/dpl-hackage.gemspec +0 -3
- data/dpl-hephy.gemspec +0 -3
- data/dpl-heroku.gemspec +0 -3
- data/dpl-lambda.gemspec +0 -3
- data/dpl-launchpad.gemspec +0 -3
- data/dpl-npm.gemspec +0 -3
- data/dpl-openshift.gemspec +0 -3
- data/dpl-ops_works.gemspec +0 -3
- data/dpl-packagecloud.gemspec +0 -3
- data/dpl-pages.gemspec +0 -3
- data/dpl-puppet_forge.gemspec +0 -3
- data/dpl-pypi.gemspec +0 -3
- data/dpl-releases.gemspec +0 -8
- data/dpl-rubygems.gemspec +0 -3
- data/dpl-s3.gemspec +0 -3
- data/dpl-scalingo.gemspec +0 -3
- data/dpl-script.gemspec +0 -3
- data/dpl-snap.gemspec +0 -3
- data/dpl-surge.gemspec +0 -3
- data/dpl-testfairy.gemspec +0 -3
- data/dpl-transifex.gemspec +0 -3
- data/dpl.gemspec +0 -3
- data/gemspec_helper.rb +0 -51
- data/lib/dpl/error.rb +0 -3
- data/notes/engine_yard.md +0 -1
- data/notes/heroku.md +0 -3
- data/spec/cli_spec.rb +0 -36
- data/spec/provider_spec.rb +0 -191
- data/spec/spec_helper.rb +0 -20
@@ -0,0 +1,30 @@
|
|
1
|
+
module Dpl
|
2
|
+
module Providers
|
3
|
+
class Netlify < Provider
|
4
|
+
status :alpha
|
5
|
+
|
6
|
+
description sq(<<-str)
|
7
|
+
tbd
|
8
|
+
str
|
9
|
+
|
10
|
+
npm 'netlify-cli', 'netlify'
|
11
|
+
|
12
|
+
opt '--site ID', 'A site ID to deploy to', required: true
|
13
|
+
opt '--auth TOKEN', 'An auth token to log in with', required: true, secret: true
|
14
|
+
opt '--dir DIR', 'Specify a folder to deploy'
|
15
|
+
opt '--functions FUNCS', 'Specify a functions folder to deploy'
|
16
|
+
opt '--message MSG', 'A message to include in the deploy log'
|
17
|
+
opt '--prod', 'Deploy to production'
|
18
|
+
|
19
|
+
def deploy
|
20
|
+
shell "netlify deploy #{deploy_opts}"
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def deploy_opts
|
26
|
+
opts_for(%i(site auth dir functions message prod))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Dpl
|
2
|
+
module Providers
|
3
|
+
class Npm < Provider
|
4
|
+
status :alpha
|
5
|
+
|
6
|
+
full_name 'npm'
|
7
|
+
|
8
|
+
description sq(<<-str)
|
9
|
+
tbd
|
10
|
+
str
|
11
|
+
|
12
|
+
gem 'json'
|
13
|
+
|
14
|
+
opt '--email EMAIL', 'npm account email'
|
15
|
+
opt '--api_token TOKEN', 'npm api token', alias: :api_key, required: true, secret: true, note: 'can be retrieved from your local ~/.npmrc file', see: 'https://docs.npmjs.com/creating-and-viewing-authentication-tokens'
|
16
|
+
opt '--access ACCESS', 'Access level', enum: %w(public private)
|
17
|
+
opt '--registry URL', 'npm registry url'
|
18
|
+
opt '--src SRC', 'directory or tarball to publish', default: '.'
|
19
|
+
opt '--tag TAGS', 'distribution tags to add'
|
20
|
+
opt '--auth_method', 'Authentication method', enum: %w(auth)
|
21
|
+
|
22
|
+
REGISTRY = 'registry.npmjs.org'
|
23
|
+
NPMRC = '~/.npmrc'
|
24
|
+
|
25
|
+
msgs version: 'npm version: %{npm_version}',
|
26
|
+
login: 'Authenticated with API token %{api_token}'
|
27
|
+
|
28
|
+
cmds registry: 'npm config set registry "%{registry}"',
|
29
|
+
deploy: 'npm publish %{src} %{publish_opts}'
|
30
|
+
|
31
|
+
errs registry: 'Failed to set registry config',
|
32
|
+
deploy: 'Failed pushing to npm'
|
33
|
+
|
34
|
+
def login
|
35
|
+
info :version
|
36
|
+
info :login
|
37
|
+
write_npmrc
|
38
|
+
shell :registry
|
39
|
+
end
|
40
|
+
|
41
|
+
def deploy
|
42
|
+
shell :deploy
|
43
|
+
end
|
44
|
+
|
45
|
+
def finish
|
46
|
+
remove_npmrc
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def publish_opts
|
52
|
+
opts_for(%i(access tag))
|
53
|
+
end
|
54
|
+
|
55
|
+
def write_npmrc
|
56
|
+
write_file(npmrc_path, npmrc)
|
57
|
+
info "#{NPMRC} size: #{file_size(npmrc_path)}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def remove_npmrc
|
61
|
+
rm_f npmrc_path
|
62
|
+
end
|
63
|
+
|
64
|
+
def npmrc_path
|
65
|
+
expand(NPMRC)
|
66
|
+
end
|
67
|
+
|
68
|
+
def npmrc
|
69
|
+
if npm_version =~ /^1/ || auth_method == 'auth'
|
70
|
+
"_auth = #{api_token}\nemail = #{email}"
|
71
|
+
else
|
72
|
+
"//#{registry.sub('https://', '').sub(%r(/$), '')}/:_authToken=#{api_token}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def registry
|
77
|
+
return super if super
|
78
|
+
data = package_json
|
79
|
+
url = data && data.fetch('publishConfig', {})['registry']
|
80
|
+
url ? URI(url).host : REGISTRY
|
81
|
+
end
|
82
|
+
|
83
|
+
def package_json
|
84
|
+
File.exists?('package.json') ? JSON.parse(File.read('package.json')) : {}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Dpl
|
2
|
+
module Providers
|
3
|
+
class Openshift < Provider
|
4
|
+
status :alpha
|
5
|
+
|
6
|
+
full_name 'OpenShift'
|
7
|
+
|
8
|
+
description sq(<<-str)
|
9
|
+
tbd
|
10
|
+
str
|
11
|
+
|
12
|
+
opt '--server SERVER', 'OpenShift server', required: true
|
13
|
+
opt '--token TOKEN', 'OpenShift token', required: true, secret: true
|
14
|
+
opt '--project PROJECT', 'OpenShift project', required: true
|
15
|
+
opt '--app APP', 'OpenShift application', default: :repo_name
|
16
|
+
|
17
|
+
cmds install: 'curl %{URL} | tar xz',
|
18
|
+
login: './oc login --token=%{token} --server=%{server}',
|
19
|
+
prepare: './oc project %{project}',
|
20
|
+
deploy: './oc start-build %{app} --follow --commit %{git_sha}'
|
21
|
+
|
22
|
+
errs install: 'CLI tool installation failed',
|
23
|
+
login: 'Authentication failed',
|
24
|
+
prepare: 'Unable to select project %{project}',
|
25
|
+
deploy: 'Deployment failed'
|
26
|
+
|
27
|
+
URL = 'https://mirror.openshift.com/pub/openshift-v4/clients/oc/4.1/linux/oc.tar.gz'
|
28
|
+
|
29
|
+
def install
|
30
|
+
shell :install
|
31
|
+
end
|
32
|
+
|
33
|
+
def login
|
34
|
+
shell :login
|
35
|
+
end
|
36
|
+
|
37
|
+
def prepare
|
38
|
+
shell :prepare
|
39
|
+
end
|
40
|
+
|
41
|
+
def deploy
|
42
|
+
shell :deploy
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
module Dpl
|
2
|
+
module Providers
|
3
|
+
class Opsworks < Provider
|
4
|
+
status :alpha
|
5
|
+
|
6
|
+
full_name 'AWS OpsWorks'
|
7
|
+
|
8
|
+
description sq(<<-str)
|
9
|
+
tbd
|
10
|
+
str
|
11
|
+
|
12
|
+
gem 'aws-sdk-opsworks', '~> 1.0'
|
13
|
+
|
14
|
+
env :aws
|
15
|
+
config '~/.aws/credentials', '~/.aws/config', prefix: 'aws'
|
16
|
+
|
17
|
+
opt '--access_key_id ID', 'AWS access key id', required: true, secret: true
|
18
|
+
opt '--secret_access_key KEY', 'AWS secret key', required: true, secret: true
|
19
|
+
opt '--app_id APP', 'The app id', required: true
|
20
|
+
opt '--region REGION', 'AWS region', default: 'us-east-1'
|
21
|
+
opt '--instance_ids ID', 'An instance id', type: :array
|
22
|
+
opt '--layer_ids ID', 'A layer id', type: :array
|
23
|
+
opt '--migrate', 'Migrate the database.'
|
24
|
+
opt '--wait_until_deployed', 'Wait until the app is deployed and return the deployment status.'
|
25
|
+
opt '--update_on_success', 'When wait-until-deployed and updated-on-success are both not given, application source is updated to the current SHA. Ignored when wait-until-deployed is not given.', alias: :update_app_on_success
|
26
|
+
opt '--custom_json JSON', 'Custom json options override (overwrites default configuration)'
|
27
|
+
|
28
|
+
msgs login: 'Using Access Key: %{access_key_id}',
|
29
|
+
create_deploy: 'Creating deployment ... ',
|
30
|
+
done: 'Done: %s',
|
31
|
+
waiting: 'Deploying ',
|
32
|
+
failed: 'Failed.',
|
33
|
+
success: 'Success.',
|
34
|
+
update_app: 'Updating application source branch/revision setting.',
|
35
|
+
app_not_found: 'App %s not found.',
|
36
|
+
timeout: 'Timeout: failed to finish deployment within 10 minutes.',
|
37
|
+
service_error: 'Deployment failed. OpsWorks service error: %s',
|
38
|
+
comment: 'Deploy build %{build_number} via Travis CI'
|
39
|
+
|
40
|
+
def login
|
41
|
+
info :login
|
42
|
+
end
|
43
|
+
|
44
|
+
def deploy
|
45
|
+
timeout(600) { create_deployment }
|
46
|
+
rescue Aws::Errors::ServiceError => e
|
47
|
+
error :service_error, e.message
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_deployment
|
51
|
+
print :create_deploy
|
52
|
+
id = opsworks.create_deployment(deploy_config)[:deployment_id]
|
53
|
+
info :done, id
|
54
|
+
wait_until_deployed(id) if wait_until_deployed?
|
55
|
+
end
|
56
|
+
|
57
|
+
def deploy_config
|
58
|
+
compact(
|
59
|
+
stack_id: stack_id,
|
60
|
+
app_id: app_id,
|
61
|
+
command: { name: 'deploy' },
|
62
|
+
comment: comment,
|
63
|
+
custom_json: custom_json,
|
64
|
+
instance_ids: instance_ids,
|
65
|
+
layer_ids: layer_ids
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def wait_until_deployed(id)
|
70
|
+
print :waiting
|
71
|
+
depl = poll_deployment(id) while depl.nil? || depl[:status] == 'running'
|
72
|
+
error :failed if depl[:status] != 'successful'
|
73
|
+
info :success
|
74
|
+
update_app if update_on_success?
|
75
|
+
end
|
76
|
+
|
77
|
+
def poll_deployment(id)
|
78
|
+
print '.'
|
79
|
+
sleep 5
|
80
|
+
describe_deployments(id)[:deployments].first
|
81
|
+
end
|
82
|
+
|
83
|
+
def update_app
|
84
|
+
info :update_app
|
85
|
+
opsworks.update_app(update_config)
|
86
|
+
end
|
87
|
+
|
88
|
+
def update_config
|
89
|
+
{
|
90
|
+
app_id: app_id,
|
91
|
+
app_source: {
|
92
|
+
revision: git_sha,
|
93
|
+
}
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
def custom_json
|
98
|
+
super || { deploy: { app[:shortname] => { migrate: migrate?, scm: { revision: git_sha } } } }.to_json
|
99
|
+
end
|
100
|
+
|
101
|
+
def stack_id
|
102
|
+
app[:stack_id]
|
103
|
+
end
|
104
|
+
|
105
|
+
def app
|
106
|
+
@app ||= describe_app
|
107
|
+
end
|
108
|
+
|
109
|
+
def comment
|
110
|
+
interpolate(msg(:comment))
|
111
|
+
end
|
112
|
+
|
113
|
+
def build_number
|
114
|
+
super || sha
|
115
|
+
end
|
116
|
+
|
117
|
+
def describe_app
|
118
|
+
data = opsworks.describe_apps(app_ids: [app_id])
|
119
|
+
error :app_not_found, app_id unless data[:apps] && data[:apps].any?
|
120
|
+
data[:apps].first
|
121
|
+
end
|
122
|
+
|
123
|
+
def describe_deployments(id)
|
124
|
+
opsworks.describe_deployments(deployment_ids: [id])
|
125
|
+
end
|
126
|
+
|
127
|
+
def opsworks
|
128
|
+
@opsworks ||= Aws::OpsWorks::Client.new(region: region, credentials: credentials)
|
129
|
+
end
|
130
|
+
|
131
|
+
def credentials
|
132
|
+
Aws::Credentials.new(access_key_id, secret_access_key)
|
133
|
+
end
|
134
|
+
|
135
|
+
def timeout(sec, &block)
|
136
|
+
Timeout::timeout(sec, &block)
|
137
|
+
rescue Timeout::Error
|
138
|
+
error :timeout
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
# talk to previous contributors about the logic in source_files
|
2
|
+
#
|
3
|
+
# the docs recommend to just `packagecloud push src target` https://packagecloud.io/docs#travis
|
4
|
+
|
5
|
+
module Dpl
|
6
|
+
module Providers
|
7
|
+
class Packagecloud < Provider
|
8
|
+
status :alpha
|
9
|
+
|
10
|
+
description sq(<<-str)
|
11
|
+
tbd
|
12
|
+
str
|
13
|
+
|
14
|
+
gem 'packagecloud-ruby', '~> 1.0.8', require: 'packagecloud'
|
15
|
+
|
16
|
+
opt '--username USER', 'The packagecloud.io username.', required: true
|
17
|
+
opt '--token TOKEN', 'The packagecloud.io api token.', required: true, secret: true
|
18
|
+
opt '--repository REPO', 'The repository to push to.', required: true
|
19
|
+
opt '--local_dir DIR', 'The sub-directory of the built assets for deployment.', default: '.'
|
20
|
+
opt '--dist DIST', 'Required for debian, rpm, and node.js packages (use "node" for node.js packages). The complete list of supported strings can be found on the packagecloud.io docs.'
|
21
|
+
opt '--force', 'Whether package has to be (re)uploaded / deleted before upload'
|
22
|
+
opt '--connect_timeout SEC', type: :integer, default: 60
|
23
|
+
opt '--read_timeout SEC', type: :integer, default: 60
|
24
|
+
opt '--write_timeout SEC', type: :integer, default: 180
|
25
|
+
opt '--package_glob GLOB', type: :array, default: ['**/*']
|
26
|
+
|
27
|
+
# previous implementation checks against all of these in dist_required? but
|
28
|
+
# then the error message only lists rmp, deb, python, and dsc. i think the
|
29
|
+
# error message might be out of date? so is the option description in the
|
30
|
+
# readme (and thus above).
|
31
|
+
NEED_DIST = %w(rpm deb dsc whl egg egg-info gz zip tar bz2 z tgz)
|
32
|
+
|
33
|
+
msgs authenticate: 'Logging in to https://packagecloud.io with %{username}:%{token}',
|
34
|
+
timeouts: 'Timeouts: %{timeout_info}',
|
35
|
+
unauthenticated: 'Could not authenticate to https://packagecloud.io, please check the credentials',
|
36
|
+
supported_packages: 'Supported packages: %s',
|
37
|
+
source_packages: 'Source packages: %s',
|
38
|
+
delete_package: 'Deleting package: %s on %s',
|
39
|
+
push_package: 'Pushing package: %s to %s/%s',
|
40
|
+
source_fragment: 'Found source fragment: %s for %s',
|
41
|
+
missing_packages: 'No supported packages found',
|
42
|
+
missing_dist: 'Distribution needed for rpm, deb, python, and dsc packages (e.g. dist: ubuntu/breezy)',
|
43
|
+
unknown_dist: 'Failed to find distribution %{dist}',
|
44
|
+
error: 'Error: %s'
|
45
|
+
|
46
|
+
def install
|
47
|
+
@cwd = Dir.pwd
|
48
|
+
Dir.chdir(local_dir)
|
49
|
+
end
|
50
|
+
|
51
|
+
def login
|
52
|
+
info :authenticate
|
53
|
+
info :timeouts
|
54
|
+
client
|
55
|
+
rescue ::Packagecloud::UnauthenticatedException
|
56
|
+
error :unauthenticated
|
57
|
+
end
|
58
|
+
|
59
|
+
def timeout_info
|
60
|
+
to_pairs(timeouts)
|
61
|
+
end
|
62
|
+
|
63
|
+
def validate
|
64
|
+
error :missing_packages if paths.empty?
|
65
|
+
error :missing_dist if missing_dist?
|
66
|
+
info :supported_packages, paths.join(', ')
|
67
|
+
info :source_packages, source_paths.join(', ') if source_paths.any?
|
68
|
+
end
|
69
|
+
|
70
|
+
def deploy
|
71
|
+
packages.each do |package|
|
72
|
+
delete(package) if force?
|
73
|
+
push(package)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def finish
|
78
|
+
Dir.chdir(@cwd)
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def delete(package)
|
84
|
+
info :delete_package, package.filename, dist
|
85
|
+
result = client.delete_package(repository, *dist.split('/'), package.filename)
|
86
|
+
error "Error #{result.response}" unless result.succeeded
|
87
|
+
end
|
88
|
+
|
89
|
+
def push(package)
|
90
|
+
info :push_package, package.filename, username, repository
|
91
|
+
args = [repository, package]
|
92
|
+
args << distro if dist_required?(package.filename)
|
93
|
+
result = client.put_package(*args)
|
94
|
+
error :error, result.response unless result.succeeded
|
95
|
+
end
|
96
|
+
|
97
|
+
def packages
|
98
|
+
paths.map { |path| package(path) }
|
99
|
+
end
|
100
|
+
|
101
|
+
def package(path)
|
102
|
+
opts = { file: path }
|
103
|
+
opts[:source_files] = source_files(path) if source?(path)
|
104
|
+
::Packagecloud::Package.new(opts)
|
105
|
+
end
|
106
|
+
|
107
|
+
def paths
|
108
|
+
@paths ||= glob(package_glob).select { |path| supported?(path) }
|
109
|
+
end
|
110
|
+
|
111
|
+
def source_paths
|
112
|
+
paths.select { |path| source?(path) }
|
113
|
+
end
|
114
|
+
|
115
|
+
# I believe this resembles the logic in the previous version, but it seems
|
116
|
+
# very odd to me. Files are considered source files only if they are already
|
117
|
+
# part of the package (it looks up the package from the client, and extracts
|
118
|
+
# the file names), and if they are not located in sub directories (it uses
|
119
|
+
# File.basename to filter). Not sure that's how it's supposed to work?
|
120
|
+
def source_files(path)
|
121
|
+
files = contents(path)
|
122
|
+
paths = glob('**/*').select { |path| files.include?(path) }
|
123
|
+
paths = paths.map { |path| [File.basename(path), path] }
|
124
|
+
paths.each { |name, _| info(:source_fragement, name, path) }
|
125
|
+
paths.map { |name, path| [name, open(path)] }.to_h
|
126
|
+
end
|
127
|
+
|
128
|
+
def contents(path)
|
129
|
+
package = ::Packagecloud::Package.new(file: path)
|
130
|
+
result = client.package_contents(repository, package, distro)
|
131
|
+
error :error, result.response unless result.succeeded
|
132
|
+
result.response['files'].map { |file| file['filename'] }
|
133
|
+
end
|
134
|
+
|
135
|
+
def distro
|
136
|
+
@distro ||= client.find_distribution_id(dist) || error(:unknown_dist)
|
137
|
+
rescue ArgumentError => e
|
138
|
+
error :error, e.message
|
139
|
+
end
|
140
|
+
|
141
|
+
def supported?(path)
|
142
|
+
::Packagecloud::SUPPORTED_EXTENSIONS.include?(ext(path))
|
143
|
+
end
|
144
|
+
|
145
|
+
def source?(path)
|
146
|
+
ext(path) == 'dsc'
|
147
|
+
end
|
148
|
+
|
149
|
+
def dist_required?(path)
|
150
|
+
NEED_DIST.include?(ext(path))
|
151
|
+
end
|
152
|
+
|
153
|
+
def package_glob
|
154
|
+
"{#{super.join(',')}}"
|
155
|
+
end
|
156
|
+
|
157
|
+
def timeouts
|
158
|
+
only(opts, :connect_timeout, :read_timeout, :write_timeout)
|
159
|
+
end
|
160
|
+
|
161
|
+
def ext(path)
|
162
|
+
File.extname(path).to_s.gsub('.','').downcase
|
163
|
+
end
|
164
|
+
|
165
|
+
def glob(glob)
|
166
|
+
Dir.glob(glob).reject { |path| File.directory?(path) }
|
167
|
+
end
|
168
|
+
|
169
|
+
def missing_dist?
|
170
|
+
!dist? && paths.any? { |path| dist_required?(path) }
|
171
|
+
end
|
172
|
+
|
173
|
+
def client
|
174
|
+
@client ||= ::Packagecloud::Client.new(credentials, "travis-ci dpl #{Dpl::VERSION}", connection)
|
175
|
+
end
|
176
|
+
|
177
|
+
def credentials
|
178
|
+
::Packagecloud::Credentials.new(username, token)
|
179
|
+
end
|
180
|
+
|
181
|
+
def connection
|
182
|
+
::Packagecloud::Connection.new('https', 'packagecloud.io', '443', timeouts)
|
183
|
+
end
|
184
|
+
|
185
|
+
def to_pairs(hash)
|
186
|
+
hash.map { |pair| pair.join('=') }.join(' ')
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|