docker-publish 0.0.2 → 0.0.3

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: ece2c1e991dbe762ca4d4c492fded71a2abed48f
4
- data.tar.gz: d340a2140194cc2479c36aaf11dcc711480e8b30
3
+ metadata.gz: f8875d5dbe700e32e0aea142a31b96e2b9616884
4
+ data.tar.gz: c34f814ee3d4d6236b672ac46c6eba7c985142b8
5
5
  SHA512:
6
- metadata.gz: 79d878520d704d43758b431c6bb16b50d5e3aee6721a850933ad703637d57b385c1297a57fb9a0aa7453778759252884e02732dd1156bd1cb27ea3550deedf77
7
- data.tar.gz: 49af2e42a9c0dc1fa9a59d9df38683f20a5015f5a049495829cc1cf39d505f32fd14a2bccd5ddc6864a0b3999a020ba90e4aa6119920969e1c0e65682373dd44
6
+ metadata.gz: 47385b2fbeb3123ea3309c68af1d40314d953befbc69555d4b8217caef3f3f1e929a32ca0226edb5b264e447eecfb0ead2dcce1314acfc77c8d1813af05724bd
7
+ data.tar.gz: f77697fe25a28e5a8c012ab90689e12a3d17c6a2c6c64e4056d8f1bb6ad0205101d3bd21695c3aed1725289b649f9aa85001938b32a179f04077b4f7ff54b0cd
@@ -7,11 +7,10 @@ class DockerCompose
7
7
  end
8
8
 
9
9
  # @param [string] dist_file_path
10
- # @param [string] duty
11
10
  # @param [int] port
12
11
  # @param [string] image_tag
13
12
  # @return [File]
14
- def generate_compose_yaml(dist_file_path, duty, port, image_tag, out_filename)
13
+ def generate_compose_yaml(dist_file_path, port, image_tag, out_filename)
15
14
  path = File.dirname(dist_file_path)
16
15
  file_path = "#{path}/#{out_filename}"
17
16
 
@@ -29,5 +28,4 @@ class DockerCompose
29
28
  out_file
30
29
  end
31
30
 
32
-
33
31
  end
@@ -0,0 +1,66 @@
1
+ class GoogleCloudCompute
2
+
3
+ def initialize(project_name, app_name, credentials_path)
4
+ @project_name = project_name
5
+ @app_name = app_name
6
+
7
+ @client = Google::APIClient.new(
8
+ :application_name => 'docker-publish',
9
+ :application_version => '0.0.2'
10
+ )
11
+
12
+ json_key = JSON.parse(File.read(credentials_path))
13
+ gauth = {
14
+ token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
15
+ audience: 'https://accounts.google.com/o/oauth2/token',
16
+ scope: 'https://www.googleapis.com/auth/compute',
17
+ issuer: json_key['client_email'],
18
+ signing_key: OpenSSL::PKey::RSA.new(json_key['private_key'])
19
+ }
20
+ @client.authorization = Signet::OAuth2::Client.new(gauth)
21
+ @client.authorization.fetch_access_token!
22
+
23
+ @compute = @client.discovered_api('compute')
24
+
25
+ @replica_pool = GoogleCloudReplicaPool.new(project_name, app_name, credentials_path)
26
+ end
27
+
28
+ def create_instance_template(machine_type, startup_script_uri)
29
+ puts 'Creating Google Cloud Compute instance template'
30
+
31
+ dist_file_path = File.join(File.dirname(__FILE__), 'instance-template.json.dist')
32
+ dist_request_json = File.read(dist_file_path)
33
+
34
+ dist_request_json = dist_request_json.gsub('<project_name>', @project_name)
35
+ dist_request_json = dist_request_json.gsub('<app_name>', @app_name)
36
+ dist_request_json = dist_request_json.gsub('<startup_script_uri>', startup_script_uri)
37
+ dist_request_json = dist_request_json.gsub('<machine_type>', machine_type)
38
+
39
+ result = @client.execute(
40
+ :api_method => @compute.instance_templates.insert,
41
+ :parameters => {:project => @project_name},
42
+ :body_object => JSON.parse(dist_request_json)
43
+ )
44
+
45
+ puts result.response.body
46
+
47
+ # wait for instance template to be created
48
+ while result.data['status'] != 'DONE' and result.data['progress'] < 100
49
+ puts "#{result.data['status']} - #{result.data['progress']}%"
50
+ result = @client.execute(
51
+ :uri => result.data['selfLink']
52
+ )
53
+ sleep 0.5
54
+ end
55
+ puts "#{result.data['status']} - #{result.data['progress']}%"
56
+
57
+ result.data['targetLink']
58
+ end
59
+
60
+ def replica_pool
61
+ @replica_pool
62
+ end
63
+ end
64
+
65
+ require 'google/api_client'
66
+ require 'infrastructure/google_cloud_platform/google_cloud_replica_pool'
@@ -11,6 +11,7 @@ class GoogleCloudPlatform
11
11
  exit 1
12
12
  end
13
13
  @google_cloud_storage = GoogleCloudStorage.new(@project_name, @app_name, @credentials)
14
+ @google_cloud_compute = GoogleCloudCompute.new(@project_name, @app_name, @credentials)
14
15
 
15
16
  @branch = `git rev-parse --abbrev-ref HEAD`.strip
16
17
  @commit = `git rev-parse --short HEAD`.strip
@@ -61,6 +62,13 @@ class GoogleCloudPlatform
61
62
  def storage
62
63
  @google_cloud_storage
63
64
  end
65
+
66
+ # @return [GoogleCloudCompute]
67
+ def compute
68
+ @google_cloud_compute
69
+ end
70
+
64
71
  end
65
72
 
66
- require 'infrastructure/google_cloud_platform/google_cloud_storage'
73
+ require 'infrastructure/google_cloud_platform/google_cloud_storage'
74
+ require 'infrastructure/google_cloud_platform/google_cloud_compute'
@@ -0,0 +1,47 @@
1
+ class GoogleCloudReplicaPool
2
+
3
+ def initialize(project_name, app_name, credentials_path)
4
+ @project_name = project_name
5
+ @app_name = app_name
6
+
7
+ @client = Google::APIClient.new(
8
+ :application_name => 'docker-publish',
9
+ :application_version => '0.0.2'
10
+ )
11
+
12
+ json_key = JSON.parse(File.read(credentials_path))
13
+ gauth = {
14
+ token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
15
+ audience: 'https://accounts.google.com/o/oauth2/token',
16
+ scope: 'https://www.googleapis.com/auth/compute',
17
+ issuer: json_key['client_email'],
18
+ signing_key: OpenSSL::PKey::RSA.new(json_key['private_key'])
19
+ }
20
+ @client.authorization = Signet::OAuth2::Client.new(gauth)
21
+ @client.authorization.fetch_access_token!
22
+
23
+ @replica_pool = @client.discovered_api('replicapool', 'v1beta2')
24
+ end
25
+
26
+ def create_instance_group(template_uri, zone, size)
27
+ result = @client.execute(
28
+ :api_method => @replica_pool.instance_group_managers.insert,
29
+ :parameters => {
30
+ :project => @project_name,
31
+ :zone => zone,
32
+ :size => size
33
+ },
34
+ :body_object => {
35
+ name: @app_name,
36
+ instanceTemplate: template_uri,
37
+ baseInstanceName: @app_name
38
+ }
39
+ )
40
+
41
+ puts result.response.body
42
+
43
+ result
44
+ end
45
+ end
46
+
47
+ require 'google/api_client'
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "<app_name>",
3
+ "properties": {
4
+ "disks": [
5
+ {
6
+ "type": "PERSISTENT",
7
+ "boot": true,
8
+ "mode": "READ_WRITE",
9
+ "deviceName": "<app_name>",
10
+ "autoDelete": true,
11
+ "initializeParams": {
12
+ "sourceImage": "https://www.googleapis.com/compute/v1/projects/coreos-cloud/global/images/coreos-stable-681-2-0-v20150618",
13
+ "diskType": "pd-ssd"
14
+ }
15
+ }
16
+ ],
17
+ "networkInterfaces": [
18
+ {
19
+ "network": "https://www.googleapis.com/compute/v1/projects/<project_name>/global/networks/default",
20
+ "accessConfigs": [
21
+ {
22
+ "name": "External NAT",
23
+ "type": "ONE_TO_ONE_NAT"
24
+ }
25
+ ]
26
+ }
27
+ ],
28
+ "metadata": {
29
+ "items": [
30
+ {
31
+ "key": "startup-script-url",
32
+ "value": "<startup_script_uri>"
33
+ }
34
+ ]
35
+ },
36
+ "tags": {
37
+ "items": [
38
+ "http-server",
39
+ "https-server"
40
+ ]
41
+ },
42
+ "canIpForward": false,
43
+ "scheduling": {
44
+ "preemptible": false,
45
+ "automaticRestart": true,
46
+ "onHostMaintenance": "MIGRATE"
47
+ },
48
+ "machineType": "<machine_type>",
49
+ "serviceAccounts": [
50
+ {
51
+ "email": "default",
52
+ "scopes": [
53
+ "https://www.googleapis.com/auth/devstorage.read_only",
54
+ "https://www.googleapis.com/auth/sqlservice.admin",
55
+ "https://www.googleapis.com/auth/logging.write"
56
+ ]
57
+ }
58
+ ]
59
+ }
60
+ }
@@ -1,12 +1,22 @@
1
1
  #!/bin/bash
2
2
 
3
+ # Download docker-compose
4
+ mkdir ~/bin
5
+ curl -L https://github.com/docker/compose/releases/download/1.3.0/docker-compose-`uname -s`-`uname -m` > ~/bin/docker-compose
6
+ chmod +x ~/bin/docker-compose
7
+ export PATH=$PATH:~/bin/
8
+
9
+ # fetch proxy container and proxy configuration
10
+ gsutil cp gs://<bucket_name>/proxy/<branch>_proxy.conf .
11
+ docker run -d --name <app_name>_proxy -p 80:80 -v `pwd`/<branch>_proxy.conf:/etc/nginx/sites-enabled/default vjftw/nginx
12
+
3
13
  gsutil cp gs://<bucket_name>/docker-compose/<primary_yaml> .
4
14
  gsutil cp gs://<bucket_name>/docker-compose/<backup_yaml> .
5
15
 
6
16
  # Pull Primary Containers and start them (faster service availability)
7
- docker-compose pull -p <app_name> -f <primary_yaml>
8
- docker-compose up -p <app_name> -f <primary_yaml> -d
17
+ docker-compose pull -p <app_name>_primary -f <primary_yaml>
18
+ docker-compose up -p <app_name>_primary -f <primary_yaml> -d
9
19
 
10
20
  # Pull Backup containers and start them
11
- docker-compose pull -p <app_name> -f <backup_yaml>
12
- docker-compose up -p <app_name> -f <backup_yaml> -d
21
+ docker-compose pull -p <app_name>_backup -f <backup_yaml>
22
+ docker-compose up -p <app_name>_backup -f <backup_yaml> -d
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-publish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - VJ Patel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-17 00:00:00.000000000 Z
11
+ date: 2015-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gcloud
@@ -42,8 +42,11 @@ files:
42
42
  - lib/deploy/deploy.rb
43
43
  - lib/deploy/docker_compose.rb
44
44
  - lib/docker_publish.rb
45
+ - lib/infrastructure/google_cloud_platform/google_cloud_compute.rb
45
46
  - lib/infrastructure/google_cloud_platform/google_cloud_platform.rb
47
+ - lib/infrastructure/google_cloud_platform/google_cloud_replica_pool.rb
46
48
  - lib/infrastructure/google_cloud_platform/google_cloud_storage.rb
49
+ - lib/infrastructure/google_cloud_platform/instance-template.json.dist
47
50
  - lib/infrastructure/google_cloud_platform/startup.sh.dist
48
51
  - lib/infrastructure/infrastructure.rb
49
52
  homepage: http://rubygems.org/gems/docker-publish