generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add policy build script to pre-commit hook (#25)
This builds and base64 encodes the policy.wasm on each commit to ensure the action always has the correct version of the OPA policy bundled.
- Loading branch information
Showing
14 changed files
with
87 additions
and
58 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
POLICY_DIR="$(dirname ${BASH_SOURCE[0]})" | ||
|
||
# Build the Open Policy Agent policy WebAssembly module (.wasm) from the .rego files | ||
opa build -t wasm \ | ||
-e 'terraform' \ | ||
-e 'terraform/no_changes' \ | ||
-e 'terraform/resource_changes' \ | ||
-e 'terraform/output_changes' "$POLICY_DIR" | ||
tar -xzf bundle.tar.gz /policy.wasm | ||
mv policy.wasm "$POLICY_DIR" | ||
rm bundle.tar.gz | ||
|
||
# Base 64 encode and write the policy.js that is used by the action | ||
POLICY_BASE64="$(base64 $POLICY_DIR/policy.wasm)" | ||
echo " | ||
\"use strict\" | ||
// Auto-generated by 'npm run policy' | ||
module.exports = { | ||
policyWasmBase64: \"${POLICY_BASE64}\", | ||
}; | ||
" > "$POLICY_DIR"/policy.js |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters