Skip to content

Commit

Permalink
use external scripts to get git sha
Browse files Browse the repository at this point in the history
  • Loading branch information
itegulov committed Jul 24, 2023
1 parent 0230285 commit a18f51b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ locals {
client_email = jsondecode(local.credentials).client_email
client_id = jsondecode(local.credentials).client_id

git_commit_hash = trimspace(file("../.git/${trimspace(trimprefix(file("../.git/HEAD"), "ref:"))}"))

env = {
defaults = {
near_rpc = "https://rpc.testnet.near.org"
Expand All @@ -43,6 +41,10 @@ locals {
workspace = merge(local.env["defaults"], contains(keys(local.env), terraform.workspace) ? local.env[terraform.workspace] : local.env["defaults"])
}

data "external" "git_checkout" {
program = ["${path.module}/scripts/get_sha.sh"]
}

provider "google" {
credentials = local.credentials

Expand Down Expand Up @@ -90,7 +92,7 @@ resource "docker_registry_image" "mpc_recovery" {
}

resource "docker_image" "mpc_recovery" {
name = "${var.region}-docker.pkg.dev/${var.project}/${google_artifact_registry_repository.mpc_recovery.name}/mpc-recovery-${var.env}:${local.git_commit_hash}"
name = "${var.region}-docker.pkg.dev/${var.project}/${google_artifact_registry_repository.mpc_recovery.name}/mpc-recovery-${var.env}:${data.external.git_checkout.result.sha}"
build {
context = "${path.cwd}/.."
}
Expand Down
4 changes: 4 additions & 0 deletions infra/scripts/get_sha.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -euo pipefail

echo '{"sha": "'"$(git rev-parse HEAD)"'"}'

0 comments on commit a18f51b

Please sign in to comment.