Skip to content

Commit e0ee252

Browse files
authored
fix: ec2 builder validation step was not working (#325)
*Issue #, if available:* *Description of changes:* The validation step was not working properly; it unexpectedly succeed even when some of the commands are missing. Thi s PR adds `|| exit 1` for every command to exit with error when a command failed. 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 ac8714d commit e0ee252

File tree

3 files changed

+79
-60
lines changed

3 files changed

+79
-60
lines changed

cdk/lib/constructs/worker/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ export class Worker extends Construct {
158158
userData.addCommands(
159159
`
160160
apt-get -o DPkg::Lock::Timeout=-1 update
161+
apt-get -o DPkg::Lock::Timeout=-1 upgrade -y
162+
163+
# Install python3
161164
apt-get -o DPkg::Lock::Timeout=-1 install -y python3-pip unzip
162165
ln -s -f /usr/bin/pip3 /usr/bin/pip
163166
ln -s -f /usr/bin/python3 /usr/bin/python

cdk/lib/constructs/worker/resources/image-component-template.yml

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ phases:
77
steps:
88
- name: InstallUpdates
99
action: UpdateOS
10+
maxAttempts: 3
1011
- name: InstallDependencies
1112
action: ExecuteBash
1213
inputs:
@@ -15,31 +16,31 @@ phases:
1516
- dummy
1617
- name: validate
1718
steps:
18-
- name: HelloWorldStep
19+
- name: ValidateStep
1920
action: ExecuteBash
2021
inputs:
2122
commands:
22-
- aws --version
23-
- docker --version
24-
- python --version
25-
- gh --version
26-
- sudo -u ubuntu bash -i -c "uv --version"
27-
- sudo -u ubuntu bash -i -c "uvx --version"
28-
- sudo -u ubuntu bash -i -c "node --version"
29-
- sudo -u ubuntu bash -i -c "npm --version"
30-
- sudo -u ubuntu bash -i -c "npx --version"
23+
- aws --version || exit 1
24+
- docker --version || exit 1
25+
- python --version || exit 1
26+
- gh --version || exit 1
27+
- sudo -u ubuntu bash -i -c "uv --version" || exit 1
28+
- sudo -u ubuntu bash -i -c "uvx --version" || exit 1
29+
- sudo -u ubuntu bash -i -c "node --version" || exit 1
30+
- sudo -u ubuntu bash -i -c "npm --version" || exit 1
31+
- sudo -u ubuntu bash -i -c "npx --version" || exit 1
3132
- name: test
3233
steps:
33-
- name: HelloWorldStep
34+
- name: TestStep
3435
action: ExecuteBash
3536
inputs:
3637
commands:
37-
- aws --version
38-
- docker --version
39-
- python --version
40-
- gh --version
41-
- sudo -u ubuntu bash -i -c "uv --version"
42-
- sudo -u ubuntu bash -i -c "uvx --version"
43-
- sudo -u ubuntu bash -i -c "node --version"
44-
- sudo -u ubuntu bash -i -c "npm --version"
45-
- sudo -u ubuntu bash -i -c "npx --version"
38+
- aws --version || exit 1
39+
- docker --version || exit 1
40+
- python --version || exit 1
41+
- gh --version || exit 1
42+
- sudo -u ubuntu bash -i -c "uv --version" || exit 1
43+
- sudo -u ubuntu bash -i -c "uvx --version" || exit 1
44+
- sudo -u ubuntu bash -i -c "node --version" || exit 1
45+
- sudo -u ubuntu bash -i -c "npm --version" || exit 1
46+
- sudo -u ubuntu bash -i -c "npx --version" || exit 1

cdk/test/__snapshots__/cdk.test.ts.snap

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4203,6 +4203,7 @@ phases:
42034203
steps:
42044204
- name: InstallUpdates
42054205
action: UpdateOS
4206+
maxAttempts: 3
42064207
- name: InstallDependencies
42074208
action: ExecuteBash
42084209
inputs:
@@ -4211,6 +4212,11 @@ phases:
42114212
42124213
apt-get -o DPkg::Lock::Timeout=-1 update
42134214
4215+
apt-get -o DPkg::Lock::Timeout=-1 upgrade -y
4216+
4217+
4218+
# Install python3
4219+
42144220
apt-get -o DPkg::Lock::Timeout=-1 install -y python3-pip unzip
42154221
42164222
ln -s -f /usr/bin/pip3 /usr/bin/pip
@@ -4669,34 +4675,34 @@ phases:
46694675
\\ "
46704676
- name: validate
46714677
steps:
4672-
- name: HelloWorldStep
4678+
- name: ValidateStep
46734679
action: ExecuteBash
46744680
inputs:
46754681
commands:
4676-
- aws --version
4677-
- docker --version
4678-
- python --version
4679-
- gh --version
4680-
- sudo -u ubuntu bash -i -c "uv --version"
4681-
- sudo -u ubuntu bash -i -c "uvx --version"
4682-
- sudo -u ubuntu bash -i -c "node --version"
4683-
- sudo -u ubuntu bash -i -c "npm --version"
4684-
- sudo -u ubuntu bash -i -c "npx --version"
4682+
- aws --version || exit 1
4683+
- docker --version || exit 1
4684+
- python --version || exit 1
4685+
- gh --version || exit 1
4686+
- sudo -u ubuntu bash -i -c "uv --version" || exit 1
4687+
- sudo -u ubuntu bash -i -c "uvx --version" || exit 1
4688+
- sudo -u ubuntu bash -i -c "node --version" || exit 1
4689+
- sudo -u ubuntu bash -i -c "npm --version" || exit 1
4690+
- sudo -u ubuntu bash -i -c "npx --version" || exit 1
46854691
- name: test
46864692
steps:
4687-
- name: HelloWorldStep
4693+
- name: TestStep
46884694
action: ExecuteBash
46894695
inputs:
46904696
commands:
4691-
- aws --version
4692-
- docker --version
4693-
- python --version
4694-
- gh --version
4695-
- sudo -u ubuntu bash -i -c "uv --version"
4696-
- sudo -u ubuntu bash -i -c "uvx --version"
4697-
- sudo -u ubuntu bash -i -c "node --version"
4698-
- sudo -u ubuntu bash -i -c "npm --version"
4699-
- sudo -u ubuntu bash -i -c "npx --version"
4697+
- aws --version || exit 1
4698+
- docker --version || exit 1
4699+
- python --version || exit 1
4700+
- gh --version || exit 1
4701+
- sudo -u ubuntu bash -i -c "uv --version" || exit 1
4702+
- sudo -u ubuntu bash -i -c "uvx --version" || exit 1
4703+
- sudo -u ubuntu bash -i -c "node --version" || exit 1
4704+
- sudo -u ubuntu bash -i -c "npm --version" || exit 1
4705+
- sudo -u ubuntu bash -i -c "npx --version" || exit 1
47004706
",
47014707
],
47024708
],
@@ -4919,6 +4925,7 @@ phases:
49194925
steps:
49204926
- name: InstallUpdates
49214927
action: UpdateOS
4928+
maxAttempts: 3
49224929
- name: InstallDependencies
49234930
action: ExecuteBash
49244931
inputs:
@@ -4927,6 +4934,11 @@ phases:
49274934
49284935
apt-get -o DPkg::Lock::Timeout=-1 update
49294936
4937+
apt-get -o DPkg::Lock::Timeout=-1 upgrade -y
4938+
4939+
4940+
# Install python3
4941+
49304942
apt-get -o DPkg::Lock::Timeout=-1 install -y python3-pip unzip
49314943
49324944
ln -s -f /usr/bin/pip3 /usr/bin/pip
@@ -5385,34 +5397,34 @@ phases:
53855397
\\ "
53865398
- name: validate
53875399
steps:
5388-
- name: HelloWorldStep
5400+
- name: ValidateStep
53895401
action: ExecuteBash
53905402
inputs:
53915403
commands:
5392-
- aws --version
5393-
- docker --version
5394-
- python --version
5395-
- gh --version
5396-
- sudo -u ubuntu bash -i -c "uv --version"
5397-
- sudo -u ubuntu bash -i -c "uvx --version"
5398-
- sudo -u ubuntu bash -i -c "node --version"
5399-
- sudo -u ubuntu bash -i -c "npm --version"
5400-
- sudo -u ubuntu bash -i -c "npx --version"
5404+
- aws --version || exit 1
5405+
- docker --version || exit 1
5406+
- python --version || exit 1
5407+
- gh --version || exit 1
5408+
- sudo -u ubuntu bash -i -c "uv --version" || exit 1
5409+
- sudo -u ubuntu bash -i -c "uvx --version" || exit 1
5410+
- sudo -u ubuntu bash -i -c "node --version" || exit 1
5411+
- sudo -u ubuntu bash -i -c "npm --version" || exit 1
5412+
- sudo -u ubuntu bash -i -c "npx --version" || exit 1
54015413
- name: test
54025414
steps:
5403-
- name: HelloWorldStep
5415+
- name: TestStep
54045416
action: ExecuteBash
54055417
inputs:
54065418
commands:
5407-
- aws --version
5408-
- docker --version
5409-
- python --version
5410-
- gh --version
5411-
- sudo -u ubuntu bash -i -c "uv --version"
5412-
- sudo -u ubuntu bash -i -c "uvx --version"
5413-
- sudo -u ubuntu bash -i -c "node --version"
5414-
- sudo -u ubuntu bash -i -c "npm --version"
5415-
- sudo -u ubuntu bash -i -c "npx --version"
5419+
- aws --version || exit 1
5420+
- docker --version || exit 1
5421+
- python --version || exit 1
5422+
- gh --version || exit 1
5423+
- sudo -u ubuntu bash -i -c "uv --version" || exit 1
5424+
- sudo -u ubuntu bash -i -c "uvx --version" || exit 1
5425+
- sudo -u ubuntu bash -i -c "node --version" || exit 1
5426+
- sudo -u ubuntu bash -i -c "npm --version" || exit 1
5427+
- sudo -u ubuntu bash -i -c "npx --version" || exit 1
54165428
",
54175429
],
54185430
],
@@ -5489,6 +5501,9 @@ phases:
54895501
[
54905502
"#!/bin/bash
54915503
apt-get -o DPkg::Lock::Timeout=-1 update
5504+
apt-get -o DPkg::Lock::Timeout=-1 upgrade -y
5505+
5506+
# Install python3
54925507
apt-get -o DPkg::Lock::Timeout=-1 install -y python3-pip unzip
54935508
ln -s -f /usr/bin/pip3 /usr/bin/pip
54945509
ln -s -f /usr/bin/python3 /usr/bin/python

0 commit comments

Comments
 (0)