Skip to content

Commit

Permalink
Add partition and domain overrides in make file
Browse files Browse the repository at this point in the history
  • Loading branch information
bedanley committed Dec 6, 2024
1 parent 6edd50b commit 99f8388
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
25 changes: 19 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,20 @@ ifeq (${REGION},)
$(error region must be set in command line using REGION variable or config files)
endif

# URL_SUFFIX - used for the docker login
ifeq (${PARTITION},)
PARTITION := $(shell cat $(PROJECT_DIR)/config-custom.yaml | yq .partition )
endif
ifeq (${PARTITION}, null)
PARTITION := aws
endif

# DOMAIN - used for the docker login
ifeq (${DOMAIN},)
ifeq ($(findstring iso,${REGION}),)
URL_SUFFIX := amazonaws.com
DOMAIN := amazonaws.com
else
URL_SUFFIX := c2s.ic.gov
DOMAIN := c2s.ic.gov
endif
endif

# Arguments defined through config files
Expand Down Expand Up @@ -117,16 +126,18 @@ MODEL_BUCKET := $(shell cat $(PROJECT_DIR)/config-custom.yaml | yq '.s3BucketMod

## Bootstrap AWS Account with CDK bootstrap
bootstrap:
@printf "Bootstrapping: $(ACCOUNT_NUMBER) | $(REGION)\n"
@printf "Bootstrapping: $(ACCOUNT_NUMBER) | $(REGION) | $(PARTITION)\n"

ifdef PROFILE
@cdk bootstrap \
--profile $(PROFILE) \
aws://$(ACCOUNT_NUMBER)/$(REGION) \
--partition $(PARTITION) \
--cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
else
@cdk bootstrap \
aws://$(ACCOUNT_NUMBER)/$(REGION) \
--partition $(PARTITION) \
--cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
endif

Expand Down Expand Up @@ -234,11 +245,11 @@ cleanMisc:
dockerLogin: dockerCheck
ifdef PROFILE
@$(foreach ACCOUNT,$(ACCOUNT_NUMBERS_ECR), \
aws ecr get-login-password --region ${REGION} --profile ${PROFILE} | $(DOCKER_CMD) login --username AWS --password-stdin ${ACCOUNT}.dkr.ecr.${REGION}.${URL_SUFFIX} >/dev/null 2>&1; \
aws ecr get-login-password --region ${REGION} --profile ${PROFILE} | $(DOCKER_CMD) login --username AWS --password-stdin ${ACCOUNT}.dkr.ecr.${REGION}.${DOMAIN} >/dev/null 2>&1; \
)
else
@$(foreach ACCOUNT,$(ACCOUNT_NUMBERS_ECR), \
aws ecr get-login-password --region ${REGION} | $(DOCKER_CMD) login --username AWS --password-stdin ${ACCOUNT}.dkr.ecr.${REGION}.${URL_SUFFIX} >/dev/null 2>&1; \
aws ecr get-login-password --region ${REGION} | $(DOCKER_CMD) login --username AWS --password-stdin ${ACCOUNT}.dkr.ecr.${REGION}.${DOMAIN} >/dev/null 2>&1; \
)
endif

Expand All @@ -255,6 +266,8 @@ define print_config
-----------------------------------\n \
Account Number $(ACCOUNT_NUMBER)\n \
Region $(REGION)\n \
Partition $(PARTITION)\n \
Domain $(DOMAIN)\n \
App Name $(APP_NAME)\n \
Deployment Stage $(DEPLOYMENT_STAGE)\n \
Deployment Name $(DEPLOYMENT_NAME)"
Expand Down
2 changes: 2 additions & 0 deletions bin/lisa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const mappings: EnvMapping[] = [
['PROFILE', 'profile'],
['DEPLOYMENT_NAME', 'deploymentName'],
['ACCOUNT_NUMBER', 'accountNumber'],
['PARTITION', 'partition'],
['DOMAIN', 'domain'],
['REGION', 'region'],
];
mappings.forEach(([envVar, configVar]) => {
Expand Down
3 changes: 2 additions & 1 deletion lib/docs/admin/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ When deploying for dev and testing you can use a self-signed certificate for the

```bash
export REGION=<your-region>
export DOMAIN=<your-domain> #Optional if not running in 'aws' partition
./scripts/gen-certs.sh
aws iam upload-server-certificate --server-certificate-name <cert-name> --certificate-body file://scripts/server.pem --private-key file://scripts/server.key
```
Expand All @@ -172,7 +173,7 @@ Update your `config-custom.yaml` with the certificate ARN:

```yaml
restApiConfig:
sslCertIamArn: arn:aws:iam::<account-number>:server-certificate/<certificate-name>
sslCertIamArn: arn:<aws-partition>:iam::<account-number>:server-certificate/<certificate-name>
```

## Step 9: Customize Model Deployment
Expand Down
2 changes: 2 additions & 0 deletions lib/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ const RawConfigSchema = z
})
.describe('AWS account number for deployment. Must be 12 digits.'),
region: z.string().describe('AWS region for deployment.'),
partition: z.string().default('aws').describe('AWS partition for deployment.'),
domain: z.string().default('amazonaws.com').describe('AWS domain for deployment'),
restApiConfig: FastApiContainerConfigSchema,
vpcId: z.string().optional().describe('VPC ID for the application. (e.g. vpc-0123456789abcdef)'),
subnets: z.array(z.object({
Expand Down
8 changes: 6 additions & 2 deletions scripts/gen-certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ if [[ -z $REGION ]]; then
exit 1
fi

domain="*.$REGION.elb.amazonaws.com"
if [[ -z $DOMAIN ]]; then
DOMAIN="amazonaws.com"
fi

domain="*.$REGION.elb.$DOMAIN"

# Check if the certificate and key files already exist
if [ ! -f "$outPathCert" ] || [ ! -f "$outPathKey" ]; then
Expand All @@ -21,7 +25,7 @@ if [ ! -f "$outPathCert" ] || [ ! -f "$outPathKey" ]; then
maj=$(echo "$openssl_version" | cut -d. -f1)
min=$(echo "$openssl_version" | cut -d. -f2)
if [ $maj -eq 1 ] && [ $min -lt 10 ] || [ $maj -lt 1 ]; then
echo "Warning: Your version of OpenSSL ${openssl_version} is not supported. Please upgrade to version 1.10+")
echo "Warning: Your version of OpenSSL ${openssl_version} is not supported. Please upgrade to version 1.10+"
exit 1
fi

Expand Down

0 comments on commit 99f8388

Please sign in to comment.