Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra: tie docker image tags to git commit hash #208

Merged
merged 3 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/terraform-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
# Generates an execution plan for Terraform
- name: Terraform Plan
id: plan
run: terraform plan -input=false -no-color -var-file terraform-dev.tfvars -var "credentials=$GOOGLE_CREDENTIALS"
run: terraform plan -input=false -no-color -lock-timeout=1h -var-file terraform-dev.tfvars -var "credentials=$GOOGLE_CREDENTIALS"
env:
GOOGLE_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS_DEV }}

Expand Down Expand Up @@ -126,6 +126,6 @@ jobs:
# On push to "develop", build or change infrastructure according to Terraform configuration files
- name: Terraform Apply
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
run: terraform apply -auto-approve -input=false -var-file terraform-dev.tfvars -var "credentials=$GOOGLE_CREDENTIALS"
run: terraform apply -auto-approve -input=false -lock-timeout=1h -var-file terraform-dev.tfvars -var "credentials=$GOOGLE_CREDENTIALS"
env:
GOOGLE_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS_DEV }}
2 changes: 1 addition & 1 deletion .github/workflows/terraform-feature-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
# Applies Terraform configuration to the temporary environment
- name: Terraform Apply
id: apply
run: terraform apply -auto-approve -input=false -no-color -var-file terraform-dev.tfvars -var "credentials=$GOOGLE_CREDENTIALS" -var "env=dev-$PR_NUMBER"
run: terraform apply -auto-approve -input=false -no-color -lock-timeout=1h -var-file terraform-dev.tfvars -var "credentials=$GOOGLE_CREDENTIALS" -var "env=dev-$PR_NUMBER"
env:
GOOGLE_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS_DEV }}
PR_NUMBER: ${{ env.PR_NUMBER }}
Expand Down
6 changes: 5 additions & 1 deletion infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,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 @@ -88,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}"
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)"'"}'