diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..18bfe7e14 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,140 @@ +version: 2.1 + +orbs: + python: circleci/python@1 + go: circleci/go@1 + gcp-cli: circleci/gcp-cli@1 + +jobs: + build: + executor: + name: python/default + steps: + - attach_workspace: + at: ~/ + - checkout + - run: pip install mkdocs + - run: + name: Building package + command: make build + - gcp-cli/install + - gcp-cli/initialize + - run: + name: Building docker image + command: make cloudbuild-test + - persist_to_workspace: + root: ~/ + paths: + - project + + publish-image: + executor: + name: gcp-cli/google + steps: + - attach_workspace: + at: ~/ + - gcp-cli/initialize + - run: + name: Publishing docker image + command: IMAGE_SHA=${CIRCLE_SHA1} IMAGE_TAG=${CIRCLE_TAG:-latest} make cloudbuild + + release: + executor: + name: go/default + tag: '1.15' + steps: + - attach_workspace: + at: ~/ + - run: + name: Building release package + command: make release + environment: + DIST_DIR: /tmp/dist + - run: + name: Installing github-release tool + command: go get github.com/meterup/github-release + - run: + name: Creating github release + command: | + PRE_RELEASE=${CIRCLE_TAG/${CIRCLE_TAG%-rc[0-9]*}/} + github-release delete -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -t ${CIRCLE_TAG} 2>/dev/null ||: + ./scripts/release-notes.sh ${CIRCLE_TAG} | github-release release ${PRE_RELEASE:+-p} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -t ${CIRCLE_TAG} -d - + 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 + + deploy: + description: Patches target cluster configuration + executor: + name: go/default + tag: '1.15' + parameters: + cluster: + type: string + committer_name: + type: string + default: TriggerMesh Bot + committer_email: + type: string + default: bot@triggermesh.com + steps: + - attach_workspace: + at: ~/ + - add_ssh_keys + - run: ssh-keyscan github.com >> ~/.ssh/known_hosts + - run: + name: Configuring git + command: | + git config --global user.name '<< parameters.committer_name >>' + git config --global user.email '<< parameters.committer_email >>' + - run: + name: Cloning config repository + command: git clone --single-branch git@github.com:triggermesh/config.git tmconfig + - run: + name: Updating overlays/<< parameters.cluster >>/sources manifests + working_directory: tmconfig/ + command: | + sed -i overlays/<< parameters.cluster >>/docs/deployment.yaml -e "s|gcr.io/triggermesh/docs:.*|gcr.io/triggermesh/docs:"${CIRCLE_TAG:-${CIRCLE_SHA1}}"|g" + git --no-pager diff + - run: + name: Committing overlays/<< parameters.cluster >>/docs updates + working_directory: tmconfig/ + command: | + git add overlays + git commit -m "Update overlays/<< parameters.cluster >>/docs deployment to '${CIRCLE_TAG:-${CIRCLE_SHA1}}'" + git push origin master + +workflows: + build-test-and-publish: + jobs: + - build: + context: production + filters: + tags: + only: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ + - publish-image: + context: production + requires: + - build + filters: + tags: + only: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ + branches: + only: master + - deploy: + name: update-production-config + cluster: prod + requires: + - publish-image + filters: + tags: + only: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ + branches: + ignore: /.*/ + - release: + context: production + requires: + - publish-image + filters: + tags: + only: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ + branches: + ignore: /.*/ diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..d02ca0698 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +# Top level files and directories +/.circleci/ +/.dockerignore +/.gcloudignore +/.git/ +/_output/ +/cloudbuild.yaml +/Dockerfile diff --git a/.gcloudignore b/.gcloudignore new file mode 100644 index 000000000..783f56653 --- /dev/null +++ b/.gcloudignore @@ -0,0 +1,2 @@ +#!include:.dockerignore +!Dockerfile diff --git a/.gitignore b/.gitignore index d7e435d32..574cbc287 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,18 @@ -/site -/.venv -**/.DS_Store +# Local configurations and secrets +/.env/ +/.local/ + +# Continuous integration + +# Editors and IDEs +*.swo +*.swp +*~ +/*.sublime-project +/*.sublime-workspace +/.DS_Store +/.idea/ +/.vscode/ + +# Build artifacts +**/_output diff --git a/Dockerfile b/Dockerfile index 9d5df3b97..80979a195 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,11 @@ -FROM nginx +FROM python:3 AS builder + +RUN pip install mkdocs + +COPY . /docs -ADD site/ /usr/share/nginx/html/ +RUN mkdocs build --clean --config-file /docs/mkdocs.yml + +FROM nginx +COPY --from=builder /docs/site/ /usr/share/nginx/html/ diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..45ef59f6d --- /dev/null +++ b/Makefile @@ -0,0 +1,50 @@ +PACKAGE = docs +PACKAGE_DESC = Triggermesh Docs +VERSION ?= $(shell git describe --tags --always) + +BASE_DIR ?= $(CURDIR) + +OUTPUT_DIR ?= $(BASE_DIR)/_output +DIST_DIR ?= $(OUTPUT_DIR) + +SITE_OUTPUT_DIR ?= $(OUTPUT_DIR)/site + +DOCKER ?= docker + +IMAGE_REPO ?= gcr.io/triggermesh +IMAGE_TAG ?= latest +IMAGE_SHA ?= $(shell git rev-parse HEAD) + +HAS_MKDOCS := $(shell command -v mkdocs;) + +.PHONY: help build image cloudbuild-test cloudbuild clean + +all: build + +install-mkdocs: +ifndef HAS_MKDOCS + pip3 install mkdocs +endif + +help: ## Display this help + @awk 'BEGIN {FS = ":.*?## "; printf "\n$(PACKAGE_DESC)\n\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z0-9._-]+:.*?## / {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +build: install-mkdocs ## Build the docs + mkdocs build --clean --config-file mkdocs.yml --site-dir $(SITE_OUTPUT_DIR) + +release: ## Build distribution tarball + @mkdir -p $(DIST_DIR) + tar -jcf $(DIST_DIR)/$(PACKAGE)-$(VERSION).tar.bz2 -C $$(dirname $(SITE_OUTPUT_DIR)) $$(basename $(SITE_OUTPUT_DIR)) + +image: ## Builds the container image + $(DOCKER) build -t $(IMAGE_REPO)/$(PACKAGE) -f Dockerfile . + +cloudbuild-test: ## Test container image build with Google Cloud Build + gcloud builds submit $(BASE_DIR) --config cloudbuild.yaml --substitutions COMMIT_SHA=${IMAGE_SHA},_KANIKO_IMAGE_TAG=_ + +cloudbuild: ## Build and publish image to GCR + gcloud builds submit $(BASE_DIR) --config cloudbuild.yaml --substitutions COMMIT_SHA=${IMAGE_SHA},_KANIKO_IMAGE_TAG=${IMAGE_TAG} + +clean: ## Clean build artifacts + @$(RM) -v $(DIST_DIR)/$(PACKAGE)-$(VERSION).tar.bz2 + @$(RM) -rv $(SITE_OUTPUT_DIR) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index fa96f4eec..e6deb634c 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -1,10 +1,28 @@ steps: -- name: 'gcr.io/triggermesh/mkdocs:latest' - args: ['mkdocs', 'build'] -- name: 'debian' - args: ['ls', '/workspace/site'] -- name: 'gcr.io/cloud-builders/docker' - args: ['build', '-t', 'gcr.io/$PROJECT_ID/www:$REVISION_ID', '-t', 'gcr.io/$PROJECT_ID/www:latest', '.'] -- name: 'gcr.io/cloud-builders/docker' - args: ['push', 'gcr.io/$PROJECT_ID/www:$REVISION_ID'] -images: ['gcr.io/$PROJECT_ID/www'] + +- name: gcr.io/kaniko-project/executor:latest + args: + - --dockerfile=Dockerfile + - --destination=gcr.io/$PROJECT_ID/docs:${COMMIT_SHA} + - --destination=gcr.io/$PROJECT_ID/docs:${_KANIKO_IMAGE_TAG} + - --cache-repo=gcr.io/$PROJECT_ID/docs/cache + - --cache=${_KANIKO_USE_BUILD_CACHE} + - --no-push=${_KANIKO_NO_PUSH} + - --snapshotMode=redo + - --use-new-run + - ${_KANIKO_EXTRA_ARGS} + waitFor: ['-'] + +timeout: 120s + +substitutions: + _KANIKO_IMAGE_TAG: latest + _KANIKO_NO_PUSH: 'false' + _KANIKO_USE_BUILD_CACHE: 'true' + _KANIKO_EXTRA_ARGS: + +options: + substitution_option: ALLOW_LOOSE + +tags: + - docs diff --git a/scripts/release-notes.sh b/scripts/release-notes.sh new file mode 100755 index 000000000..995402651 --- /dev/null +++ b/scripts/release-notes.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env sh + +RELEASE=${1:-${GIT_TAG}} +RELEASE=${RELEASE:-${CIRCLE_TAG}} + +if [ -z "${RELEASE}" ]; then + echo "Usage:" + echo "./scripts/release-notes.sh v0.1.0" + exit 1 +fi + +if ! git rev-list ${RELEASE} >/dev/null 2>&1; then + echo "${RELEASE} does not exist" + exit +fi + +PREV_RELEASE=${PREV_RELEASE:-$(git describe --tags --abbrev=0 ${RELEASE}^ 2>/dev/null)} +PREV_RELEASE=${PREV_RELEASE:-$(git rev-list --max-parents=0 ${RELEASE}^ 2>/dev/null)} +NOTABLE_CHANGES=$(git cat-file -p ${RELEASE} | sed '/-----BEGIN PGP SIGNATURE-----/,//d' | tail -n +6) +CHANGELOG=$(git log --no-merges --pretty=format:'- [%h] %s (%aN)' ${PREV_RELEASE}..${RELEASE}) +if [ $? -ne 0 ]; then + echo "Error creating changelog" + exit 1 +fi + +cat <