-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildspec.api-platform.yml
More file actions
59 lines (56 loc) · 3.46 KB
/
Copy pathbuildspec.api-platform.yml
File metadata and controls
59 lines (56 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
version: 0.2
env:
shell: bash
phases:
pre_build:
commands:
- set -euo pipefail
# ENVIRONMENT comes from the CodeBuild project (production | staging).
# Production keeps the original unsuffixed stack name for continuity.
- ENVIRONMENT="${ENVIRONMENT:-production}"
- if [ "$ENVIRONMENT" = "production" ]; then STACK_NAME="commons-platform-services"; else STACK_NAME="commons-platform-services-${ENVIRONMENT}"; fi
# Per-environment values injected by the CodeBuild project env vars:
# AGENT_COMMONS_INTERNAL_URL, COMMON_OS_INTERNAL_URL, IDENTITY_ISSUER_URL
- IMAGE_TAG="${CODEBUILD_RESOLVED_SOURCE_VERSION:-manual}-${CODEBUILD_BUILD_NUMBER}"
- REGISTRY="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
- GATEWAY_IMAGE="${REGISTRY}/${GATEWAY_ECR_REPOSITORY}:${IMAGE_TAG}"
- >-
IDENTITY_IMAGE="$(aws cloudformation describe-stacks
--stack-name "$STACK_NAME"
--query 'Stacks[0].Parameters[?ParameterKey==`IdentityImageUri`].ParameterValue | [0]'
--output text --region "$AWS_REGION" 2>/dev/null || true)"
- if [[ -z "$IDENTITY_IMAGE" || "$IDENTITY_IMAGE" == "None" || "${DEPLOY_IDENTITY:-false}" == "true" ]]; then IDENTITY_IMAGE="${REGISTRY}/${IDENTITY_ECR_REPOSITORY}:${IMAGE_TAG}"; fi
- aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$REGISTRY"
build:
commands:
- if [[ "${DEPLOY_IDENTITY:-false}" == "true" ]]; then docker build --platform linux/amd64 -f apps/commons-identity/Dockerfile -t "$IDENTITY_IMAGE" .; fi
- docker build --platform linux/amd64 -f apps/commons-api-gateway/Dockerfile -t "$GATEWAY_IMAGE" .
- if [[ "${DEPLOY_IDENTITY:-false}" == "true" ]]; then docker push "$IDENTITY_IMAGE"; fi
- docker push "$GATEWAY_IMAGE"
post_build:
commands:
- >-
aws cloudformation deploy
--stack-name "$STACK_NAME"
--template-file infra/aws/api-platform-services.yml
--capabilities CAPABILITY_NAMED_IAM
--parameter-overrides
Environment="$ENVIRONMENT"
IdentityIssuerUrl="${IDENTITY_ISSUER_URL:-https://auth.agentcommons.io/api/auth}"
IdentityImageUri="$IDENTITY_IMAGE"
GatewayImageUri="$GATEWAY_IMAGE"
ExecutionRoleArn="$TASK_EXECUTION_ROLE_ARN"
InfrastructureRoleArn="$INFRASTRUCTURE_ROLE_ARN"
IdentityRuntimeSecretArn="$IDENTITY_RUNTIME_SECRET_ARN"
GatewayRuntimeSecretArn="$GATEWAY_RUNTIME_SECRET_ARN"
AgentCommonsInternalUrl="$AGENT_COMMONS_INTERNAL_URL"
CommonOsInternalUrl="$COMMON_OS_INTERNAL_URL"
--region "$AWS_REGION"
- IDENTITY_ENDPOINT=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query 'Stacks[0].Outputs[?OutputKey==`IdentityEndpoint`].OutputValue' --output text --region "$AWS_REGION")
- GATEWAY_ENDPOINT=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query 'Stacks[0].Outputs[?OutputKey==`GatewayEndpoint`].OutputValue' --output text --region "$AWS_REGION")
- curl --fail --silent --show-error --retry 20 --retry-delay 10 --retry-all-errors "https://${IDENTITY_ENDPOINT#https://}/health"
- curl --fail --silent --show-error --retry 20 --retry-delay 10 --retry-all-errors "https://${GATEWAY_ENDPOINT#https://}/health"
- printf '{"identityEndpoint":"%s","gatewayEndpoint":"%s","environment":"%s"}\n' "$IDENTITY_ENDPOINT" "$GATEWAY_ENDPOINT" "$ENVIRONMENT" > deployment.json
artifacts:
files:
- deployment.json