Skip to content

Commit

Permalink
Added ci pipeline, altered Makefile for better ci support
Browse files Browse the repository at this point in the history
Updated Makefile for pipeline support

Updated .gitignore for build artifacts renaming

Further refinements to Makefile in support of pipeline

[wip] Started CI pipeline addition

[ci] Iterating on getting pipeline working

[ci] Run make from the repo root

Make quoting rules make me mad

[ci] don't need to copy src into gopath when using gomod

Also fixed cmd_path and static_binary issues

[ci] Fix paths for repo and tar target

Make variable fixes (who knew there are 5 different assignment operators)

[ci] Get build job working

Renaming and including version for app tag

[ci] Update test script

[ci] update build task in release

[ci] build has version in name, must specify correctly in tar call
  • Loading branch information
dennisjbell committed Jul 21, 2023
1 parent d7756f5 commit b0a7655
Show file tree
Hide file tree
Showing 38 changed files with 1,719 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
*~
*.swp
/scheduler
/scheduler-for-ocf
/ocf-scheduler
/scheduler-*.tar.gz
/coverage.out
/ignoremelol
/demo
/builds
38 changes: 21 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# This how we want to name the binary output
BINARY=scheduler
APP_NAME ?= scheduler

# These are the values we want to pass for VERSION and BUILD
# git tag 1.0.1
# git commit -am "One more change after the tags"
VERSION=`./scripts/genver`
BUILD=`date +%FT%T%z`
PACKAGE="github.com/starkandwayne/scheduler-for-ocf/cmd/scheduler"
TARGET="builds/${BINARY}-${VERSION}"
PREFIX="${TARGET}/${BINARY}-${VERSION}"
VERSION ?= `./scripts/genver` (dev)

MODULE ?= github.com/cloudfoundry-community/ocf-scheduler
CMD_PATH ?= cmd/scheduler
CGO_ENABLED ?= 0
BUILD_PATH=builds
BUILD=${APP_NAME}-${VERSION}
TESTFILES=`go list ./... | grep -v /vendor/`

# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS=-ldflags "-w -s \
-extldflags '-static'"
LDFLAGS := -w -s -X main.Version=$(VERSION)
ifeq ($(CGO_ENABLED),0)
LDFLAGS += -extldflags '-static'
endif

# Build for the current platform
all: clean build
Expand All @@ -23,34 +27,34 @@ release: distclean distbuild linux package

# Builds the project
build:
go build ${LDFLAGS} -o ${BINARY} ${PACKAGE}
go build -ldflags="${LDFLAGS}" -o "${APP_NAME}" "${MODULE}/${CMD_PATH}"

cli:
go build ${LDFLAGS} -o sch github.com/starkandwayne/scheduler-for-ocf/cmd/cli
$(MAKE) build APP_NAME=sch CMD_PATH=cmd/cli


# Builds the project for all possible platforms
distbuild:
mkdir -p ${TARGET}
mkdir -p ${BUILD_PATH}

# Installs our project: copies binaries
install:
go install ${LDFLAGS}
go install -ldflags="${LDFLAGS}"

# Cleans our project: deletes binaries
clean:
rm -rf ${BINARY}
rm -rf ${APP_NAME}

# Cleans release files
distclean:
rm -rf ${TARGET} ${TARGET}.tar.gz
rm -rf ${BUILD_PATH} ${APP_NAME}-*.tar.gz

test:
./scripts/blanket

linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o ${TARGET}/${BINARY}-linux-amd64 ${PACKAGE}
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build ${LDFLAGS} -o ${TARGET}/${BINARY}-linux-arm ${PACKAGE}
CGO_ENABLED=${CGO_ENABLED} GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o "${BUILD_PATH}/${BUILD}-linux-amd64" "${MODULE}/${CMD_PATH}"
CGO_ENABLED=${CGO_ENABLED} GOOS=linux GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o "${BUILD_PATH}/${BUILD}-linux-arm64" "${MODULE}/${CMD_PATH}"

package:
tar -C builds -z -c -v -f ${TARGET}.tar.gz ${BINARY}-${VERSION}
cd builds && tar -z -c -v -f ../${BUILD}.tar.gz "${BUILD}"-*
26 changes: 26 additions & 0 deletions ci/ddconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
backends:
- type: vault
name: (( grab meta.name ))
refresh_interval: 30
properties:
# (string) The URL where the Vault API is located
address: (( grab meta.url ))
insecure_skip_verfiy: true
base_path: "secret/"
auth:
token: (( grab $SAFE_TOKEN ))

# (hash) Configuration for the doomsday server API
server:
port: 8111
tls:
cert: (( vault "secret/dd/ssl:certificate" ))
key: (( vault "secret/dd/ssl:key" ))

auth:
type: userpass
properties:
username: admin
password: password
timeout: 30
refresh: true
83 changes: 83 additions & 0 deletions ci/pipeline/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
#
# ci/pipeline/base.yml
#
# Pipeline structure file for a Go Project pipeline
#
# DO NOT MAKE CHANGES TO THIS FILE. Instead, modify
# ci/settings.yml and override what needs overridden.
# This uses spruce, so you have some options there.
#
# author: Dennis Bell <[email protected]>
# Wayne Seguin <[email protected]>
# created: 2023-05-30

groups:
- name: (( concat "build-" meta.pipeline "-releases" ))
jobs:
- build
- ship-prerelease
- test
- prepare
- ship-release
- name: (( concat "test-" meta.pipeline "-pull-requests" ))
jobs:
- test-pr
- name: version
jobs:
- major
- minor
- patch

meta:
name: (( param "Please name your pipeline" ))
release: (( concat meta.name " Release" ))
target: (( param "Please identify the name of the target Concourse CI" ))
pipeline: (( grab meta.name ))

git:
email: (( param "Please provide the git email for automated commits" ))
name: (( param "Please provide the git name for automated commits" ))

go:
module: (( concat "github.com/" meta.github.owner "/" meta.github.repo ))
cmd_module: (( grab meta.go.module ))
binary: (( grab meta.github.repo ))
force_static_binary: false

image:
name: genesiscommunity/concourse-go
tag: latest

aws:
bucket: (( concat meta.pipeline "-pipeline" ))
region_name: us-east-1
access_key: (( param "Please set your AWS Access Key ID" ))
secret_key: (( param "Please set your AWS Secret Key ID" ))

github:
uri: (( concat "[email protected]:" meta.github.owner "/" meta.github.repo ))
owner: (( param "Please specify the name of the user / organization that owns the Github repository" ))
repo: (( param "Please specify the name of the Github repository" ))
branch: develop
private_key: (( param "Please generate an SSH Deployment Key for this repo and specify it here" ))
access_token: (( param "Please generate a Personal Access Token and specify it here" ))
release_notes:
repo: "ci-release-notes"
branch: "main"
file: (( concat meta.name "-release-notes.md" ))
uri: (( concat "[email protected]:" meta.github.owner "/" meta.github.release_notes.repo ))
edit: (( concat "https://github.com/" meta.github.owner "/" meta.github.release_notes.repo "/edit/" meta.github.release_notes.branch "/" meta.github.release_notes.file ))

slack:
webhook: (( param "Please specify your Slack Incoming Webhook Integration URL" ))
notification: '(( concat ":sadpanda: " meta.pipeline " build failed!<br>URL-GOES-HERE" ))'
username: concourse
icon: http://cl.ly/image/3e1h0H3H2s0P/concourse-logo.png
fail_moji: ":airplane_arriving:"
success_moji: ":airplane_departure:"
upset_moji: ":sad_panda:"
fail_url: '(( concat "<" meta.url "/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME| Concourse Failure! " meta.slack.upset_moji ">" ))'

url: (( param "What is the URL for the Concourse instance this pipeline is located on?" ))

29 changes: 29 additions & 0 deletions ci/pipeline/jobs/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
jobs:
- name: build
public: true
serial: false
plan:
- in_parallel:
- { get: version, params: {pre: rc} }
- { get: git, trigger: true }
- { get: git-ci }
- task: build
file: git-ci/ci/tasks/build.yml
params:
APP_NAME: (( grab meta.app_name || meta.name ))
MODULE: (( grab meta.go.module ))
CMD_PATH: (( grab meta.go.cmd_path ))
STATIC_BINARY: (( grab meta.go.force_static_binary ))
- put: build
params:
file: build/*.tar.gz
acl: public-read
- put: version
params: {file: version/number}

on_failure:
put: notify
params:
username: (( grab meta.slack.username ))
icon_url: (( grab meta.slack.icon ))
text: '(( concat meta.slack.fail_url " " meta.pipeline ": test job failed" ))'
41 changes: 41 additions & 0 deletions ci/pipeline/jobs/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
jobs:
- name: prepare
public: true
serial: true
plan:
- do:
- in_parallel:
- { get: version, passed: [test], params: {bump: final} }
- { get: git, passed: [test], trigger: true }
- { get: git-ci }
- { get: git-latest-tag }
- { get: release-notes }
- task: generate-release-notes
file: git-ci/ci/tasks/generate-release-notes.yml
params:
RELEASE_NOTES_WEB_URL: (( grab meta.github.release_notes.edit ))
RELEASE_NOTES_FILE: (( grab meta.github.release_notes.file ))
GIT_NAME: (( grab meta.git.name ))
GIT_EMAIL: (( grab meta.git.email ))
APP_NAME: (( grab meta.name ))
NO_UPSTREAM_SYNC: true
NO_RELEASE_VERSIONS: true
- put: release-notes
params:
rebase: true
repository: release-notes
on_failure:
put: notify
params:
username: (( grab meta.slack.username ))
icon_url: (( grab meta.slack.icon ))
text: '(( concat meta.slack.fail_url " " meta.pipeline ": prepare job failed" ))'

# Shout-based notification when its working again
# on_failure:
# put: notify
# params:
# topic: (( concat meta.shout.topic "-$BUILD_JOB_NAME" ))
# message: release candidate job 'pre' failed (which is unusual).
# ok: no
# link: (( grab meta.shout.links.build ))
49 changes: 49 additions & 0 deletions ci/pipeline/jobs/ship-prerelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
jobs:
- name: ship-prerelease
public: true
serial: false
plan:
- do:
- in_parallel:
- { get: build, passed: [build]}
- { get: version, passed: [build]}
- { get: git, passed: [build]}
- { get: git-ci }

- task: ship-prerelease
file: git-ci/ci/tasks/prerelease.yml
params:
PRERELEASE: 1
APP_NAME: (( grab meta.name ))
DEVELOP_BRANCH: (( grab meta.github.branch ))
RELEASE_BRANCH: (( grab meta.github.branch ))
RELEASE_ROOT: gh
RELEASE_NOTES: (( grab meta.github.release_notes.file ))
NOTIFICATION_OUT: notifications
GITHUB_OWNER: (( grab meta.github.owner ))
GIT_EMAIL: (( grab meta.git.email ))
GIT_NAME: (( grab meta.git.name ))

- put: github-prerelease
params:
name: gh/name
tag: gh/tag
body: gh/notes.md
commitish: gh/commit
globs: [gh/artifacts/*]

on_failure:
put: notify
params:
username: (( grab meta.slack.username ))
icon_url: (( grab meta.slack.icon ))
text: '(( concat meta.slack.fail_url " " meta.pipeline ": ship prerelease job failed" ))'

# Shout-based notification - currently not available
# on_failure:
# put: notify
# params:
# topic: (( concat meta.shout.topic "-$BUILD_JOB_NAME" ))
# message: tests job '$BUILD_JOB_NAME' failed.
# ok: no
# link: (( grab meta.shout.links.build ))
72 changes: 72 additions & 0 deletions ci/pipeline/jobs/ship-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
jobs:
- name: ship-release
public: true
serial: true
plan:
- do:
- in_parallel:
- { get: version, resource: version, passed: [prepare], params: {bump: final} }
- { get: git, passed: [prepare] }
- { get: git-ci }
- { get: git-main }
- { get: git-latest-tag }
- { get: release-notes}
- task: build-kit
file: git-ci/ci/tasks/build.yml
params:
APP_NAME: (( grab meta.name ))
MODULE: (( grab meta.go.module ))
CMD_PATH: (( grab meta.go.cmd_path ))
STATIC_BINARY: (( grab meta.go.force_static_binary ))
- task: release
file: git-ci/ci/tasks/release.yml
params:
APP_NAME: (( grab meta.name ))
DEVELOP_BRANCH: (( grab meta.github.branch ))
RELEASE_BRANCH: (( grab meta.github.main-branch ))
RELEASE_ROOT: gh
RELEASE_NOTES: (( grab meta.github.release_notes.file ))
NOTIFICATION_OUT: notifications
GITHUB_OWNER: (( grab meta.github.owner ))
GIT_EMAIL: (( grab meta.git.email ))
GIT_NAME: (( grab meta.git.name ))
- put: git-main
params:
merge: false
tag: gh/tag
repository: git-main
- put: github
params:
name: gh/name
tag: gh/tag
body: gh/notes.md
globs: [gh/artifacts/*]
- put: version
params:
bump: patch
- put: notify
params:
username: (( grab meta.slack.username ))
icon_url: (( grab meta.slack.icon ))
text_file: notifications/message
on_failure:
put: notify
params:
username: (( grab meta.slack.username ))
icon_url: (( grab meta.slack.icon ))
text: '(( concat meta.slack.fail_url " " meta.pipeline ": prepare job failed" ))'
# Shout notification - not currently available
# on_success:
# put: notify
# params:
# topic: (( concat meta.shout.topic "-$BUILD_JOB_NAME" ))
# message: release job '$BUILD_JOB_NAME' succeeded.
# ok: yes
# link: (( grab meta.shout.links.build ))
# on_failure:
# put: notify
# params:
# topic: (( concat meta.shout.topic "-$BUILD_JOB_NAME" ))
# message: release job '$BUILD_JOB_NAME' failed.
# ok: no
# link: (( grab meta.shout.links.build ))
Loading

0 comments on commit b0a7655

Please sign in to comment.