Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 0d74554

Browse files
author
Sameer Naik
authored
Merge pull request #48 from triggermesh/add-ci
Implement CI pipeline
2 parents 71950b3 + 5dd7888 commit 0d74554

File tree

8 files changed

+292
-14
lines changed

8 files changed

+292
-14
lines changed

.circleci/config.yml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
version: 2.1
2+
3+
orbs:
4+
python: circleci/python@1
5+
go: circleci/go@1
6+
gcp-cli: circleci/gcp-cli@1
7+
8+
jobs:
9+
build:
10+
executor:
11+
name: python/default
12+
steps:
13+
- attach_workspace:
14+
at: ~/
15+
- checkout
16+
- run: pip install mkdocs
17+
- run:
18+
name: Building package
19+
command: make build
20+
- gcp-cli/install
21+
- gcp-cli/initialize
22+
- run:
23+
name: Building docker image
24+
command: make cloudbuild-test
25+
- persist_to_workspace:
26+
root: ~/
27+
paths:
28+
- project
29+
30+
publish-image:
31+
executor:
32+
name: gcp-cli/google
33+
steps:
34+
- attach_workspace:
35+
at: ~/
36+
- gcp-cli/initialize
37+
- run:
38+
name: Publishing docker image
39+
command: IMAGE_SHA=${CIRCLE_SHA1} IMAGE_TAG=${CIRCLE_TAG:-latest} make cloudbuild
40+
41+
release:
42+
executor:
43+
name: go/default
44+
tag: '1.15'
45+
steps:
46+
- attach_workspace:
47+
at: ~/
48+
- run:
49+
name: Building release package
50+
command: make release
51+
environment:
52+
DIST_DIR: /tmp/dist
53+
- run:
54+
name: Installing github-release tool
55+
command: go get github.com/meterup/github-release
56+
- run:
57+
name: Creating github release
58+
command: |
59+
PRE_RELEASE=${CIRCLE_TAG/${CIRCLE_TAG%-rc[0-9]*}/}
60+
github-release delete -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -t ${CIRCLE_TAG} 2>/dev/null ||:
61+
./scripts/release-notes.sh ${CIRCLE_TAG} | github-release release ${PRE_RELEASE:+-p} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -t ${CIRCLE_TAG} -d -
62+
for f in $(find /tmp/dist -type f); do github-release upload -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -t ${CIRCLE_TAG} -n $(basename ${f}) -f ${f} ; done
63+
64+
deploy:
65+
description: Patches target cluster configuration
66+
executor:
67+
name: go/default
68+
tag: '1.15'
69+
parameters:
70+
cluster:
71+
type: string
72+
committer_name:
73+
type: string
74+
default: TriggerMesh Bot
75+
committer_email:
76+
type: string
77+
78+
steps:
79+
- attach_workspace:
80+
at: ~/
81+
- add_ssh_keys
82+
- run: ssh-keyscan github.com >> ~/.ssh/known_hosts
83+
- run:
84+
name: Configuring git
85+
command: |
86+
git config --global user.name '<< parameters.committer_name >>'
87+
git config --global user.email '<< parameters.committer_email >>'
88+
- run:
89+
name: Cloning config repository
90+
command: git clone --single-branch [email protected]:triggermesh/config.git tmconfig
91+
- run:
92+
name: Updating overlays/<< parameters.cluster >>/sources manifests
93+
working_directory: tmconfig/
94+
command: |
95+
sed -i overlays/<< parameters.cluster >>/docs/deployment.yaml -e "s|gcr.io/triggermesh/docs:.*|gcr.io/triggermesh/docs:"${CIRCLE_TAG:-${CIRCLE_SHA1}}"|g"
96+
git --no-pager diff
97+
- run:
98+
name: Committing overlays/<< parameters.cluster >>/docs updates
99+
working_directory: tmconfig/
100+
command: |
101+
git add overlays
102+
git commit -m "Update overlays/<< parameters.cluster >>/docs deployment to '${CIRCLE_TAG:-${CIRCLE_SHA1}}'"
103+
git push origin master
104+
105+
workflows:
106+
build-test-and-publish:
107+
jobs:
108+
- build:
109+
context: production
110+
filters:
111+
tags:
112+
only: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
113+
- publish-image:
114+
context: production
115+
requires:
116+
- build
117+
filters:
118+
tags:
119+
only: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
120+
branches:
121+
only: master
122+
- deploy:
123+
name: update-production-config
124+
cluster: prod
125+
requires:
126+
- publish-image
127+
filters:
128+
tags:
129+
only: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
130+
branches:
131+
ignore: /.*/
132+
- release:
133+
context: production
134+
requires:
135+
- publish-image
136+
filters:
137+
tags:
138+
only: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
139+
branches:
140+
ignore: /.*/

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Top level files and directories
2+
/.circleci/
3+
/.dockerignore
4+
/.gcloudignore
5+
/.git/
6+
/_output/
7+
/cloudbuild.yaml
8+
/Dockerfile

.gcloudignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!include:.dockerignore
2+
!Dockerfile

.gitignore

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1-
/site
2-
/.venv
3-
**/.DS_Store
1+
# Local configurations and secrets
2+
/.env/
3+
/.local/
4+
5+
# Continuous integration
6+
7+
# Editors and IDEs
8+
*.swo
9+
*.swp
10+
*~
11+
/*.sublime-project
12+
/*.sublime-workspace
13+
/.DS_Store
14+
/.idea/
15+
/.vscode/
16+
17+
# Build artifacts
18+
**/_output

Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
FROM nginx
1+
FROM python:3 AS builder
2+
3+
RUN pip install mkdocs
4+
5+
COPY . /docs
26

3-
ADD site/ /usr/share/nginx/html/
7+
RUN mkdocs build --clean --config-file /docs/mkdocs.yml
8+
9+
FROM nginx
410

11+
COPY --from=builder /docs/site/ /usr/share/nginx/html/

Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
PACKAGE = docs
2+
PACKAGE_DESC = Triggermesh Docs
3+
VERSION ?= $(shell git describe --tags --always)
4+
5+
BASE_DIR ?= $(CURDIR)
6+
7+
OUTPUT_DIR ?= $(BASE_DIR)/_output
8+
DIST_DIR ?= $(OUTPUT_DIR)
9+
10+
SITE_OUTPUT_DIR ?= $(OUTPUT_DIR)/site
11+
12+
DOCKER ?= docker
13+
14+
IMAGE_REPO ?= gcr.io/triggermesh
15+
IMAGE_TAG ?= latest
16+
IMAGE_SHA ?= $(shell git rev-parse HEAD)
17+
18+
HAS_MKDOCS := $(shell command -v mkdocs;)
19+
20+
.PHONY: help build image cloudbuild-test cloudbuild clean
21+
22+
all: build
23+
24+
install-mkdocs:
25+
ifndef HAS_MKDOCS
26+
pip3 install mkdocs
27+
endif
28+
29+
help: ## Display this help
30+
@awk 'BEGIN {FS = ":.*?## "; printf "\n$(PACKAGE_DESC)\n\nUsage:\n make \033[36m<source>\033[0m\n"} /^[a-zA-Z0-9._-]+:.*?## / {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
31+
32+
build: install-mkdocs ## Build the docs
33+
mkdocs build --clean --config-file mkdocs.yml --site-dir $(SITE_OUTPUT_DIR)
34+
35+
release: ## Build distribution tarball
36+
@mkdir -p $(DIST_DIR)
37+
tar -jcf $(DIST_DIR)/$(PACKAGE)-$(VERSION).tar.bz2 -C $$(dirname $(SITE_OUTPUT_DIR)) $$(basename $(SITE_OUTPUT_DIR))
38+
39+
image: ## Builds the container image
40+
$(DOCKER) build -t $(IMAGE_REPO)/$(PACKAGE) -f Dockerfile .
41+
42+
cloudbuild-test: ## Test container image build with Google Cloud Build
43+
gcloud builds submit $(BASE_DIR) --config cloudbuild.yaml --substitutions COMMIT_SHA=${IMAGE_SHA},_KANIKO_IMAGE_TAG=_
44+
45+
cloudbuild: ## Build and publish image to GCR
46+
gcloud builds submit $(BASE_DIR) --config cloudbuild.yaml --substitutions COMMIT_SHA=${IMAGE_SHA},_KANIKO_IMAGE_TAG=${IMAGE_TAG}
47+
48+
clean: ## Clean build artifacts
49+
@$(RM) -v $(DIST_DIR)/$(PACKAGE)-$(VERSION).tar.bz2
50+
@$(RM) -rv $(SITE_OUTPUT_DIR)

cloudbuild.yaml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
steps:
2-
- name: 'gcr.io/triggermesh/mkdocs:latest'
3-
args: ['mkdocs', 'build']
4-
- name: 'debian'
5-
args: ['ls', '/workspace/site']
6-
- name: 'gcr.io/cloud-builders/docker'
7-
args: ['build', '-t', 'gcr.io/$PROJECT_ID/www:$REVISION_ID', '-t', 'gcr.io/$PROJECT_ID/www:latest', '.']
8-
- name: 'gcr.io/cloud-builders/docker'
9-
args: ['push', 'gcr.io/$PROJECT_ID/www:$REVISION_ID']
10-
images: ['gcr.io/$PROJECT_ID/www']
2+
3+
- name: gcr.io/kaniko-project/executor:latest
4+
args:
5+
- --dockerfile=Dockerfile
6+
- --destination=gcr.io/$PROJECT_ID/docs:${COMMIT_SHA}
7+
- --destination=gcr.io/$PROJECT_ID/docs:${_KANIKO_IMAGE_TAG}
8+
- --cache-repo=gcr.io/$PROJECT_ID/docs/cache
9+
- --cache=${_KANIKO_USE_BUILD_CACHE}
10+
- --no-push=${_KANIKO_NO_PUSH}
11+
- --snapshotMode=redo
12+
- --use-new-run
13+
- ${_KANIKO_EXTRA_ARGS}
14+
waitFor: ['-']
15+
16+
timeout: 120s
17+
18+
substitutions:
19+
_KANIKO_IMAGE_TAG: latest
20+
_KANIKO_NO_PUSH: 'false'
21+
_KANIKO_USE_BUILD_CACHE: 'true'
22+
_KANIKO_EXTRA_ARGS:
23+
24+
options:
25+
substitution_option: ALLOW_LOOSE
26+
27+
tags:
28+
- docs

scripts/release-notes.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env sh
2+
3+
RELEASE=${1:-${GIT_TAG}}
4+
RELEASE=${RELEASE:-${CIRCLE_TAG}}
5+
6+
if [ -z "${RELEASE}" ]; then
7+
echo "Usage:"
8+
echo "./scripts/release-notes.sh v0.1.0"
9+
exit 1
10+
fi
11+
12+
if ! git rev-list ${RELEASE} >/dev/null 2>&1; then
13+
echo "${RELEASE} does not exist"
14+
exit
15+
fi
16+
17+
PREV_RELEASE=${PREV_RELEASE:-$(git describe --tags --abbrev=0 ${RELEASE}^ 2>/dev/null)}
18+
PREV_RELEASE=${PREV_RELEASE:-$(git rev-list --max-parents=0 ${RELEASE}^ 2>/dev/null)}
19+
NOTABLE_CHANGES=$(git cat-file -p ${RELEASE} | sed '/-----BEGIN PGP SIGNATURE-----/,//d' | tail -n +6)
20+
CHANGELOG=$(git log --no-merges --pretty=format:'- [%h] %s (%aN)' ${PREV_RELEASE}..${RELEASE})
21+
if [ $? -ne 0 ]; then
22+
echo "Error creating changelog"
23+
exit 1
24+
fi
25+
26+
cat <<EOF
27+
${NOTABLE_CHANGES}
28+
29+
## Installation
30+
31+
Download Triggermesh Docs ${RELEASE}
32+
33+
- [container](https://gcr.io/triggermesh/docs:${RELEASE})
34+
35+
## Changelog
36+
37+
${CHANGELOG}
38+
EOF

0 commit comments

Comments
 (0)