Skip to content

Commit

Permalink
fix: Provisioner deployment (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvgijssel authored Dec 19, 2023
1 parent a8c377c commit 951b11e
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/provisioner-new-olives-switch-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"provisioner": patch
---

fix: Update timeout of bunq2ynab to prevent 1password rate limit
5 changes: 5 additions & 0 deletions .changeset/provisioner-new-olives-switch-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"provisioner": patch
---

chore(deps): Update teleport to 14.2.3
5 changes: 5 additions & 0 deletions .changeset/provisioner-new-olives-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"provisioner": patch
---

fix: Ensure nix-build is available inside GitHub actions
5 changes: 5 additions & 0 deletions .changeset/rules_release-orange-masks-compare-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rules_release": patch
---

fix: Fix passing multiple arguments to generate-hashes and get-impacted-targets
5 changes: 5 additions & 0 deletions .changeset/rules_release-orange-masks-compare-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rules_release": minor
---

feat: Enable passing `previous_revision_cmd` and `final_revision_cmd` to `bazel_diff_release`
5 changes: 5 additions & 0 deletions .changeset/rules_release-orange-masks-compare-4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rules_release": minor
---

feat: Add `release_changed_files` to enable releasing based on changed file paths inside of git
5 changes: 5 additions & 0 deletions .changeset/rules_release-orange-masks-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rules_release": minor
---

feat: Support changing git directories better by stashing and restoring the working directory
5 changes: 5 additions & 0 deletions .changeset/rules_task-wet-numbers-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rules_task": patch
---

build: Use `release_changed_files` instead of `bazel_diff_release` to detect changes for a release.
5 changes: 5 additions & 0 deletions .github/actions/setup-bazel/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ runs:
OP_SERVICE_ACCOUNT_TOKEN: ${{ inputs.OP_SERVICE_ACCOUNT_TOKEN }}
BUILDBUDDY_API_KEY: op://vgijssel-prod/buildbuddy-api-key/password

- name: Install nix package manager
uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=channel:nixos-23.11

- name: Create local.bazelrc file
shell: bash
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Schedule
on:
schedule:
- cron: "*/10 * * * *"
- cron: "0 * * * *"

jobs:
provisioner-validate:
runs-on: ubuntu-latest
timeout-minutes: 9
timeout-minutes: 10
concurrency: validate-provisioner
steps:
- name: Checkout repository
Expand Down
4 changes: 2 additions & 2 deletions provisioner/deploys/bunq2ynab/files/docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ services:
environment:
- OP_SERVICE_ACCOUNT_TOKEN={{ op_service_account_token }}
- SETUP_ENV={{ setup_env }}
# sleeping for 15 minutes to prevent rate limiting
- TIMEOUT=900
# sleeping for 60 minutes to prevent rate limiting in 1Password, Bunq and YNAB
- TIMEOUT=3600
deploy:
resources:
limits:
Expand Down
2 changes: 1 addition & 1 deletion provisioner/deploys/teleport/tasks/install_teleport.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from provisioner.utils import wait_for_reconnect


TELEPORT_VERSION = "v14.0.1"
TELEPORT_VERSION = "v14.2.3"


@deploy("Install Teleport")
Expand Down
7 changes: 4 additions & 3 deletions rules/rules_release/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_task//task:defs.bzl", "cmd")
load("//tools:defs.bzl", "publish_github_release", release = "bazel_diff_release")
load("//tools:defs.bzl", "publish_github_release", release = "release_changed_files")
load("@aspect_bazel_lib//lib:tar.bzl", "mtree_spec", "tar")
load("@npm//:defs.bzl", "npm_link_all_packages")

Expand Down Expand Up @@ -137,13 +137,14 @@ publish_github_release(

release(
name = "release",
changed_file_paths = [
"rules/rules_release",
],
changelog_file = "CHANGELOG.md",
generate_hashes_extra_args = ["--fineGrainedHashExternalRepos=rules_release"],
publish_cmds = [
":publish_github_release",
],
release_name = "rules_release",
target = ":all_files",
version_file = "version.txt",
deps = [
"@rules_task//:release",
Expand Down
2 changes: 2 additions & 0 deletions rules/rules_release/tools/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
load("//tools/private:publish_github_release.bzl", _publish_github_release = "publish_github_release")
load("//tools/private:publish_oci_image.bzl", _publish_oci_image = "publish_oci_image")
load("//tools/private:bazel_diff_release.bzl", _bazel_diff_release = "bazel_diff_release")
load("//tools/private:release_changed_files.bzl", _release_changed_files = "release_changed_files")

publish_github_release = _publish_github_release
bazel_diff_release = _bazel_diff_release
publish_oci_image = _publish_oci_image
release_changed_files = _release_changed_files
30 changes: 28 additions & 2 deletions rules/rules_release/tools/lib/repositories/BazelDiffRepository.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,35 @@ export default class BazelDiffRepository {
const currentBranch =
await $`git -C ${this.workspaceDir} rev-parse --abbrev-ref HEAD`;

let hasStashedChanges = false;

try {
const stashResult =
await $`git -C ${this.workspaceDir} stash --include-untracked`;
hasStashedChanges =
stashResult.stdout.trim() !== "No local changes to save";

await this._checkoutSha(sha);
await $`${this.bazelDiffPath} generate-hashes ${this.generateHashesExtraArgs} -w ${this.workspaceDir} -b ${bazelPath} ${hashesFile}`;

await $`${
this.bazelDiffPath
} generate-hashes ${this.generateHashesExtraArgs.split(" ")} -w ${
this.workspaceDir
} -b ${bazelPath} ${hashesFile}`;

await this._checkoutSha(currentBranch);

if (hasStashedChanges) {
await $`git -C ${this.workspaceDir} stash pop`;
}
} catch (error) {
// make sure we checkout back to the current branch
await this._checkoutSha(currentBranch);

// make sure we restore the stash
if (hasStashedChanges) {
await $`git -C ${this.workspaceDir} stash pop`;
}
throw error;
}

Expand All @@ -88,7 +110,11 @@ export default class BazelDiffRepository {
return impactedTargetsPath;
}

await $`${this.bazelDiffPath} get-impacted-targets ${this.getImpactedTargetsExtraArgs} -sh ${previousHashes} -fh ${currentHashes} -o ${impactedTargetsPath}`;
await $`${
this.bazelDiffPath
} get-impacted-targets ${this.getImpactedTargetsExtraArgs.split(
" "
)} -sh ${previousHashes} -fh ${currentHashes} -o ${impactedTargetsPath}`;

return impactedTargetsPath;
}
Expand Down
46 changes: 26 additions & 20 deletions rules/rules_release/tools/private/bazel_diff_release.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def _bazel_diff_release_impl(ctx):
args = [bazel_diff_cli_path, "--bazel-diff-path", bazel_diff_path, "--previous-revision-cmd", previous_revision_path, "--final-revision-cmd", final_revision_path]

if ctx.attr.generate_hashes_extra_args:
args += ["--generate-hashes-extra-args", " ".join(ctx.attr.generate_hashes_extra_args)]
args.append("--generate-hashes-extra-args \'" + " ".join(ctx.attr.generate_hashes_extra_args) + "\'")

if ctx.attr.get_impacted_targets_extra_args:
args += ["--get-impacted-targets-extra-args", " ".join(ctx.attr.get_impacted_targets_extra_args)]
args.append("--get-impacted-targets-extra-args \'" + " ".join(ctx.attr.get_impacted_targets_extra_args) + "\'")

args.append(_to_label_string(ctx.attr.target.label))

Expand Down Expand Up @@ -58,30 +58,36 @@ _bazel_diff_release = rule(
executable = True,
)

def bazel_diff_release(**kwargs):
def bazel_diff_release(previous_revision_cmd = None, final_revision_cmd = None, **kwargs):
name = kwargs.get("name")
change_cmd_name = "{}.change_cmd".format(name)
previous_revision_cmd_name = "{}.previous_revision_cmd".format(name)
final_revision_cmd_name = "{}.final_revision_cmd".format(name)
previous_revision_cmd_name = previous_revision_cmd
final_revision_cmd_name = final_revision_cmd
target = kwargs.pop("target")
generate_hashes_extra_args = kwargs.pop("generate_hashes_extra_args", [])
get_impacted_targets_extra_args = kwargs.pop("get_impacted_targets_extra_args", [])

task(
name = previous_revision_cmd_name,
cmds = [
"git rev-parse master",
],
cwd = "$BUILD_WORKSPACE_DIRECTORY",
)

task(
name = final_revision_cmd_name,
cmds = [
"git rev-parse HEAD",
],
cwd = "$BUILD_WORKSPACE_DIRECTORY",
)
if not previous_revision_cmd_name:
previous_revision_cmd_name = "{}.previous_revision_cmd".format(name)

task(
name = previous_revision_cmd_name,
cmds = [
"git rev-parse master",
],
cwd = "$BUILD_WORKSPACE_DIRECTORY",
)

if not final_revision_cmd_name:
final_revision_cmd_name = "{}.final_revision_cmd".format(name)

task(
name = final_revision_cmd_name,
cmds = [
"git rev-parse HEAD",
],
cwd = "$BUILD_WORKSPACE_DIRECTORY",
)

_bazel_diff_release(
name = change_cmd_name,
Expand Down
48 changes: 48 additions & 0 deletions rules/rules_release/tools/private/release_changed_files.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
load("//release:defs.bzl", "release")
load("@rules_task//task:defs.bzl", "cmd", "task")

def release_changed_files(changed_file_paths, previous_revision_cmd = None, final_revision_cmd = None, **kwargs):
name = kwargs.get("name")
change_cmd_name = "{}.change_cmd".format(name)
previous_revision_cmd_name = previous_revision_cmd
final_revision_cmd_name = final_revision_cmd

if not previous_revision_cmd_name:
previous_revision_cmd_name = "{}.previous_revision_cmd".format(name)

task(
name = previous_revision_cmd_name,
cmds = [
"git rev-parse master",
],
cwd = "$BUILD_WORKSPACE_DIRECTORY",
)

if not final_revision_cmd_name:
final_revision_cmd_name = "{}.final_revision_cmd".format(name)

task(
name = final_revision_cmd_name,
cmds = [
"git rev-parse HEAD",
],
cwd = "$BUILD_WORKSPACE_DIRECTORY",
)

task(
name = change_cmd_name,
cmds = [
"export PREVIOUS_REVISION=$($PREVIOUS_REVISION_CMD)",
"export FINAL_REVISION=$($FINAL_REVISION_CMD)",
"export HAS_CHANGED=$(git diff --name-only $PREVIOUS_REVISION $FINAL_REVISION -- $CHANGED_FILES)",
'if [ -z "$HAS_CHANGED" ]; then echo "false"; else echo "true"; fi',
],
cwd = "$BUILD_WORKSPACE_DIRECTORY",
env = {
"PREVIOUS_REVISION_CMD": cmd.executable(previous_revision_cmd_name),
"FINAL_REVISION_CMD": cmd.executable(final_revision_cmd_name),
"CHANGED_FILES": cmd.shell(*changed_file_paths),
},
)

release(change_cmd = change_cmd_name, **kwargs)
7 changes: 4 additions & 3 deletions rules/rules_task/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@rules_release//tools:defs.bzl", "publish_github_release", release = "bazel_diff_release")
load("@rules_release//tools:defs.bzl", "publish_github_release", release = "release_changed_files")
load("@aspect_bazel_lib//lib:tar.bzl", "mtree_spec", "tar")
load("//task:defs.bzl", "cmd")
load("//tools:defs.bzl", "compile_pip_requirements")
Expand Down Expand Up @@ -106,12 +106,13 @@ publish_github_release(

release(
name = "release",
changed_file_paths = [
"rules/rules_task",
],
changelog_file = "CHANGELOG.md",
generate_hashes_extra_args = ["--fineGrainedHashExternalRepos=rules_task"],
publish_cmds = [
":publish_github_release",
],
release_name = "rules_task",
target = ":all_files",
version_file = "version.txt",
)

0 comments on commit 951b11e

Please sign in to comment.