Browse Source

initial

master
Sean Johnson 5 months ago
commit
d0853be3d8
  1. 1
      .gitignore
  2. 0
      README.md
  3. 154
      ci/repipe
  4. 68
      pipeline.yml
  5. 28
      resource/Dockerfile
  6. 45
      settings.yml

1
.gitignore

@ -0,0 +1 @@
.kitchen

0
README.md

154
ci/repipe

@ -0,0 +1,154 @@
#!/bin/bash
#
# repipe.sh
#
# Script for merging together pipeline configuration files
# (via Spruce!) and configuring Concourse.
#
# author: James Hunt <james@niftylogic.com>
# Dennis Bell <dennis.j.bell@gmail.com>
# created: 2016-03-04
need_command() {
local cmd=${1:?need_command() - no command name given}
if [[ ! -x "$(command -v $cmd)" ]]; then
echo >&2 "${cmd} is not installed."
if [[ "${cmd}" == "spruce" ]]; then
echo >&2 "Please download it from https://github.com/geofffranks/spruce/releases"
fi
exit 2
fi
}
NO_FLY=
SAVE_MANIFEST=
VALIDATE_PIPELINE=
NON_INTERACTIVE=
cleanup() {
rm -f save-manifest.yml
if [[ -n ${SAVE_MANIFEST} && -e .deploy.yml ]]; then
mv .deploy.yml save-manifest.yml
fi
rm -f .deploy.yml .settings.yml
}
usage() {
echo Command line arguments:
echo "no-fly Do not execute any fly commands"
echo "save-manifest Save manifest to file save-manifest"
echo "validate Validate pipeline instead of set pipeline"
echo "validate-strict Validate pipeline with strict mode"
echo "non-interactive Run set-pipeline in non-interactive mode"
echo "open Open pipeline dashboard to browser (if possible)"
}
open_pipeline() {
url=$(show_pipeline_url)
cleanup
if [[ -x /usr/bin/open ]]; then
exec /usr/bin/open "$url"
else
echo "Sorry, but I was not able to automagically open"
echo "your Concourse Pipeline in the browser."
echo
echo "Here's a link you can click on, though:"
echo
echo " $url"
echo
exit 0;
fi
}
show_pipeline_url() {
spruce merge --skip-eval pipeline.yml ${settings_file} > .deploy.yml
concourse_url=$(spruce json .deploy.yml | jq -r ".meta.url")
team=$(spruce json .deploy.yml | jq -r ".meta.team // \"main\"")
pipeline=$(spruce merge --skip-eval \
--cherry-pick meta.pipeline \
--cherry-pick meta.name \
.deploy.yml | spruce merge - | spruce json | jq -r ".meta.pipeline")
echo "$concourse_url/teams/$team/pipelines/$pipeline"
exit 0
}
for arg do
case "${arg}" in
no-fly|no_fly) NO_FLY="yes" ;;
save-manifest|save_manifest) SAVE_MANIFEST="yes" ;;
validate) VALIDATE_PIPELINE="normal" ;;
validate-strict|validate_strict) VALIDATE_PIPELINE="strict" ;;
non-interactive|non_interactive) NON_INTERACTIVE="--non-interactive" ;;
url) SHOW_PIPELINE_URL="yes" ;;
open) OPEN_PIPELINE="yes" ;;
help|-h|--help) usage; exit 0 ;;
*) echo Invalid argument
usage
exit 1
esac
done
echo >&2 "Working in $(pwd)"
need_command spruce
# Allow for target-specific settings
settings_files="$(find $(pwd) -name settings.yml ${CONCOURSE_TARGET:+"-name settings-${CONCOURSE_TARGET}.yml"})"
if [[ -z "$settings_files" ]]
then
echo >&2 "Could not find any local settings files!"
exit 1
fi
echo >&2 "Using settings found in ${settings_files}"
set -e
trap "cleanup" QUIT TERM EXIT INT
[[ -n ${SHOW_PIPELINE_URL} ]] && { show_pipeline_url; exit 0; }
[[ -n ${OPEN_PIPELINE} ]] && { open_pipeline; exit 0; }
spruce merge --skip-eval ${settings_files} > .settings.yml
settings_file="$(pwd)/.settings.yml"
FRAGMENTS=$(find $(pwd) -type f -name "pipeline.yml")
spruce merge --prune meta ${FRAGMENTS} ${settings_file} > .deploy.yml
PIPELINE=$(spruce json ${settings_file} | jq -r '.meta.pipeline // ""')
if [[ -z ${PIPELINE} ]]; then
echo >&2 "Missing pipeline name in ci/settings.yml!"
exit 1
fi
TARGET_FROM_SETTINGS=$(spruce json ${settings_file} | jq -r '.meta.target // ""')
if [[ -z ${CONCOURSE_TARGET} ]]; then
TARGET=${TARGET_FROM_SETTINGS}
elif [[ "$CONCOURSE_TARGET" != "$TARGET_FROM_SETTINGS" ]]
then
echo >&2 "Target in {$settings_file} differs from target in \$CONCOURSE_TARGET"
echo >&2 " \$CONCOURSE_TARGET: $CONCOURSE_TARGET"
echo >&2 " Target in file: $TARGET_FROM_SETTINGS"
exit 1
else
TARGET=${CONCOURSE_TARGET}
fi
if [[ -z ${TARGET} ]]; then
echo >&2 "Missing Concourse Target in ci/settings.yml!"
exit 1
fi
fly_cmd="${FLY_CMD:-fly}"
[[ -n ${NO_FLY} ]] && { echo no fly execution requested ; exit 0; }
case "${VALIDATE_PIPELINE}" in
normal) fly_opts="validate-pipeline" ;;
strict) fly_opts="validate-pipeline --strict" ;;
*) fly_opts="set-pipeline ${NON_INTERACTIVE} --pipeline ${PIPELINE}" ;;
esac
set +x
$fly_cmd --target ${TARGET} ${fly_opts} --config .deploy.yml
[[ -n ${VALIDATE_PIPELINE} ]] && exit 0
$fly_cmd --target ${TARGET} unpause-pipeline --pipeline ${PIPELINE}

68
pipeline.yml

@ -0,0 +1,68 @@
---
resources:
- name: alpine
type: registry-image
icon: pine-tree
source:
repository: (( grab meta.upstream.alpine.repo ))
tag: (( grab meta.upstream.alpine.tag ))
.: (( inject meta.upstream.alpine.auth ))
- name: commons
type: git
icon: git
source:
.: (( inject meta.upstream.commons ))
- name: golang
type: registry-image
icon: language-go
source:
repository: (( grab meta.upstream.golang.repo ))
tag: (( grab meta.upstream.golang.tag ))
.: (( inject meta.upstream.golang.auth ))
- name: spruce
type: registry-image
icon: wall
source:
repository: (( grab meta.image.spruce.repo ))
tag: (( grab meta.image.spruce.tag ))
.: (( inject meta.registry.auth ))
- name: source
type: git
icon: git
source:
.: (( inject meta.source ))
jobs:
- name: "spruce"
public: true
plan:
- get: commons
- get: source
trigger: true
- get: alpine
trigger: true
- get: golang
- task: "build-image"
file: (( grab meta.tasks.img-build-oci ))
privileged: true
input_mapping: {context: source}
params:
BUILD_ARG_ALPINE_REPO: (( grab meta.upstream.alpine.repo ))
BUILD_ARG_ALPINE_VERSION: (( grab meta.upstream.alpine.tag ))
BUILD_ARG_SPRUCE_VERSION: (( grab meta.upstream.spruce.version ))
BUILD_ARG_GOLANG_REPO: (( grab meta.upstream.golang.repo ))
BUILD_ARG_GOLANG_VERSION: (( grab meta.upstream.golang.tag ))
CONTEXT: (( grab meta.image.spruce.context ))
- task: "write-image-tags"
file: (( grab meta.tasks.img-write-tags ))
params:
TAGS: (( grab meta.upstream.spruce.version ))
- put: spruce
params:
image: image/image.tar
additional_tags: metadata/additional_tags

28
resource/Dockerfile

@ -0,0 +1,28 @@
ARG ALPINE_REPO=containers.dev.maio.me/library/alpine
ARG ALPINE_VERSION=v3.13
ARG GOLANG_REPO=containers.dev.maio.me/library/golang
ARG GOLANG_VERSION=1.15.6
ARG SPRUCE_VERSION=v0.5.2
#
# --- BUILD
#
FROM ${GOLANG_REPO}:${GOLANG_VERSION} as build
WORKDIR /source
RUN apk add git
RUN go get -d github.com/geofffranks/spruce && \
cd ${GOPATH:-/go}/src/github.com/geofffranks/spruce && \
git checkout ${SPRUCE_VERSION} && \
go install ./...
#
# --- APP
#
FROM ${ALPINE_REPO}:${ALPINE_VERSION}
COPY --from=build /go/bin/spruce /bin/spruce
ENTRYPOINT ["/bin/spruce"]

45
settings.yml

@ -0,0 +1,45 @@
---
meta:
name: spruce
target: glow-containers
url: https://concourse.dev.maio.me
team: containers
pipeline: spruce
registry:
repository: containers.dev.maio.me/library
auth:
username: ((glow_registry_ci.username))
password: ((glow_registry_ci.password))
image:
convoy:
context: resource/
repo: (( concat meta.registry.repository "/spruce" ))
tag: latest
source:
uri: https://glow.dev.maio.me/containers/spruce.git
branch: master
tasks:
img-build-oci: commons/tasks/img/build-oci.yml
img-write-tags: commons/tasks/img/write-tags.yml
upstream:
alpine:
repo: "containers.dev.maio.me/library/alpine"
tag: "latest"
auth:
.: (( inject meta.registry.auth ))
commons:
uri: "https://glow.dev.maio.me/containers/commons.git"
branch: "master"
golang:
repo: "containers.dev.maio.me/library/golang"
tag: "1.15.6"
auth:
.: (( inject meta.registry.auth ))
spruce:
version: v1.27.0
Loading…
Cancel
Save