Skip to content

Commit

Permalink
Merge pull request #2 from jdbaldry/release
Browse files Browse the repository at this point in the history
feat: Add CI
  • Loading branch information
jdbaldry authored Nov 17, 2020
2 parents 2d2d8a6 + 3c05131 commit f11af5e
Show file tree
Hide file tree
Showing 32 changed files with 804 additions and 0 deletions.
108 changes: 108 additions & 0 deletions .drone/drone.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package drone

let pipeline = {
kind: "pipeline"
platform: {os: "linux", arch: "amd64"}
}

let build_image = "jdbgrafana/haproxy-mixin-build-image:0.0.2"

let step = {
check_artifacts: {
name: "check artifacts"
image: build_image
commands: [
"make build",
"git diff --exit-code",
]
}
}

pipelines: [
pipeline & {
name: "pr"
steps: [
{
name: "check .drone/drone.yml"
image: build_image
commands: [
"make .drone/drone.yml",
"git diff --exit-code -- .drone/drone.yml",
]
},
{
name: "check formatting"
image: build_image
commands: [
"make fmt",
"git diff --exit-code",
]
},
step.check_artifacts,
{
name: "lint mixin"
image: build_image
commands: [
"make lint",
]
},
]
trigger: event: include: ["pull_request"]
},
pipeline & {
name: "default"
steps: [
{
name: "fmt"
image: build_image
commands: [
"make fmt",
]
},
{
name: ".drone/drone.yml"
image: build_image
commands: [
"make .drone/drone.yml",
]
},
{
name: "build"
image: build_image
commands: [
"make build",
]
},
{
name: "lint"
image: build_image
commands: [
"make lint",
]
},
]
trigger: event: include: ["custom"]
},
pipeline & {
name: "release"
steps: [
step.check_artifacts,
{
name: "make dist/haproxy-mixin.tar.gz"
image: build_image
commands: [
"make dist/haproxy-mixin.tar.gz",
]
},
{
name: "publish"
image: "plugins/github-release"
settings: {
api_key: from_secret: "github_token"
files: "dist/*"
}
},
]
trigger: event: include: ["tag"]
},
]
83 changes: 83 additions & 0 deletions .drone/drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: pr
kind: pipeline
platform:
os: linux
arch: amd64
steps:
- name: check .drone/drone.yml
image: jdbgrafana/haproxy-mixin-build-image:0.0.2
commands:
- make .drone/drone.yml
- git diff --exit-code -- .drone/drone.yml
- name: check formatting
image: jdbgrafana/haproxy-mixin-build-image:0.0.2
commands:
- make fmt
- git diff --exit-code
- name: check artifacts
image: jdbgrafana/haproxy-mixin-build-image:0.0.2
commands:
- make build
- git diff --exit-code
- name: lint mixin
image: jdbgrafana/haproxy-mixin-build-image:0.0.2
commands:
- make lint
trigger:
event:
include:
- pull_request
---
name: default
kind: pipeline
platform:
os: linux
arch: amd64
steps:
- name: fmt
image: jdbgrafana/haproxy-mixin-build-image:0.0.2
commands:
- make fmt
- name: .drone/drone.yml
image: jdbgrafana/haproxy-mixin-build-image:0.0.2
commands:
- make .drone/drone.yml
- name: build
image: jdbgrafana/haproxy-mixin-build-image:0.0.2
commands:
- make build
- name: lint
image: jdbgrafana/haproxy-mixin-build-image:0.0.2
commands:
- make lint
trigger:
event:
include:
- custom
---
name: release
kind: pipeline
platform:
os: linux
arch: amd64
steps:
- name: check artifacts
image: jdbgrafana/haproxy-mixin-build-image:0.0.2
commands:
- make build
- git diff --exit-code
- name: make dist/haproxy-mixin.tar.gz
image: jdbgrafana/haproxy-mixin-build-image:0.0.2
commands:
- make dist/haproxy-mixin.tar.gz
- name: publish
image: plugins/github-release
settings:
files: dist/*
api_key:
from_secret: github_token
trigger:
event:
include:
- tag

12 changes: 12 additions & 0 deletions .drone/dump_tool.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package drone

import (
"encoding/yaml"
"tool/cli"
)

command: dump: {
task: print: cli.Print & {
text: yaml.MarshalStream(pipelines)
}
}
5 changes: 5 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if command -v lorri >/dev/null; then
eval "$(lorri direnv)"
fi

export PROMETHEUS_PORT=9091
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/result
/dist/haproxy-mixin.tar.gz
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,27 @@ post: dashboards/$(DASHBOARD)
-H "Authorization: Bearer $${GRAFANA_API_TOKEN}" \
-d "$$(jq '{ "dashboard": ., "overwrite": true }' dashboards/$(DASHBOARD))" \
$(GRAFANA_URL)/api/dashboards/db

.drone/drone.yml: ## Write out YAML drone configuration
.drone/drone.yml: .drone/drone.cue .drone/dump_tool.cue $(wildcard cue.mod/**/github.com/drone/drone-yaml/yaml/*.cue)
cue fmt $<
cue vet -c $<
cue cmd dump ./.drone/ > $@
drone lint $@

.PHONY: haproxy-mixin-build-image
haproxy-mixin-build-image: ## Build the haproxy-mixin-build-image
haproxy-mixin-build-image: build-image.nix common.nix $(wildcard nix/*nix)
docker load --input $$(nix-build build-image.nix)

.PHONY: inspect-build-image
inspect-build-image: ## Inspect the haproxy-mixin-build-image
inspect-build-image:
docker save jdbgrafana/haproxy-mixin-build-image | tar x --to-stdout --wildcards '*/layer.tar' | tar tv | sort -nr -k3

dist:
mkdir -p dist

dist/haproxy-mixin.tar.gz: ## Create a release of the haproxy-mixin artifacts
dist/haproxy-mixin.tar.gz: $(wildcard dashboards/*.json) $(wildcard alerts/*yaml) $(wildcard rules/*.yaml) $(wildcard img/*.png) | dist
tar -c -f $@ $^
10 changes: 10 additions & 0 deletions build-image.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let
common = import ./common.nix;
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs { };
in pkgs.dockerTools.buildImage {
name = "jdbgrafana/haproxy-mixin-build-image";
created = "now";
tag = "0.0.1";
contents = common.buildTools;
}
29 changes: 29 additions & 0 deletions common.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
let
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs {
overlays = [
(self: super:
let inherit (super) callPackage;
in {
jsonnet-bundler = callPackage ./nix/jsonnet-bundler.nix { };
mixtool = callPackage ./nix/mixtool.nix { };
})
];
};
in {
# devTools are packages specifically for development environments.
devTools = [ pkgs.docker pkgs.docker-compose ];
# buildTools are packages needed for dev and CI builds.
buildTools = [
pkgs.bash
pkgs.coreutils
pkgs.cue
pkgs.drone-cli
pkgs.git
pkgs.gnumake
pkgs.gnutar
pkgs.jsonnet
pkgs.jsonnet-bundler
pkgs.mixtool
];
}
14 changes: 14 additions & 0 deletions cue.mod/gen/github.com/drone/drone-yaml/yaml/build_go_gen.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go github.com/drone/drone-yaml/yaml

package yaml

#Build: {
args?: {[string]: string} @go(Args,map[string]string)
cache_from?: [...string] @go(CacheFrom,[]string)
context?: string @go(Context)
dockerfile?: string @go(Dockerfile)
image?: string @go(Image)
labels?: {[string]: string} @go(Labels,map[string]string)
}
26 changes: 26 additions & 0 deletions cue.mod/gen/github.com/drone/drone-yaml/yaml/cond_go_gen.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go github.com/drone/drone-yaml/yaml

package yaml

// Conditions defines a group of conditions.
#Conditions: {
action?: #Condition @go(Action)
cron?: #Condition @go(Cron)
ref?: #Condition @go(Ref)
repo?: #Condition @go(Repo)
instance?: #Condition @go(Instance)
target?: #Condition @go(Target)
event?: #Condition @go(Event)
branch?: #Condition @go(Branch)
status?: #Condition @go(Status)
paths?: #Condition @go(Paths)
matrix?: {[string]: string} @go(Matrix,map[string]string)
}

// Condition defines a runtime condition.
#Condition: {
include?: [...string] @go(Include,[]string)
exclude?: [...string] @go(Exclude,[]string)
}
23 changes: 23 additions & 0 deletions cue.mod/gen/github.com/drone/drone-yaml/yaml/cron_go_gen.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go github.com/drone/drone-yaml/yaml

package yaml

#Cron: {
version?: string @go(Version)
kind?: string @go(Kind)
type?: string @go(Type)
name?: string @go(Name)
spec?: #CronSpec @go(Spec)
}

#CronSpec: {
schedule?: string @go(Schedule)
branch?: string @go(Branch)
deployment?: #CronDeployment @go(Deploy)
}

#CronDeployment: {
target?: string @go(Target)
}
10 changes: 10 additions & 0 deletions cue.mod/gen/github.com/drone/drone-yaml/yaml/env_go_gen.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go github.com/drone/drone-yaml/yaml

package yaml

#Variable: {
value?: string @go(Value)
from_secret?: string @go(Secret)
}
23 changes: 23 additions & 0 deletions cue.mod/gen/github.com/drone/drone-yaml/yaml/manifest_go_gen.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go github.com/drone/drone-yaml/yaml

package yaml

#KindCron: "cron"
#KindPipeline: "pipeline"
#KindRegistry: "registry"
#KindSecret: "secret"
#KindSignature: "signature"

#Manifest: {
Resources: [...#Resource] @go(,[]Resource)
}

#Resource: _

#RawResource: {
Version: string
Kind: string
Type: string
}
10 changes: 10 additions & 0 deletions cue.mod/gen/github.com/drone/drone-yaml/yaml/param_go_gen.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go github.com/drone/drone-yaml/yaml

package yaml

#Parameter: {
value?: _ @go(Value,interface{})
from_secret?: string @go(Secret)
}
Loading

0 comments on commit f11af5e

Please sign in to comment.