Skip to content

Commit 4b01fad

Browse files
authored
Merge pull request #75 from GwonsooLee/hotfix_20200806
fix directory structure and base manifest file
2 parents 550b2f0 + 8334cf0 commit 4b01fad

File tree

23 files changed

+198
-176
lines changed

23 files changed

+198
-176
lines changed

configs/hello.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: hello
33
userdata:
44
type: local
5-
path: examples/scripts/userdata.sh
5+
path: scripts/userdata.sh
66

77
autoscaling: &autoscaling_policy
88
- name: scale_in

docs/content/en/schemas/metric.json

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,36 @@
88
"definitions": {
99
"MetricConfig": {
1010
"properties": {
11-
"metrics": {
12-
"$ref": "#/definitions/Metrics",
13-
"description": "Configuration of metrics",
14-
"x-intellij-html-description": "Configuration of metrics"
15-
},
1611
"region": {
1712
"type": "string",
1813
"description": "Base region for gathering metrics",
1914
"x-intellij-html-description": "Base region for gathering metrics"
2015
},
2116
"storage": {
2217
"$ref": "#/definitions/Storage",
23-
"description": "configuration for storing metric data",
24-
"x-intellij-html-description": "configuration for storing metric data"
18+
"description": "Configuration for storage",
19+
"x-intellij-html-description": "Configuration for storage"
2520
}
2621
},
2722
"additionalProperties": false,
2823
"preferredOrder": [
2924
"region",
30-
"storage",
31-
"metrics"
25+
"storage"
3226
],
3327
"description": "Metric Builder Configurations",
3428
"x-intellij-html-description": "Metric Builder Configurations"
3529
},
36-
"Metrics": {
37-
"properties": {
38-
"base_timezone": {
39-
"type": "string",
40-
"description": "Timezone of metrics",
41-
"x-intellij-html-description": "Timezone of metrics"
42-
}
43-
},
44-
"additionalProperties": false,
45-
"preferredOrder": [
46-
"base_timezone"
47-
],
48-
"description": "Configurations of metrics",
49-
"x-intellij-html-description": "Configurations of metrics"
50-
},
5130
"Storage": {
5231
"properties": {
5332
"name": {
5433
"type": "string",
55-
"description": "of storage",
56-
"x-intellij-html-description": "of storage"
34+
"description": "Storage Name",
35+
"x-intellij-html-description": "Storage Name"
5736
},
5837
"type": {
5938
"type": "string",
60-
"description": "of storage",
61-
"x-intellij-html-description": "of storage"
39+
"description": "Storage Type - dynamodb",
40+
"x-intellij-html-description": "Storage Type - dynamodb"
6241
}
6342
},
6443
"additionalProperties": false,

docs/layouts/shortcodes/schema.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
{{ $schema := (readFile $json_schema) | unmarshal }}
1414
{{ if not $schema}}
15-
{{ errorf "missing json schema: %s" .Position }}
15+
{{ errorf "missing json schemas: %s" .Position }}
1616
{{ end }}
1717

1818
{{ $definition := index $schema.definitions $root }}

docs/static/swagger/swagger-ui-bundle.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/static/swagger/swagger-ui-standalone-preset.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/static/swagger/swagger-ui.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hack/schemas/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func main() {
7272

7373
func generateSchemas(root string, dryRun bool, inputFile, outputFile string) (bool, error) {
7474

75-
input := filepath.Join(root, "pkg", "builder", inputFile+".go")
75+
input := filepath.Join(root, "pkg", "schemas", inputFile+".go")
7676
output := filepath.Join(root, "docs", "content", "en", "schemas", outputFile+".json")
7777

7878
generator := Generator{}

pkg/aws/cloudwatch.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package aws
22

33
import (
44
"fmt"
5-
"github.com/DevopsArtFactory/goployer/pkg/builder"
5+
"github.com/DevopsArtFactory/goployer/pkg/schemas"
66
"github.com/DevopsArtFactory/goployer/pkg/tool"
77
"github.com/aws/aws-sdk-go/aws"
88
"github.com/aws/aws-sdk-go/aws/awserr"
@@ -32,7 +32,7 @@ func getCloudwatchClientFn(session *session.Session, region string, creds *crede
3232
}
3333

3434
//CreateScalingAlarms creates scaling alarms
35-
func (c CloudWatchClient) CreateScalingAlarms(asg_name string, alarms []builder.AlarmConfigs, policyArns map[string]string) error {
35+
func (c CloudWatchClient) CreateScalingAlarms(asg_name string, alarms []schemas.AlarmConfigs, policyArns map[string]string) error {
3636
if len(alarms) == 0 {
3737
return nil
3838
}
@@ -53,7 +53,7 @@ func (c CloudWatchClient) CreateScalingAlarms(asg_name string, alarms []builder.
5353
}
5454

5555
// Create cloudwatch alarms for autoscaling group
56-
func (c CloudWatchClient) CreateCloudWatchAlarm(asg_name string, alarm builder.AlarmConfigs) error {
56+
func (c CloudWatchClient) CreateCloudWatchAlarm(asg_name string, alarm schemas.AlarmConfigs) error {
5757
input := &cloudwatch.PutMetricAlarmInput{
5858
AlarmName: aws.String(alarm.Name),
5959
AlarmActions: MakeStringArrayToAwsStrings(alarm.AlarmActions),

pkg/aws/ec2.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package aws
22

33
import (
44
"fmt"
5-
"github.com/DevopsArtFactory/goployer/pkg/builder"
5+
"github.com/DevopsArtFactory/goployer/pkg/schemas"
66
"github.com/DevopsArtFactory/goployer/pkg/tool"
77
"github.com/aws/aws-sdk-go/aws"
88
"github.com/aws/aws-sdk-go/aws/awserr"
@@ -304,7 +304,7 @@ func (e EC2Client) CreateNewLaunchConfiguration(name, ami, instanceType, keyName
304304
}
305305

306306
// Create New Launch Template
307-
func (e EC2Client) CreateNewLaunchTemplate(name, ami, instanceType, keyName, iamProfileName, userdata string, ebsOptimized, mixedInstancePolicyEnabled bool, securityGroups []*string, blockDevices []*ec2.LaunchTemplateBlockDeviceMappingRequest, instanceMarketOptions *builder.InstanceMarketOptions) bool {
307+
func (e EC2Client) CreateNewLaunchTemplate(name, ami, instanceType, keyName, iamProfileName, userdata string, ebsOptimized, mixedInstancePolicyEnabled bool, securityGroups []*string, blockDevices []*ec2.LaunchTemplateBlockDeviceMappingRequest, instanceMarketOptions *schemas.InstanceMarketOptions) bool {
308308
input := &ec2.CreateLaunchTemplateInput{
309309
LaunchTemplateData: &ec2.RequestLaunchTemplateData{
310310
ImageId: aws.String(ami),
@@ -423,7 +423,7 @@ func (e EC2Client) GetSecurityGroupList(vpc string, sgList []string) []*string {
423423
}
424424

425425
// MakeBlockDevices returns list of block device mapping for launch configuration
426-
func (e EC2Client) MakeBlockDevices(blocks []builder.BlockDevice) []*autoscaling.BlockDeviceMapping {
426+
func (e EC2Client) MakeBlockDevices(blocks []schemas.BlockDevice) []*autoscaling.BlockDeviceMapping {
427427
ret := []*autoscaling.BlockDeviceMapping{}
428428

429429
for _, block := range blocks {
@@ -454,7 +454,7 @@ func (e EC2Client) MakeBlockDevices(blocks []builder.BlockDevice) []*autoscaling
454454
}
455455

456456
//MakeLaunchTemplateBlockDeviceMappings returns list of block device mappings for launch template
457-
func (e EC2Client) MakeLaunchTemplateBlockDeviceMappings(blocks []builder.BlockDevice) []*ec2.LaunchTemplateBlockDeviceMappingRequest {
457+
func (e EC2Client) MakeLaunchTemplateBlockDeviceMappings(blocks []schemas.BlockDevice) []*ec2.LaunchTemplateBlockDeviceMappingRequest {
458458
ret := []*ec2.LaunchTemplateBlockDeviceMappingRequest{}
459459

460460
for _, block := range blocks {
@@ -536,11 +536,11 @@ func (e EC2Client) GetVPCId(vpc string) string {
536536

537537
func (e EC2Client) CreateAutoScalingGroup(name, launch_template_name, healthcheck_type string,
538538
healthcheck_grace_period int64,
539-
capacity builder.Capacity,
539+
capacity schemas.Capacity,
540540
loadbalancers, target_group_arns, termination_policies, availability_zones []*string,
541541
tags []*(autoscaling.Tag),
542542
subnets []string,
543-
mixedInstancePolicy builder.MixedInstancesPolicy,
543+
mixedInstancePolicy schemas.MixedInstancesPolicy,
544544
hooks []*autoscaling.LifecycleHookSpecification) (bool, error) {
545545

546546
lt := autoscaling.LaunchTemplateSpecification{
@@ -813,7 +813,7 @@ func (e EC2Client) UpdateAutoScalingGroup(asg string, min, max, desired, retry i
813813
}
814814

815815
//CreateScalingPolicy creates scaling policy
816-
func (e EC2Client) CreateScalingPolicy(policy builder.ScalePolicy, asg_name string) (*string, error) {
816+
func (e EC2Client) CreateScalingPolicy(policy schemas.ScalePolicy, asg_name string) (*string, error) {
817817
input := &autoscaling.PutScalingPolicyInput{
818818
AdjustmentType: aws.String(policy.AdjustmentType),
819819
AutoScalingGroupName: aws.String(asg_name),
@@ -876,7 +876,7 @@ func (e EC2Client) EnableMetrics(asg_name string) error {
876876
}
877877

878878
// Generate Lifecycle Hooks
879-
func (e EC2Client) GenerateLifecycleHooks(hooks builder.LifecycleHooks) []*autoscaling.LifecycleHookSpecification {
879+
func (e EC2Client) GenerateLifecycleHooks(hooks schemas.LifecycleHooks) []*autoscaling.LifecycleHookSpecification {
880880
ret := []*autoscaling.LifecycleHookSpecification{}
881881

882882
if len(hooks.LaunchTransition) > 0 {
@@ -896,7 +896,7 @@ func (e EC2Client) GenerateLifecycleHooks(hooks builder.LifecycleHooks) []*autos
896896
return ret
897897
}
898898

899-
func createSingleLifecycleHookSpecification(l builder.LifecycleHookSpecification, transition string) autoscaling.LifecycleHookSpecification {
899+
func createSingleLifecycleHookSpecification(l schemas.LifecycleHookSpecification, transition string) autoscaling.LifecycleHookSpecification {
900900
lhs := autoscaling.LifecycleHookSpecification{
901901
LifecycleHookName: aws.String(l.LifecycleHookName),
902902
LifecycleTransition: aws.String(transition),

pkg/builder/builder.go

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package builder
33
import (
44
"encoding/base64"
55
"fmt"
6+
"github.com/DevopsArtFactory/goployer/pkg/schemas"
67
"github.com/spf13/viper"
78
"gopkg.in/yaml.v2"
89
"io/ioutil"
@@ -14,6 +15,44 @@ import (
1415
Logger "github.com/sirupsen/logrus"
1516
)
1617

18+
type Builder struct { // Do not add comments for this struct
19+
// Config from command
20+
Config Config
21+
22+
// AWS related Configuration
23+
AwsConfig schemas.AWSConfig
24+
25+
// Configuration for metrics
26+
MetricConfig schemas.MetricConfig
27+
28+
// Stack configuration
29+
Stacks []schemas.Stack
30+
}
31+
32+
type Config struct { // Do not add comments for this struct
33+
Manifest string `json:"manifest"`
34+
ManifestS3Region string `json:"manifest_s3_region"`
35+
Ami string `json:"ami"`
36+
Env string `json:"env"`
37+
Stack string `json:"stack"`
38+
AssumeRole string `json:"assume_role"`
39+
Timeout time.Duration `json:"timeout"`
40+
Region string `json:"region"`
41+
SlackOff bool `json:"slack_off"`
42+
LogLevel string `json:"log_level"`
43+
ExtraTags string `json:"extra_tags"`
44+
AnsibleExtraVars string `json:"ansible_extra_vars"`
45+
OverrideInstanceType string `json:"override_instance_type"`
46+
DisableMetrics bool `json:"disable_metrics"`
47+
ReleaseNotes string `json:"release_notes"`
48+
ReleaseNotesBase64 string `json:"release_notes_base64"`
49+
ForceManifestCapacity bool `json:"force_manifest_capacity"`
50+
PollingInterval time.Duration `json:"polling_interval"`
51+
AutoApply bool `json:"auto-apply"`
52+
Application string `,inline`
53+
StartTimestamp int64 `,inline`
54+
}
55+
1756
var (
1857
NO_MANIFEST_EXISTS = "Manifest file does not exist"
1958
DEFAULT_SPOT_ALLOCATION_STRATEGY = "lowest-price"
@@ -88,15 +127,15 @@ func (b Builder) SetManifestConfigWithS3(fileBytes []byte) Builder {
88127
}
89128

90129
// SetStacks set stack information
91-
func (b Builder) SetStacks(stacks []Stack) Builder {
130+
func (b Builder) SetStacks(stacks []schemas.Stack) Builder {
92131

93132
if len(b.Config.AssumeRole) > 0 {
94133
for i, _ := range stacks {
95134
stacks[i].AssumeRole = b.Config.AssumeRole
96135
}
97136
}
98137

99-
var deployStack Stack
138+
var deployStack schemas.Stack
100139
for _, stack := range stacks {
101140
if b.Config.Stack == stack.Stack {
102141
deployStack = stack
@@ -309,6 +348,11 @@ func (b Builder) CheckValidation() error {
309348
if region.HealthcheckLB != "" && region.HealthcheckTargetGroup != "" {
310349
return fmt.Errorf("you cannot use healthcheck_target_group and healthcheck_load_balancer at the same time")
311350
}
351+
352+
// Check userdata
353+
if stack.Userdata.Type == "local" && len(stack.Userdata.Path) > 0 && !tool.FileExists(stack.Userdata.Path) {
354+
return fmt.Errorf("script file does not exists")
355+
}
312356
}
313357

314358
if stack.MixedInstancesPolicy.Enabled {
@@ -339,9 +383,9 @@ Target Stack Deployment Information
339383
name : %s
340384
env : %s
341385
timeout : %.0f min
342-
polling-interval : %.0f sec
386+
polling-interval : %.0f sec
343387
assume role : %s
344-
ansible-extra-vars : %s
388+
ansible-extra-vars : %s
345389
extra tags : %s
346390
============================================================
347391
Stack
@@ -357,12 +401,12 @@ Stack
357401
return strings.Join(summary, "\n")
358402
}
359403

360-
func printEnvironment(stack Stack) string {
404+
func printEnvironment(stack schemas.Stack) string {
361405
formatting := `[ %s ]
362406
Account : %s
363407
Environment : %s
364408
IAM Instance Profile : %s
365-
tags : %s
409+
tags : %s
366410
Capacity : %+v
367411
MixedInstancesPolicy
368412
- Enabled : %t
@@ -391,28 +435,28 @@ MixedInstancesPolicy
391435
}
392436

393437
// Parsing Manifest File
394-
func ParsingManifestFile(manifest string) (AWSConfig, []Stack) {
438+
func ParsingManifestFile(manifest string) (schemas.AWSConfig, []schemas.Stack) {
395439
var yamlFile []byte
396440
var err error
397441

398442
yamlFile, err = ioutil.ReadFile(manifest)
399443
if err != nil {
400444
Logger.Errorf("Error reading YAML file: %s\n", err)
401-
return AWSConfig{}, nil
445+
return schemas.AWSConfig{}, nil
402446
}
403447

404448
return buildStructFromYaml(yamlFile)
405449
}
406450

407-
func buildStructFromYaml(yamlFile []byte) (AWSConfig, []Stack) {
451+
func buildStructFromYaml(yamlFile []byte) (schemas.AWSConfig, []schemas.Stack) {
408452

409-
yamlConfig := YamlConfig{}
453+
yamlConfig := schemas.YamlConfig{}
410454
err := yaml.Unmarshal(yamlFile, &yamlConfig)
411455
if err != nil {
412456
tool.FatalError(err)
413457
}
414458

415-
awsConfig := AWSConfig{
459+
awsConfig := schemas.AWSConfig{
416460
Name: yamlConfig.Name,
417461
Userdata: yamlConfig.Userdata,
418462
Tags: yamlConfig.Tags,
@@ -455,7 +499,7 @@ func argumentParsing() Config {
455499
}
456500

457501
// Set Userdata provider
458-
func SetUserdataProvider(userdata Userdata, default_userdata Userdata) UserdataProvider {
502+
func SetUserdataProvider(userdata schemas.Userdata, default_userdata schemas.Userdata) UserdataProvider {
459503
//Set default if no userdata exists in the stack
460504
if userdata.Type == "" {
461505
userdata.Type = default_userdata.Type

0 commit comments

Comments
 (0)