Skip to content

Commit

Permalink
fix: Provisioner deploy once again (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvgijssel authored Dec 23, 2023
1 parent dc5d883 commit 2c31663
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/provisioner-poor-news-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"provisioner": patch
---

fix: Improve CI caching and fix remote tags loading
15 changes: 15 additions & 0 deletions .github/actions/setup-bazel/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: "Setup Bazel"
description: "Setup the CI to work properly with Bazel"
inputs:
OP_SERVICE_ACCOUNT_TOKEN:
description: "Service Account Token for 1Password"
required: true
runs:
using: "composite"
steps:
Expand All @@ -8,9 +12,19 @@ runs:
with:
path: |
tmp/output_base/external
/nix/store
key: bazel-cache-${{ runner.os }}-${{ github.job }}-${{ github.sha }}
restore-keys: bazel-cache-${{ runner.os }}-${{ github.job }}-

- name: Load secret
uses: 1password/load-secrets-action@v1
with:
# Export loaded secrets as environment variables
export-env: true
env:
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:
Expand All @@ -19,5 +33,6 @@ runs:
- name: Create local.bazelrc file
shell: bash
run: |
echo "build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY" > local.bazelrc
echo "startup --output_base=$(pwd)/tmp/output_base" >> local.bazelrc
cat local.bazelrc
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./.github/actions/setup-bazel
- run: bazel run //provisioner:deploy
env:
ONEPASSWORD_SERVICE_ACCOUNT_TOKEN_PROD: ${{ secrets.ONEPASSWORD_SERVICE_ACCOUNT_TOKEN_PROD }}
with:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.ONEPASSWORD_SERVICE_ACCOUNT_TOKEN_PROD }}
- run: bazel run --config buildbuddy --config buildbuddy_rbe //provisioner:deploy
4 changes: 3 additions & 1 deletion .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./.github/actions/setup-bazel
- run: bazel run //provisioner:deploy_validate
with:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.ONEPASSWORD_SERVICE_ACCOUNT_TOKEN_PROD }}
- run: bazel run --config buildbuddy --config buildbuddy_rbe //provisioner:deploy_validate
env:
ONEPASSWORD_SERVICE_ACCOUNT_TOKEN_PROD: ${{ secrets.ONEPASSWORD_SERVICE_ACCOUNT_TOKEN_PROD }}
1 change: 0 additions & 1 deletion provisioner/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ task(
cmd.executable(":deploy_provision"),
cmd.executable(":deploy_validate"),
],
cwd = "$BUILD_WORKSPACE_DIRECTORY",
# Add in all the .github files to the data attribute,
# so if the github workflows change then we re-run the deployment
data = glob([".github/**"]),
Expand Down
15 changes: 2 additions & 13 deletions tools/onepassword/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,12 @@
from pathlib import Path


def _get_onepassword_service_account_token(env_key, tmp_file):
def _get_onepassword_service_account_token(env_key):
if env_key in os.environ:
return os.environ[env_key]

file = os.path.join(
os.environ.get("BUILD_WORKSPACE_DIRECTORY", ""),
"tmp",
tmp_file,
)

if os.path.exists(file):
return Path(file).read_text()

else:
raise ValueError(f"Either set env variable '{env_key}' or create file '{file}'")
raise ValueError(f"Set env variable '{env_key}'.")


def get_item_path(path):
Expand All @@ -37,13 +28,11 @@ def get_item_path(path):
onepassword_vault_id = "vgijssel-prod"
onepassword_service_account_token = _get_onepassword_service_account_token(
"ONEPASSWORD_SERVICE_ACCOUNT_TOKEN_PROD",
"1password-service-account-token-prod",
)
else:
onepassword_vault_id = "vgijssel-dev"
onepassword_service_account_token = _get_onepassword_service_account_token(
"ONEPASSWORD_SERVICE_ACCOUNT_TOKEN_DEV",
"1password-service-account-token-dev",
)

op_binary = os.environ["OP_BINARY"]
Expand Down

0 comments on commit 2c31663

Please sign in to comment.