-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildspec.yaml
79 lines (65 loc) · 3.05 KB
/
buildspec.yaml
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Build specifications for AWS CodeBuild
# See: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html
# Each input artifact is extracted to its own directory by CodePipeline, the locations of which
# are stored in environment variables. The directory for the primary source artifact (this repo)
# is made available with $CODEBUILD_SRC_DIR. The directory for the DMPTool push artifacts is
# made available with $CODEBUILD_SRC_DIR_dmptool-commit.
# Do not change version. This is the version of aws buildspec, not the version of your buldspec file.
version: 0.2
phases:
install:
runtime-versions:
# Apollo gives error when building on < 21
nodejs: 21
commands:
# Install any libraries necessary for testing and compilation
# - echo Installing Mocha...
# - npm install -g mocha
pre_build:
commands:
# Set some ENV variables here because CF only allows a limit of 1000 characters in the
# EnvironmentVariable config for the Pipeline action :(
- export AWS_VERSION=$(aws --version)
# Fetch the ECR repository name
- echo $ECR_REPOSITORY_URI >> .ecr
- export SHORT_ECR_URI=$(awk '{gsub("$ECR_REPOSITORY_NAME", "");print}' .ecr)
- rm .ecr
# Set the repository URI to your ECR image and add an image tag with the first seven characters of the Git
# commit ID of the source.
- echo Logging in to Amazon ECR ...
- aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $SHORT_ECR_URI
- IMAGE_TAG=${COMMIT_HASH:=apollo-latest}
# Install MySQL so we can run DB migrations
# - dnf -y install mariadb105
build:
commands:
- echo "Running build in ${NODE_ENV} mode - started on `date`"
- cd $CODEBUILD_SRC_DIR
# - echo Checking for DB migrations
# - cd $CODEBUILD_SRC_DIR
# - cd data-migrations && ./process-aws.sh $NODE_ENV && cd ..
# Install all of the dependencies (including dev so we can compile TS)
- npm install --production=false
# Generate all of the GraphQL schema types
- npm run generate
# Run any tests here
# - npm run test
# Build the Apollo server which writes to the ./dist dir
- npm run build
- echo Building the Docker image...
- docker build -f Dockerfile.aws -t $SHORT_ECR_URI:apollo-latest .
- docker tag $ECR_REPOSITORY_URI:apollo-latest $SHORT_ECR_URI:$IMAGE_TAG
post_build:
commands:
# Push the Docker image to the ECR repository. Fargate will pick it up an deploy automatically
- echo Build completed on `date`
- echo Pushing the Docker images...
- cd $CODEBUILD_SRC_DIR
- docker push $SHORT_ECR_URI:apollo-latest
- docker push $SHORT_ECR_URI:$IMAGE_TAG
- echo Writing image definitions file...
- printf '[{"name":"%s","imageUri":"%s"}]' $TASK_DEFINITION_CONTAINER_NAME $ECR_REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
- echo Build completed on `date`
artifacts:
# The Deploy step is expecting this name
files: imagedefinitions.json