Skip to content

Commit

Permalink
ci: onboarding files from repo-template-razee
Browse files Browse the repository at this point in the history
bringing common files in template up to date
template: repo-template-razee
branch: main
commit: 346a51babd6f3322acf3d64763f89a41779c5b2f

Ref: REL-91
  • Loading branch information
charlesthomas committed Dec 17, 2021
1 parent 3b9a82d commit b9086dc
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @answerbook/release-engineering
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tmp/
release/
2 changes: 2 additions & 0 deletions .repo-template-razee-answers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_last_applied_template_hash: 346a51b
_src_path: /tmp/filesync_clones/repo-template-razee
9 changes: 9 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extends: relaxed

rules:
empty-lines:
max-end: 3
indentation:
spaces: consistent
indent-sequences: whatever
line-length: disable
56 changes: 56 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
def BRANCH_ACTUAL = env.CHANGE_BRANCH ? env.CHANGE_BRANCH : env.BRANCH_NAME
pipeline {
agent {
node {
label 'ec2-fleet'
customWorkspace("/tmp/workspace/${env.BUILD_TAG}")
}
}

options {
timeout time: 1, unit: 'HOURS'
timestamps()
ansiColor 'xterm'
}

environment {
GITHUB_TOKEN = credentials('github-api-token')
}

stages {
stage('Setup') {
steps {
sh "git checkout ${BRANCH_ACTUAL}"
}
}

stage('Build') {
steps {
sh 'make build'
archiveArtifacts allowEmptyArchive: true, artifacts: 'release/*.yaml', caseSensitive: false, followSymlinks: false
}
}

stage('Lint') {
steps {
sh 'make lint'
}
}

stage('Test') {
steps {
sh 'make test'
}
}

stage('Publish') {
when {
branch 'main'
}

steps {
sh 'make publish'
}
}
}
}
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
APP_NAME := $(shell git remote -v | awk '/origin/ && /fetch/ { sub(/\.git/, ""); n=split($$2, origin, "/"); print origin[n]}')
BUILD_DATESTAMP := $(shell date -u '+%Y%m%dT%H%M%SZ')
GIT_BRANCH := $(shell git branch --show-current)
GIT_SHA1 := $(shell git log --pretty=format:'%h' -n 1)
GIT_URL := $(shell git remote get-url origin | sed 's/https:\/\/.*\@github.com/https:\/\/github.com/')

BUILD_DIR ?= deployment/kubernetes
BUILD_ENV ?= $(TMP_DIR)/build-env
ifndef BUILD_TAG
BUILD_TAG := localbuild://${USER}@$(shell uname -n | sed "s/'//g")
endif
ORG_NAME ?= answerbook
RELEASE_BRANCHES ?= main
RELEASE_DIR ?= release
TMP_DIR ?= tmp

DOCKER_RUN ?= docker run --rm -i
DOCKER_RUN_BUILD_ENV ?= $(DOCKER_RUN) --env-file=$(BUILD_ENV)

ENVSUBST_COMMAND ?= $(DOCKER_RUN_BUILD_ENV) -v $(PWD):/data:Z bhgedigital/envsubst envsubst "$$(printf '$${%s} ' $$(cut -f1 -d'=' ${BUILD_ENV}))"
GH_COMMAND ?= $(DOCKER_RUN) -e GITHUB_TOKEN -v $(PWD):/data:Z -w /data us.gcr.io/logdna-k8s/gh:latest gh
KUBEVAL_COMMAND ?= $(DOCKER_RUN) -v $(PWD):/data:Z garethr/kubeval --ignore-missing-schemas
YAMLLINT_COMMAND ?= $(DOCKER_RUN) -v $(PWD):/data:Z cytopia/yamllint:latest

BUILD_ARTIFACTS := $(wildcard $(BUILD_DIR)/*.yaml.envsubst)
RELEASE_ARTIFACTS := $(patsubst $(BUILD_DIR)/%.envsubst, $(RELEASE_DIR)/%, $(BUILD_ARTIFACTS))
RELEASE_VERSION := $(BUILD_DATESTAMP)

include versions.mk

export

.PHONY:build clean debug-% lint publish test

DRAFT =
ifneq ($(GIT_BRANCH), $(filter $(RELEASE_BRANCHES), $(GIT_BRANCH)))
DRAFT = --draft
endif

$(RELEASE_DIR) $(TMP_DIR):
@mkdir -p $(@)

$(RELEASE_DIR)/%: $(BUILD_DIR)/%.envsubst $(BUILD_ENV) | $(RELEASE_DIR)
$(ENVSUBST_COMMAND) < $(<) > $(@)

$(BUILD_ENV): $(TMP_DIR)
@env | awk '!/TOKEN/ && /^(GIT|BUILD|WAVE)/ { print }' | sort > $(@)

build: $(RELEASE_ARTIFACTS)

clean:
rm -rf $(RELEASE_DIR) $(TMP_DIR)

debug-%: ## Debug a variable by calling `make debug-VARIABLE`
@echo $(*) = $($(*))

lint: $(RELEASE_ARTIFACTS)
$(YAMLLINT_COMMAND) /data/$(RELEASE_DIR)

publish: $(RELEASE_ARTIFACTS)
$(GH_COMMAND) release create --repo $(ORG_NAME)/$(APP_NAME) $(DRAFT) $(RELEASE_VERSION) $(RELEASE_ARTIFACTS)

test: $(RELEASE_ARTIFACTS)
$(KUBEVAL_COMMAND) -d /data/$(RELEASE_DIR)

0 comments on commit b9086dc

Please sign in to comment.