-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildspec.yml
57 lines (53 loc) · 2.32 KB
/
buildspec.yml
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
version: 0.2
phases:
install:
runtime-versions:
nodejs: 20
commands:
- npm update -g npm
- npm install -g yarn
- node -v
- npm -v
- yarn -v
- # Update the AWS CLI and SAM CLI
- pip install --upgrade awscli
- pip install --upgrade aws-sam-cli
build:
commands:
# Build/package the backend
- sam build -c -p
#- sam package --template-file .aws-sam/build/template.yaml --s3-bucket $S3_BUCKET --output-template-file packaged-template.yaml
# Copy custom embeds from source to the build folder
- |
if [ -d "$CODEBUILD_SRC_DIR_Embeds" ]; then
# Copy custom embeds from source to the build folder
cp -R "$CODEBUILD_SRC_DIR_Embeds"/* client/src/components/posts/embeds/domains_custom/
ls -la client/src/components/posts/embeds/domains_custom/
else
echo "Source directory not found. Skipping copy."
fi
# Build the frontend
- cd client
- yarn install
# get the .env file from SSM
- aws ssm get-parameter --name $ENV_SSM_PARAM --query Parameter.Value --output text > .env.production
- cp .env.production .env # needed for the build
- yarn build
# Debug: List files in the build directory
- ls -la dist
# Navigate back to the parent directory
- cd ..
post_build:
commands:
# Deploy the backend
- sam deploy --template-file .aws-sam/build/template.yaml --stack-name $STACK_NAME --capabilities CAPABILITY_IAM --parameter-overrides Domain=$DOMAIN ACMCertificateArn=$ACM_CERTIFICATE_ARN ENVSsmParam=$ENV_SSM_PARAM --resolve-s3
# Get the s3 bucket name from the stack output
- FRONTEND_S3=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query "Stacks[0].Outputs[?OutputKey=='ReacdditAPIBucket'].OutputValue" --output text)
# Get the cloudfront distribution id from the stack output
- CLOUDFRONT_DISTRIBUTION_ID=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query "Stacks[0].Outputs[?OutputKey=='CloudFrontDistribution'].OutputValue" --output text)
- aws s3 cp client/dist s3://$FRONTEND_S3/dist --recursive
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"
artifacts:
files:
- packaged-template.yaml
- client/dist/**/*