Migrate project to Go #1
5 changed files with 98 additions and 2 deletions
36
.drone.yml
36
.drone.yml
|
@ -1,11 +1,39 @@
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: build
|
name: build-go
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Build service
|
||||||
|
image: registry.cuzo.dev/library/golang
|
||||||
|
volumes:
|
||||||
|
- name: deps
|
||||||
|
path: /go
|
||||||
|
commands:
|
||||||
|
- go build -o bin/ cmd/drone-ntfy/main.go
|
||||||
|
- go run cmd/drone-ntfy/main.go
|
||||||
|
|
||||||
|
image_pull_secrets:
|
||||||
|
- custom_mirror_registry
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
- tag
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: build-image
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Build docker image
|
- name: Build docker image
|
||||||
image: registry.cuzo.dev/plugins/docker
|
image: registry.cuzo.dev/plugins/docker
|
||||||
privileged: true
|
privileged: true
|
||||||
|
when:
|
||||||
|
branch:
|
||||||
|
- main
|
||||||
volumes:
|
volumes:
|
||||||
- name: manifest
|
- name: manifest
|
||||||
path: docker
|
path: docker
|
||||||
|
@ -38,6 +66,9 @@ steps:
|
||||||
- name: Upload manifest
|
- name: Upload manifest
|
||||||
image: registry.cuzo.dev/plugins/manifest
|
image: registry.cuzo.dev/plugins/manifest
|
||||||
privileged: true
|
privileged: true
|
||||||
|
when:
|
||||||
|
branch:
|
||||||
|
- main
|
||||||
volumes:
|
volumes:
|
||||||
- name: manifest
|
- name: manifest
|
||||||
path: docker
|
path: docker
|
||||||
|
@ -70,7 +101,8 @@ steps:
|
||||||
from_secret: ntfy_password
|
from_secret: ntfy_password
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- build
|
- build-image
|
||||||
|
- build-go
|
||||||
|
|
||||||
image_pull_secrets:
|
image_pull_secrets:
|
||||||
- custom_mirror_registry
|
- custom_mirror_registry
|
||||||
|
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
.vscode/
|
||||||
|
bin/
|
50
cmd/drone-ntfy/main.go
Normal file
50
cmd/drone-ntfy/main.go
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/caarlos0/env/v7"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
BaseUrl string `env:"PLUGIN_BASE_URL" envDefault:"https://ntfy.sh"`
|
||||||
|
Topic string `env:"PLUGIN_TOPIC,required"`
|
||||||
|
Title string `env:"PLUGIN_TITLE" envDefault:"Drone notification"`
|
||||||
|
Priority string `env:"PLUGIN_PRIORITY" envDefault:"default"`
|
||||||
|
Tags []string `env:"PLUGIN_TAGS" envSeparator:","`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DroneConfig struct {
|
||||||
|
BuildNumber string `envPrefix:"DRONE_"`
|
||||||
|
StageName string `envPrefix:"DRONE_"`
|
||||||
|
StageStatus string `envPrefix:"DRONE_"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CiConfig struct {
|
||||||
|
RepoName string `envPrefix:"CI_"`
|
||||||
|
CommitMessage string `envPrefix:"CI_"`
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULT_PRIORITY = "default"
|
||||||
|
|
||||||
|
const BASE_URL = "https://ntfy.sh"
|
||||||
|
const TOPIC = ""
|
||||||
|
const TITLE = ""
|
||||||
|
const PRIORITY = ""
|
||||||
|
const TAGS = ""
|
||||||
|
|
||||||
|
const MESSAGE = "Build $DRONE_BUILD_NUMBER of $CI_REPO_NAME at stage $DRONE_STAGE_NAME $DRONE_STAGE_STATUS.\n\nCommit: $CI_COMMIT_MESSAGE"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
fmt.Printf("Topic: %s\n", os.Environ())
|
||||||
|
cfg := Config{}
|
||||||
|
err := env.Parse(&cfg)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("unable to parse environment variables: %e", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Config: %v\n", cfg)
|
||||||
|
}
|
8
go.mod
Normal file
8
go.mod
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
module git.parravidales.es/parra/drone-ntfy
|
||||||
|
|
||||||
|
go 1.19
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/caarlos0/env/v7 v7.0.0 // indirect
|
||||||
|
github.com/joho/godotenv v1.5.1 // indirect
|
||||||
|
)
|
4
go.sum
Normal file
4
go.sum
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
github.com/caarlos0/env/v7 v7.0.0 h1:cyczlTd/zREwSr9ch/mwaDl7Hse7kJuUY8hvHfXu5WI=
|
||||||
|
github.com/caarlos0/env/v7 v7.0.0/go.mod h1:LPPWniDUq4JaO6Q41vtlyikhMknqymCLBw0eX4dcH1E=
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
Loading…
Reference in a new issue