Skip to content

Commit 870a6a7

Browse files
authored
chore(cicd): update buildspec to list and build jobs (#1505)
<!-- Provide summary of changes --> Updates the buildspec to list, package, and build jobs. Shouldn't be merged in until #1428 is completed. Related #1131 #1428 #1480 <!-- Issue number, if available. E.g. "Fixes #31", "Addresses #42, 77" --> By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent d608791 commit 870a6a7

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

templates/cicd/buildspec.yml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ phases:
2222
- export COLOR="false"
2323
# Find all the local services in the workspace.
2424
- svcs=$(./copilot-linux svc ls --local --json | jq '.services[].name' | sed 's/"//g')
25-
# Find all the environments.
25+
# Find all the local jobs in the workspace.
26+
- jobs=$(./copilot-linux job ls --local --json | jq '.jobs[].name' | sed 's/"//g')
27+
# Find all the environments
2628
- envs=$(./copilot-linux env ls --json | jq '.environments[].name' | sed 's/"//g')
2729
# Generate the cloudformation templates.
2830
# The tag is the build ID but we replaced the colon ':' with a dash '-'.
@@ -32,17 +34,22 @@ phases:
3234
for svc in $svcs; do
3335
./copilot-linux svc package -n $svc -e $env --output-dir './infrastructure' --tag $tag;
3436
done;
37+
for job in $jobs; do
38+
./copilot-linux job package -n $job -e $env --output-dir './infrastructure' --tag $tag;
39+
done;
3540
done;
3641
- ls -lah ./infrastructure
42+
# Concatenate jobs and services into one var for addons
3743
# If addons exists, upload addons templates to each S3 bucket and write template URL to template config files.
44+
- WORKLOADS=$(echo $jobs $svcs)
3845
- |
39-
for svc in $svcs; do
40-
ADDONSFILE=./infrastructure/$svc.addons.stack.yml
46+
for workload in $WORKLOADS; do
47+
ADDONSFILE=./infrastructure/$workload.addons.stack.yml
4148
if [ -f "$ADDONSFILE" ]; then
4249
tmp=$(mktemp)
4350
timestamp=$(date +%s){{range $bucket := .ArtifactBuckets}}
44-
aws s3 cp "$ADDONSFILE" "s3://{{$bucket.BucketName}}/manual/$timestamp/$svc.addons.stack.yml";{{range $envName := $bucket.Environments}}
45-
jq --arg a "https://{{$bucket.BucketName}}.s3-{{$bucket.Region}}.amazonaws.com/manual/$timestamp/$svc.addons.stack.yml" '.Parameters.AddonsTemplateURL = $a' ./infrastructure/$svc-{{$envName}}.params.json > "$tmp" && mv "$tmp" ./infrastructure/$svc-{{$envName}}.params.json{{end}}{{end}}
51+
aws s3 cp "$ADDONSFILE" "s3://{{$bucket.BucketName}}/manual/$timestamp/$workload.addons.stack.yml";{{range $envName := $bucket.Environments}}
52+
jq --arg a "https://{{$bucket.BucketName}}.s3-{{$bucket.Region}}.amazonaws.com/manual/$timestamp/$workload.addons.stack.yml" '.Parameters.AddonsTemplateURL = $a' ./infrastructure/$workload-{{$envName}}.params.json > "$tmp" && mv "$tmp" ./infrastructure/$workload-{{$envName}}.params.json{{end}}{{end}}
4653
fi
4754
done;
4855
# Build images
@@ -53,8 +60,8 @@ phases:
5360
# - Retrieve the ECR repository.
5461
# - Login and push the image.
5562
- >
56-
for svc in $svcs; do
57-
manifest=$(cat $CODEBUILD_SRC_DIR/copilot/$svc/manifest.yml | ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))')
63+
for workload in $WORKLOADS; do
64+
manifest=$(cat $CODEBUILD_SRC_DIR/copilot/$workload/manifest.yml | ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))')
5865
image_location=$(echo $manifest | jq '.image.location')
5966
if [ ! "$image_location" = null ]; then
6067
echo "skipping image building because location is provided as $image_location";
@@ -79,15 +86,15 @@ phases:
7986
build_args="$build_args--build-arg $arg "
8087
done
8188
fi
82-
echo "Service: $svc"
89+
echo "Name: $workload"
8390
echo "Relative Dockerfile path: $df_rel_path"
8491
echo "Docker build context: $df_dir_path"
8592
echo "Docker build args: $build_args"
86-
echo "Running command: docker build -t $svc:$tag $build_args-f $df_path $df_dir_path";
87-
docker build -t $svc:$tag $build_args-f $df_path $df_dir_path;
88-
image_id=$(docker images -q $svc:$tag);
93+
echo "Running command: docker build -t $workload:$tag $build_args-f $df_path $df_dir_path";
94+
docker build -t $workload:$tag $build_args-f $df_path $df_dir_path;
95+
image_id=$(docker images -q $workload:$tag);
8996
for env in $envs; do
90-
repo=$(cat $CODEBUILD_SRC_DIR/infrastructure/$svc-$env.params.json | jq '.Parameters.ContainerImage' | sed 's/"//g');
97+
repo=$(cat $CODEBUILD_SRC_DIR/infrastructure/$workload-$env.params.json | jq '.Parameters.ContainerImage' | sed 's/"//g');
9198
region=$(echo $repo | cut -d'.' -f4);
9299
$(aws ecr get-login --no-include-email --region $region);
93100
docker tag $image_id $repo;
@@ -96,4 +103,4 @@ phases:
96103
done;
97104
artifacts:
98105
files:
99-
- "infrastructure/*"
106+
- "infrastructure/*"

0 commit comments

Comments
 (0)