Docker building and various fixes around the code.
This commit is contained in:
		
							
								
								
									
										60
									
								
								.drone.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								.drone.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,60 @@ | |||||||
|  | --- | ||||||
|  | kind: pipeline | ||||||
|  | type: docker | ||||||
|  | name: build | ||||||
|  |  | ||||||
|  | steps: | ||||||
|  |   - name: notify-start | ||||||
|  |     image: pztrn/discordrone | ||||||
|  |     settings: | ||||||
|  |       webhook_id: | ||||||
|  |         from_secret: discord_webhook_id | ||||||
|  |       webhook_token: | ||||||
|  |         from_secret: discord_webhook_secret | ||||||
|  |       message: 'Starting building **{{repo.name}}#{{build.number}}@{{commit.sha}}** @ {{datetime build.started "02-Jan-2006 15:04:05 MST" "Asia/Yekaterinburg"}} (See {{build.link}} for logs).' | ||||||
|  |  | ||||||
|  |   - name: lint | ||||||
|  |     image: golangci/golangci-lint:latest | ||||||
|  |     environment: | ||||||
|  |       CGO_ENABLED: 0 | ||||||
|  |     commands: | ||||||
|  |       - golangci-lint run | ||||||
|  |  | ||||||
|  |   - name: test | ||||||
|  |     image: golang:1.13.1-alpine | ||||||
|  |     environment: | ||||||
|  |       GOFLAGS: -mod=vendor | ||||||
|  |       CGO_ENABLED: 0 | ||||||
|  |     commands: | ||||||
|  |       - go test ./... | ||||||
|  |  | ||||||
|  |   - name: docker | ||||||
|  |     image: plugins/docker | ||||||
|  |     when: | ||||||
|  |       branch: | ||||||
|  |         master | ||||||
|  |     settings: | ||||||
|  |       username: | ||||||
|  |         from_secret: dockerhub_user | ||||||
|  |       password: | ||||||
|  |         from_secret: dockerhub_password | ||||||
|  |       repo: pztrn/discordrone | ||||||
|  |       auto_tag: true | ||||||
|  |  | ||||||
|  |   - name: notify-end | ||||||
|  |     when: | ||||||
|  |       status: | ||||||
|  |       - success | ||||||
|  |       - failure | ||||||
|  |     image: pztrn/discordrone | ||||||
|  |     settings: | ||||||
|  |       webhook_id: | ||||||
|  |         from_secret: discord_webhook_id | ||||||
|  |       webhook_token: | ||||||
|  |         from_secret: discord_webhook_secret | ||||||
|  |       message: " | ||||||
|  |         {{#success build.status}} | ||||||
|  |           **{{repo.name}}#{{build.number}}@{{commit.sha}}** built in {{since build.started}} and pushed to hub.docker.com. | ||||||
|  |         {{ else }} | ||||||
|  |           **{{repo.name}}#{{build.number}}@{{commit.sha}}** failed. See {{build.link}}. | ||||||
|  |         {{/success}}" | ||||||
							
								
								
									
										14
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | |||||||
|  | FROM golang:1.13.1-alpine AS build | ||||||
|  |  | ||||||
|  | WORKDIR /discordrone | ||||||
|  | COPY . . | ||||||
|  |  | ||||||
|  | RUN CGO_ENABLED=0 go build -tags netgo -ldflags '-w -extldflags "-static"' | ||||||
|  |  | ||||||
|  | FROM alpine:3.10 | ||||||
|  | LABEL maintainer "Stanislav N. <pztrn@pztrn.name>" | ||||||
|  |  | ||||||
|  | COPY --from=build /discordrone/discordrone /app/discordrone | ||||||
|  | RUN apk add --no-cache ca-certificates | ||||||
|  |  | ||||||
|  | ENTRYPOINT [ "/app/discordrone" ] | ||||||
							
								
								
									
										18
									
								
								env/env.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										18
									
								
								env/env.go
									
									
									
									
										vendored
									
									
								
							| @@ -17,15 +17,15 @@ type environmentData struct { | |||||||
| 	Drone struct { | 	Drone struct { | ||||||
| 		Branch string `envconfig:"optional"` | 		Branch string `envconfig:"optional"` | ||||||
| 		Build  struct { | 		Build  struct { | ||||||
| 			Action   string `envconfig:"optional"` | 			Action   string  `envconfig:"optional"` | ||||||
| 			Created  int    `envconfig:"optional"` | 			Created  float64 `envconfig:"optional"` | ||||||
| 			Event    string `envconfig:"optional"` | 			Event    string  `envconfig:"optional"` | ||||||
| 			Finished int    `envconfig:"optional"` | 			Finished float64 `envconfig:"optional"` | ||||||
| 			Link     string `envconfig:"optional"` | 			Link     string  `envconfig:"optional"` | ||||||
| 			Number   int    `envconfig:"optional"` | 			Number   int     `envconfig:"optional"` | ||||||
| 			Parent   string `envconfig:"optional"` | 			Parent   string  `envconfig:"optional"` | ||||||
| 			Started  int    `envconfig:"optional"` | 			Started  float64 `envconfig:"optional"` | ||||||
| 			Status   string `envconfig:"optional"` | 			Status   string  `envconfig:"optional"` | ||||||
| 		} | 		} | ||||||
| 		CommitHash string `envconfig:"DRONE_COMMIT,optional"` | 		CommitHash string `envconfig:"DRONE_COMMIT,optional"` | ||||||
| 		Commit     struct { | 		Commit     struct { | ||||||
|   | |||||||
| @@ -35,7 +35,7 @@ type ( | |||||||
| 		Title       string             `json:"title"` | 		Title       string             `json:"title"` | ||||||
| 		Description string             `json:"description"` | 		Description string             `json:"description"` | ||||||
| 		URL         string             `json:"url"` | 		URL         string             `json:"url"` | ||||||
| 		Color       int                `json:"color"` | 		Color       int64              `json:"color"` | ||||||
| 		Footer      EmbedFooterObject  `json:"footer"` | 		Footer      EmbedFooterObject  `json:"footer"` | ||||||
| 		Author      EmbedAuthorObject  `json:"author"` | 		Author      EmbedAuthorObject  `json:"author"` | ||||||
| 		Fields      []EmbedFieldObject `json:"fields"` | 		Fields      []EmbedFieldObject `json:"fields"` | ||||||
|   | |||||||
| @@ -1,8 +0,0 @@ | |||||||
| package message |  | ||||||
|  |  | ||||||
| // stdlib |  | ||||||
|  |  | ||||||
| // local |  | ||||||
|  |  | ||||||
| // other |  | ||||||
| //"github.com/drone/drone-template-lib/template" |  | ||||||
| @@ -40,7 +40,7 @@ func Process() error { | |||||||
|  |  | ||||||
| 	// If message was set - format it. | 	// If message was set - format it. | ||||||
| 	if len(env.Data.Plugin.Message) > 0 { | 	if len(env.Data.Plugin.Message) > 0 { | ||||||
| 		text, err := template.RenderTrim(env.Data.Plugin.Message, env.Data) | 		text, err := template.RenderTrim(env.Data.Plugin.Message, env.Data.Drone) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ const ( | |||||||
| 	// DroneIconURL default drone logo url | 	// DroneIconURL default drone logo url | ||||||
| 	droneIconURL = "https://c1.staticflickr.com/5/4236/34957940160_435d83114f_z.jpg" | 	droneIconURL = "https://c1.staticflickr.com/5/4236/34957940160_435d83114f_z.jpg" | ||||||
| 	// DroneDesc default drone description | 	// DroneDesc default drone description | ||||||
| 	droneDesc = "Powered by DiscoDrone Plugin" | 	droneDesc = "Powered by DiscorDrone Plugin" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func createEmbed() EmbedObject { | func createEmbed() EmbedObject { | ||||||
| @@ -54,25 +54,28 @@ func createEmbed() EmbedObject { | |||||||
| 	embed.Description = description | 	embed.Description = description | ||||||
|  |  | ||||||
| 	// Compose color. | 	// Compose color. | ||||||
| 	var color int | 	var color int64 | ||||||
| 	if env.Data.Plugin.Color != "" { | 	if env.Data.Plugin.Color != "" { | ||||||
| 		env.Data.Plugin.Color = strings.Replace(env.Data.Plugin.Color, "#", "", -1) | 		env.Data.Plugin.Color = strings.Replace(env.Data.Plugin.Color, "#", "", -1) | ||||||
| 		if s, err := strconv.ParseInt(env.Data.Plugin.Color, 16, 32); err == nil { | 		s, err := strconv.ParseInt(env.Data.Plugin.Color, 16, 32) | ||||||
| 			color = int(s) | 		if err == nil { | ||||||
|  | 			color = s | ||||||
|  | 		} | ||||||
|  | 	} else { | ||||||
|  |  | ||||||
|  | 		switch env.Data.Drone.Build.Status { | ||||||
|  | 		case "success": | ||||||
|  | 			// green | ||||||
|  | 			color = 0x1ac600 | ||||||
|  | 		case "failure", "error", "killed": | ||||||
|  | 			// red | ||||||
|  | 			color = 0xff3232 | ||||||
|  | 		default: | ||||||
|  | 			// yellow | ||||||
|  | 			color = 0xffd930 | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	switch env.Data.Drone.Build.Status { |  | ||||||
| 	case "success": |  | ||||||
| 		// green |  | ||||||
| 		color = 0x1ac600 |  | ||||||
| 	case "failure", "error", "killed": |  | ||||||
| 		// red |  | ||||||
| 		color = 0xff3232 |  | ||||||
| 	default: |  | ||||||
| 		// yellow |  | ||||||
| 		color = 0xffd930 |  | ||||||
| 	} |  | ||||||
| 	embed.Color = color | 	embed.Color = color | ||||||
|  |  | ||||||
| 	return embed | 	return embed | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user