From a18f51bdb193fdb9b37eb967d7167a42209ffa05 Mon Sep 17 00:00:00 2001 From: Daniyar Itegulov Date: Mon, 24 Jul 2023 18:35:26 +1000 Subject: [PATCH] use external scripts to get git sha --- infra/main.tf | 8 +++++--- infra/scripts/get_sha.sh | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 infra/scripts/get_sha.sh diff --git a/infra/main.tf b/infra/main.tf index f64b7c7a1..ce3f18b22 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -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" @@ -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 @@ -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}/.." } diff --git a/infra/scripts/get_sha.sh b/infra/scripts/get_sha.sh new file mode 100644 index 000000000..784f8a343 --- /dev/null +++ b/infra/scripts/get_sha.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -euo pipefail + +echo '{"sha": "'"$(git rev-parse HEAD)"'"}'