Skip to content

Commit

Permalink
release pipeline (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
kzadorozhny authored Oct 19, 2022
1 parent 5d2eda5 commit c638e7a
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.1
5.3.1
4 changes: 2 additions & 2 deletions .fasterci/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ workflows:
run: bazel run //:buildifier-check

- <<: *build_workflow
name: Faster CI / build (5.3.0)
name: Faster CI / build (5.3.1)
env:
USE_BAZEL_VERSION: "5.3.0"
USE_BAZEL_VERSION: "5.3.1"
11 changes: 6 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ on:

jobs:
build:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
bazel-version:
- 5.1.1
- 5.3.0
- 5.3.1
env:
USE_BAZEL_VERSION: ${{ matrix.bazel-version }}
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3
- name: Mount Bazel cache
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cache/bazel
key: bazel-${{ matrix.bazel-version }}-${{ github.sha }}
Expand All @@ -32,7 +33,7 @@ jobs:
run: |
TOOLS_DIR="${HOME}/.cache/tools"
mkdir -p "${TOOLS_DIR}/bin/"
curl -Ls -o "${TOOLS_DIR}/bin/bazel" "https://github.com/bazelbuild/bazelisk/releases/download/v1.3.0/bazelisk-linux-amd64"
curl -Ls -o "${TOOLS_DIR}/bin/bazel" "https://github.com/bazelbuild/bazelisk/releases/download/v1.14.0/bazelisk-linux-amd64"
chmod +x "${TOOLS_DIR}/bin/bazel"
curl -Ls -o "${TOOLS_DIR}/bin/buildifier" "https://github.com/bazelbuild/buildtools/releases/download/0.29.0/buildifier"
chmod +x "${TOOLS_DIR}/bin/buildifier"
Expand Down
87 changes: 87 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Cut a release whenever a new tag is pushed to the repo.
# You should use an annotated tag, like `git tag -a v1.2.3`
# and put the release notes into the commit message for the tag.
name: Release

on:
push:
tags:
- "v*.*.*"

jobs:
build:
runs-on: ubuntu-20.04
env:
USE_BAZEL_VERSION: 5.3.1
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Mount Bazel cache
uses: actions/cache@v3
with:
path: ~/.cache/bazel
key: bazel-${{ env.USE_BAZEL_VERSION }}-${{ github.sha }}
restore-keys: |
bazel-${{ env.USE_BAZEL_VERSION }}-
bazel-
- name: Setup build tools
run: |
TOOLS_DIR="${HOME}/.cache/tools"
mkdir -p "${TOOLS_DIR}/bin/"
curl -Ls -o "${TOOLS_DIR}/bin/bazel" "https://github.com/bazelbuild/bazelisk/releases/download/v1.14.0/bazelisk-linux-amd64"
chmod +x "${TOOLS_DIR}/bin/bazel"
curl -Ls -o "${TOOLS_DIR}/bin/buildifier" "https://github.com/bazelbuild/buildtools/releases/download/0.29.0/buildifier"
chmod +x "${TOOLS_DIR}/bin/buildifier"
curl -Ls -o "${TOOLS_DIR}/bin/kind" "https://github.com/kubernetes-sigs/kind/releases/download/v0.11.1/kind-linux-amd64"
chmod +x "${TOOLS_DIR}/bin/kind"
echo "${TOOLS_DIR}/bin" >> $GITHUB_PATH
- name: Setup kind cluster
run: |
./create_kind_cluster.sh
- name: Build
run: |
bazel build //...
- name: Check
# run downloaded version of buildifier to reduce uncached build times
# see: bazel run //:buildifier-check
run: |
find . -type f \(\
-name '*.bzl' \
-o -name '*.sky' \
-o -name BUILD \
-o -name BUILD.bazel \
-o -name WORKSPACE \
-o -name WORKSPACE.bazel \
\) | xargs buildifier \
-mode=check \
-lint=warn \
--warnings=-module-docstring,-function-docstring,-function-docstring-header,-function-docstring-args,-function-docstring-return,-print \
|| {
buildifier_exit_code=$?
echo "Error: failed buildifier checks. Please run \"bazel run //:buildifier-fix\" and commit the changes."
exit $buildifier_exit_code
}
- name: Test
run: |
bazel test //...
- name: Build examples
run: |
cd examples
bazel build //...
- name: Test examples
run: |
cd examples
bazel test //...
- name: E2E
run: |
cd examples
./e2e-test.sh
- name: Prepare workspace snippet
run: .github/workflows/workspace_snippet.sh ${{ env.GITHUB_REF_NAME }} > release_notes.txt
- name: Release
uses: softprops/action-gh-release@v1
with:
prerelease: true
# Use GH feature to populate the changelog automatically
generate_release_notes: true
body_path: release_notes.txt
26 changes: 26 additions & 0 deletions .github/workflows/workspace_snippet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

TAG=${GITHUB_REF_NAME}
PREFIX="rules_gitops-${TAG:1}"
SHA=$(git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip | shasum -a 256 | awk '{print $1}')

cat << EOF
WORKSPACE snippet:
\`\`\`starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "com_adobe_rules_gitops",
sha256 = "${SHA}",
strip_prefix = "${PREFIX}",
url = ["https://github.com/adobe/rules_gitops/archive/refs/tags/${TAG}.tar.gz"],
)
EOF

awk '/---SNIP---/{f=1;next}/---END_SNIP---/{f=0}f' examples/WORKSPACE
echo "\`\`\`"
75 changes: 13 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,62 +32,13 @@ Bazel GitOps Rules is an alternative to [rules_k8s](https://github.com/bazelbuil
* [Integration Testing Support](#integration-testing-support)


## Setup
<a name="installation"></a>
## Installation

Add the following to your `WORKSPACE` file to add the necessary external dependencies:
From the release you wish to use:
<https://github.com/adobe/rules_gitops/releases>
copy the WORKSPACE snippet into your `WORKSPACE` file.

<!--
# generate the WORKSPACE snippet:
rev=$(git rev-parse HEAD) && sha265=$(curl -Ls https://github.com/adobe/rules_gitops/archive/${rev}.zip | shasum -a 256 - | cut -d ' ' -f1) && cat <<EOF
# copy/paste following snippet into README.md
rules_gitops_version = "${rev}"
http_archive(
name = "com_adobe_rules_gitops",
sha256 = "${sha265}",
strip_prefix = "rules_gitops-%s" % rules_gitops_version,
urls = ["https://github.com/adobe/rules_gitops/archive/%s.zip" % rules_gitops_version],
)
EOF
-->

```python
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_bazel_rules_go",
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.19.2")

rules_gitops_version = "6db602bea69822a1fa17d19865a450f504e5a4bc"

http_archive(
name = "com_adobe_rules_gitops",
sha256 = "08b909ff9440e1bb03befa5cbd01e9880fff67ce2b83dc20f53e918dff9e4f6b",
strip_prefix = "rules_gitops-%s" % rules_gitops_version,
urls = ["https://github.com/adobe/rules_gitops/archive/%s.zip" % rules_gitops_version],
)

load("@com_adobe_rules_gitops//gitops:deps.bzl", "rules_gitops_dependencies")

rules_gitops_dependencies()

load("@com_adobe_rules_gitops//gitops:repositories.bzl", "rules_gitops_repositories")

rules_gitops_repositories()

```

<a name="k8s_deploy"></a>
## k8s_deploy
Expand Down Expand Up @@ -147,7 +98,7 @@ The base manifests will be modified by most of the other `k8s_deploy` attributes
To demonstrate, let's go over hypothetical multi cluster deployment.

Here is the fragment of the `k8s_deploy` rule that is responsible for generating manifest variants per CLOUD, CLUSTER, and NAMESPACE :
```python
```starlark
k8s_deploy(
...
manifests = glob([ # (1)
Expand Down Expand Up @@ -208,7 +159,7 @@ That looks like a lot. But lets try to decode what is happening here:

Configmaps are a special case of manifests. They can be rendered from a collection of files of any kind (.yaml, .properties, .xml, .sh, whatever). Let's use hypothetical Grafana deployment as an example:

```python
```starlark
[
k8s_deploy(
name = NAME,
Expand Down Expand Up @@ -280,7 +231,7 @@ spec:
Third-party Docker images can be referenced directly in K8s manifests, but for most apps, we need to run our own images. The images are built in the Bazel build pipeline using [rules_docker](https://github.com/bazelbuild/rules_docker). For example, the `java_image` rule creates an image of a Java application from Java source code, dependencies, and configuration.

Here's a (very contrived) example of how this ties in with `k8s_deploy`. Here's the `BUILD` file located in the package `//examples`:
```python
```starlark
java_image(
name = "helloworld_image",
srcs = glob(["*.java"]),
Expand Down Expand Up @@ -371,7 +322,7 @@ Many instances of `k8s_deploy` include an `objects` attribute that references ot
`k8s_deploy`. When chained this way, running the `.apply` will also apply any dependencies as well.

For example, to add dependency to the example [helloworld deployment](./examples/helloworld/BUILD):
```python
```starlark
k8s_deploy(
name = "mynamespace",
objects = [
Expand Down Expand Up @@ -457,7 +408,7 @@ The `create_gitops_prs` tool will query all `gitops` targets which have set the
The all discovered `gitops` targets are grouped by the value of ***deploy_branch*** attribute. The one deployment branch will accumulate the output of all corresponding `gitops` targets.

For example, we define two deployments: grafana and prometheus. Both deployments share the same namespace. The deployments a grouped by namespace.
```python
```starlark
[
k8s_deploy(
name = NAME,
Expand Down Expand Up @@ -524,7 +475,7 @@ The meaning of the parameters is the same as with [trunk based workflow](#trunk_
The `--release_branch` parameter takes the value of `release/team`. The additional parameter `--deployment_branch_suffix` will add the release branch suffix to the target deployment branch name.

If we modify previous example:
```python
```starlark
[
k8s_deploy(
name = NAME,
Expand Down Expand Up @@ -564,7 +515,7 @@ The result of the setup above the `create_gitops_prs` tool will open up to 2 pot
**Note:** the Integration testing support has known limitations and should be considered **experimental**. The public API is subject to change.

Integration tests are defined in `BUILD` files like this:
```python
```starlark
k8s_test_setup(
name = "service_it.setup",
kubeconfig = "@k8s_test//:kubeconfig",
Expand Down Expand Up @@ -597,7 +548,7 @@ The test code launches the script to perform the test setup. The test code shoul

The `@k8s_test//:kubeconfig` target referenced from `k8s_test_setup` rule serves the purpose of making Kubernetes configuration available in the test sandbox. The `kubeconfig` repository rule in the `WORKSPACE` file will need, at minimum, provide the cluster name.

```python
```starlark
load("@com_adobe_rules_gitops//gitops:defs.bzl", "kubeconfig")
kubeconfig(
Expand Down
2 changes: 1 addition & 1 deletion examples/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.1
5.3.1
18 changes: 12 additions & 6 deletions examples/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@

workspace(name = "examples")

local_repository(
name = "com_adobe_rules_gitops",
path = "..",
)

# generated by workspace_snippet.sh
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

#---SNIP--- Below here is re-used in the workspace snippet published on releases

http_archive(
name = "io_bazel_rules_go",
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
Expand All @@ -27,11 +35,6 @@ go_rules_dependencies()

go_register_toolchains(version = "1.19.2")

local_repository(
name = "com_adobe_rules_gitops",
path = "..",
)

load("@com_adobe_rules_gitops//gitops:deps.bzl", "rules_gitops_dependencies")

rules_gitops_dependencies()
Expand All @@ -40,9 +43,12 @@ load("@com_adobe_rules_gitops//gitops:repositories.bzl", "rules_gitops_repositor

rules_gitops_repositories()

#---END_SNIP--- marks the end of the the workspace snippet published on releases

#
# Repository dependencies
# examples dependencies
#

load(
"@io_bazel_rules_docker//go:image.bzl",
go_image_repositories = "repositories",
Expand Down

0 comments on commit c638e7a

Please sign in to comment.