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

[Issue #3003] Add deployment info #3072

Merged
merged 3 commits into from
Dec 3, 2024
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
6 changes: 5 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ jobs:
environment: ${{ inputs.environment }}

- name: Deploy release
run: make release-deploy APP_NAME=${{ inputs.app_name }} ENVIRONMENT=${{ inputs.environment }}
run: make release-deploy \
APP_NAME=${{ inputs.app_name }} \
ENVIRONMENT=${{ inputs.environment }} \
DEPLOY_GITHUB_REF=${{ github.ref_name }} \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the ref always the branch name, or does it become the release?

Just thinking about how we build the URLs in the API with this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will there be a consistent URL I can build if it can refer to both a branch and a release? Any pattern of github.com/something/<branch or release> that I can follow?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err, I suppose the /tree path does, but for releases I wonder if linking to the release page would be better - could maybe regex that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For both the ref and commit the URL is gonna be https://github.com/HHS/simpler-grants-gov/tree/< commit / branch / release >, examples:

DEPLOY_GITHUB_SHA=${{ github.sha }}
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ infra-update-app-service: ## Create or update $APP_NAME's web service module
@:$(call check_defined, APP_NAME, the name of subdirectory of /infra that holds the application's infrastructure code)
@:$(call check_defined, ENVIRONMENT, the name of the application environment e.g. "prod" or "staging")
terraform -chdir="infra/$(APP_NAME)/service" init -input=false -reconfigure -backend-config="$(ENVIRONMENT).s3.tfbackend"
terraform -chdir="infra/$(APP_NAME)/service" apply -var="environment_name=$(ENVIRONMENT)"
terraform -chdir="infra/$(APP_NAME)/service" apply -var="environment_name=$(ENVIRONMENT)" -var="deploy_github_ref=$(DEPLOY_GITHUB_REF)" -var="deploy_github_sha=$(DEPLOY_GITHUB_SHA)"

infra-update-metabase-service: ## Create or update $APP_NAME's web service module
# APP_NAME has a default value defined above, but check anyways in case the default is ever removed
Expand Down Expand Up @@ -201,12 +201,12 @@ release-run-database-migrations: ## Run $APP_NAME's database migrations in $ENVI
release-deploy: ## Deploy release to $APP_NAME's web service in $ENVIRONMENT
@:$(call check_defined, APP_NAME, the name of subdirectory of /infra that holds the application's infrastructure code)
@:$(call check_defined, ENVIRONMENT, the name of the application environment e.g. "prod" or "dev")
./bin/deploy-release.sh $(APP_NAME) $(IMAGE_TAG) $(ENVIRONMENT)
./bin/deploy-release.sh $(APP_NAME) $(IMAGE_TAG) $(ENVIRONMENT) $(DEPLOY_GITHUB_REF) $(DEPLOY_GITHUB_SHA)

metabase-deploy: ## Deploy metabase to $APP_NAME's web service in $ENVIRONMENT
@:$(call check_defined, APP_NAME, the name of subdirectory of /infra that holds the application's infrastructure code)
@:$(call check_defined, ENVIRONMENT, the name of the application environment e.g. "prod" or "dev")
./bin/deploy-metabase.sh $(APP_NAME) $(IMAGE_TAG) $(ENVIRONMENT)
./bin/deploy-metabase.sh $(APP_NAME) $(IMAGE_TAG) $(ENVIRONMENT)

release-image-name: ## Prints the image name of the release image
@:$(call check_defined, APP_NAME, the name of subdirectory of /infra that holds the application's infrastructure code)
Expand Down
6 changes: 5 additions & 1 deletion bin/deploy-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -euo pipefail
APP_NAME=$1
IMAGE_TAG=$2
ENVIRONMENT=$3
DEPLOY_GITHUB_REF=$4
DEPLOY_GITHUB_SHA=$5

echo "--------------"
echo "Deploy release"
Expand All @@ -12,9 +14,11 @@ echo "Input parameters:"
echo " APP_NAME=$APP_NAME"
echo " IMAGE_TAG=$IMAGE_TAG"
echo " ENVIRONMENT=$ENVIRONMENT"
echo " DEPLOY_GITHUB_REF=$DEPLOY_GITHUB_REF"
echo " DEPLOY_GITHUB_SHA=$DEPLOY_GITHUB_SHA"
echo
echo "Starting $APP_NAME deploy of $IMAGE_TAG to $ENVIRONMENT"

TF_CLI_ARGS_apply="-input=false -auto-approve -var=image_tag=$IMAGE_TAG" make infra-update-app-service APP_NAME="$APP_NAME" ENVIRONMENT="$ENVIRONMENT"
TF_CLI_ARGS_apply="-input=false -auto-approve -var=image_tag=$IMAGE_TAG" make infra-update-app-service APP_NAME="$APP_NAME" ENVIRONMENT="$ENVIRONMENT" DEPLOY_GITHUB_REF="$DEPLOY_GITHUB_REF" DEPLOY_GITHUB_SHA="$DEPLOY_GITHUB_SHA"

echo "Completed $APP_NAME deploy of $IMAGE_TAG to $ENVIRONMENT"
12 changes: 12 additions & 0 deletions infra/analytics/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ variable "image_tag" {
description = "image tag to deploy to the environment"
default = null
}

variable "deploy_github_ref" {
type = string
description = "github ref to deploy"
default = null
}

variable "deploy_github_sha" {
type = string
description = "github sha to deploy"
default = null
}
3 changes: 3 additions & 0 deletions infra/api/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ module "service" {
extra_environment_variables = merge(
local.service_config.extra_environment_variables,
{ "ENVIRONMENT" : var.environment_name },
{ "DEPLOY_TIMESTAMP" : timestamp() },
var.deploy_github_sha != null ? { "DEPLOY_GITHUB_SHA" : var.deploy_github_sha } : {},
var.deploy_github_ref != null ? { "DEPLOY_GITHUB_REF" : var.deploy_github_ref } : {}
)

secrets = concat(
Expand Down
12 changes: 12 additions & 0 deletions infra/api/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ variable "image_tag" {
description = "image tag to deploy to the environment"
default = null
}

variable "deploy_github_ref" {
type = string
description = "github ref to deploy"
default = null
}

variable "deploy_github_sha" {
type = string
description = "github sha to deploy"
default = null
}
12 changes: 12 additions & 0 deletions infra/frontend/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ variable "domain" {
description = "DNS domain of the website managed by HHS"
default = null
}

variable "deploy_github_ref" {
type = string
description = "github ref to deploy"
default = null
}

variable "deploy_github_sha" {
type = string
description = "github sha to deploy"
default = null
}