Skip to content

Commit e4ebc40

Browse files
authored
fix: Clean-up Lambda /tmp directory for a fresh runner (#244)
The `/tmp` directory can have some files left behind from previous runs when a Lambda instance is reused. We want a clean home directory and clean `/tmp` directory so one run can break the next one. See #242
1 parent 66b10db commit e4ebc40

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

src/providers/docker-images/lambda/linux-arm64/runner.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22

33
set -e -u -o pipefail
44

5+
# cleanup
6+
find /tmp -mindepth 1 -maxdepth 1 -exec rm -rf '{}' \;
7+
# copy runner code (it needs a writable directory)
58
cp -r /runner /tmp/
69
cd /tmp/runner
7-
mkdir -p /tmp/home
10+
# setup home directory
11+
mkdir /tmp/home
812
export HOME=/tmp/home
913

14+
# start runner
1015
if [ "${RUNNER_VERSION}" = "latest" ]; then RUNNER_FLAGS=""; else RUNNER_FLAGS="--disableupdate"; fi
1116
./config.sh --unattended --url "https://${GITHUB_DOMAIN}/${OWNER}/${REPO}" --token "${RUNNER_TOKEN}" --ephemeral --work _work --labels "${RUNNER_LABEL}" --name "${RUNNER_NAME}" ${RUNNER_FLAGS}
1217
echo Config done
1318
./run.sh
1419
echo Run done
1520

21+
# print status for metrics
1622
STATUS=$(grep -Phors "finish job request for job [0-9a-f\-]+ with result: \K.*" _diag/ | tail -n1)
1723
[ -n "$STATUS" ] && echo CDKGHA JOB DONE "$RUNNER_LABEL" "$STATUS"

src/providers/docker-images/lambda/linux-x64/runner.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22

33
set -e -u -o pipefail
44

5+
# cleanup
6+
find /tmp -mindepth 1 -maxdepth 1 -exec rm -rf '{}' \;
7+
# copy runner code (it needs a writable directory)
58
cp -r /runner /tmp/
69
cd /tmp/runner
7-
mkdir -p /tmp/home
10+
# setup home directory
11+
mkdir /tmp/home
812
export HOME=/tmp/home
913

14+
# start runner
1015
if [ "${RUNNER_VERSION}" = "latest" ]; then RUNNER_FLAGS=""; else RUNNER_FLAGS="--disableupdate"; fi
1116
./config.sh --unattended --url "https://${GITHUB_DOMAIN}/${OWNER}/${REPO}" --token "${RUNNER_TOKEN}" --ephemeral --work _work --labels "${RUNNER_LABEL}" --name "${RUNNER_NAME}" ${RUNNER_FLAGS}
1217
echo Config done
1318
./run.sh
1419
echo Run done
1520

21+
# print status for metrics
1622
STATUS=$(grep -Phors "finish job request for job [0-9a-f\-]+ with result: \K.*" _diag/ | tail -n1)
1723
[ -n "$STATUS" ] && echo CDKGHA JOB DONE "$RUNNER_LABEL" "$STATUS"

test/default.integ.snapshot/github-runners-test.assets.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
}
2828
}
2929
},
30-
"d0f41cb3ffaf59833eb0a5a2bfa51517fd1355417251e3239c73bd07bc11b3ad": {
30+
"62a61b3949f1689cbe3d634ea53cdf3653739068ea82405b3f5daa6af112cd14": {
3131
"source": {
32-
"path": "asset.d0f41cb3ffaf59833eb0a5a2bfa51517fd1355417251e3239c73bd07bc11b3ad",
32+
"path": "asset.62a61b3949f1689cbe3d634ea53cdf3653739068ea82405b3f5daa6af112cd14",
3333
"packaging": "zip"
3434
},
3535
"destinations": {
3636
"current_account-current_region": {
3737
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
38-
"objectKey": "d0f41cb3ffaf59833eb0a5a2bfa51517fd1355417251e3239c73bd07bc11b3ad.zip",
38+
"objectKey": "62a61b3949f1689cbe3d634ea53cdf3653739068ea82405b3f5daa6af112cd14.zip",
3939
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
4040
}
4141
}
@@ -131,15 +131,15 @@
131131
}
132132
}
133133
},
134-
"99e7f30a15606f77d86003b506907ee44f64af10a56007d5d24f8a47b7aed7e0": {
134+
"91095b20a1ffa4f95834cb332fde4bda534f434fcdd9ea642110a24e343c7756": {
135135
"source": {
136-
"path": "asset.99e7f30a15606f77d86003b506907ee44f64af10a56007d5d24f8a47b7aed7e0",
136+
"path": "asset.91095b20a1ffa4f95834cb332fde4bda534f434fcdd9ea642110a24e343c7756",
137137
"packaging": "zip"
138138
},
139139
"destinations": {
140140
"current_account-current_region": {
141141
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
142-
"objectKey": "99e7f30a15606f77d86003b506907ee44f64af10a56007d5d24f8a47b7aed7e0.zip",
142+
"objectKey": "91095b20a1ffa4f95834cb332fde4bda534f434fcdd9ea642110a24e343c7756.zip",
143143
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
144144
}
145145
}
@@ -222,15 +222,15 @@
222222
}
223223
}
224224
},
225-
"e987f0c6f034458f63a2566fd75f8a6f469bc10b58bdf6f19e2a273df6062c63": {
225+
"6e8975ed119d1f7f505caddd0ae58abe25145850dbcf411d35b94dea9090b2e2": {
226226
"source": {
227227
"path": "github-runners-test.template.json",
228228
"packaging": "file"
229229
},
230230
"destinations": {
231231
"current_account-current_region": {
232232
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
233-
"objectKey": "e987f0c6f034458f63a2566fd75f8a6f469bc10b58bdf6f19e2a273df6062c63.json",
233+
"objectKey": "6e8975ed119d1f7f505caddd0ae58abe25145850dbcf411d35b94dea9090b2e2.json",
234234
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
235235
}
236236
}

test/default.integ.snapshot/github-runners-test.template.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@
12841284
{
12851285
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
12861286
},
1287-
"/d0f41cb3ffaf59833eb0a5a2bfa51517fd1355417251e3239c73bd07bc11b3ad.zip"
1287+
"/62a61b3949f1689cbe3d634ea53cdf3653739068ea82405b3f5daa6af112cd14.zip"
12881288
]
12891289
]
12901290
}
@@ -1539,7 +1539,7 @@
15391539
{
15401540
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
15411541
},
1542-
"/d0f41cb3ffaf59833eb0a5a2bfa51517fd1355417251e3239c73bd07bc11b3ad.zip"
1542+
"/62a61b3949f1689cbe3d634ea53cdf3653739068ea82405b3f5daa6af112cd14.zip"
15431543
]
15441544
]
15451545
},
@@ -1658,7 +1658,7 @@
16581658
"ProjectName": {
16591659
"Ref": "LambdaImageBuilderx64CodeBuild67DE14C8"
16601660
},
1661-
"BuildHash": "0fd9c5246493d4f0a256280a2bd764c6"
1661+
"BuildHash": "77b8f5dad1e9729b3b7e6d367706e97d"
16621662
},
16631663
"DependsOn": [
16641664
"buildimagedcc036c8876b451ea2c1552f9e06e9e1LogRetention13129CEB",
@@ -5950,7 +5950,7 @@
59505950
{
59515951
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
59525952
},
5953-
"/99e7f30a15606f77d86003b506907ee44f64af10a56007d5d24f8a47b7aed7e0.zip"
5953+
"/91095b20a1ffa4f95834cb332fde4bda534f434fcdd9ea642110a24e343c7756.zip"
59545954
]
59555955
]
59565956
}
@@ -6205,7 +6205,7 @@
62056205
{
62066206
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
62076207
},
6208-
"/99e7f30a15606f77d86003b506907ee44f64af10a56007d5d24f8a47b7aed7e0.zip"
6208+
"/91095b20a1ffa4f95834cb332fde4bda534f434fcdd9ea642110a24e343c7756.zip"
62096209
]
62106210
]
62116211
},
@@ -6324,7 +6324,7 @@
63246324
"ProjectName": {
63256325
"Ref": "LambdaImageBuilderzCodeBuild73AB6718"
63266326
},
6327-
"BuildHash": "7b0c042d89affec2026f94fad8afde5d"
6327+
"BuildHash": "3709ba4b6f968ba6cb6e9ab467a81291"
63286328
},
63296329
"DependsOn": [
63306330
"buildimagedcc036c8876b451ea2c1552f9e06e9e1LogRetention13129CEB",

test/default.integ.snapshot/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"validateOnSynth": false,
2424
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
2525
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
26-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/e987f0c6f034458f63a2566fd75f8a6f469bc10b58bdf6f19e2a273df6062c63.json",
26+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/6e8975ed119d1f7f505caddd0ae58abe25145850dbcf411d35b94dea9090b2e2.json",
2727
"requiresBootstrapStackVersion": 6,
2828
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2929
"additionalDependencies": [

test/default.integ.snapshot/tree.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@
19181918
{
19191919
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
19201920
},
1921-
"/d0f41cb3ffaf59833eb0a5a2bfa51517fd1355417251e3239c73bd07bc11b3ad.zip"
1921+
"/62a61b3949f1689cbe3d634ea53cdf3653739068ea82405b3f5daa6af112cd14.zip"
19221922
]
19231923
]
19241924
}
@@ -2121,7 +2121,7 @@
21212121
{
21222122
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
21232123
},
2124-
"/d0f41cb3ffaf59833eb0a5a2bfa51517fd1355417251e3239c73bd07bc11b3ad.zip"
2124+
"/62a61b3949f1689cbe3d634ea53cdf3653739068ea82405b3f5daa6af112cd14.zip"
21252125
]
21262126
]
21272127
},
@@ -8036,7 +8036,7 @@
80368036
{
80378037
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
80388038
},
8039-
"/99e7f30a15606f77d86003b506907ee44f64af10a56007d5d24f8a47b7aed7e0.zip"
8039+
"/91095b20a1ffa4f95834cb332fde4bda534f434fcdd9ea642110a24e343c7756.zip"
80408040
]
80418041
]
80428042
}
@@ -8239,7 +8239,7 @@
82398239
{
82408240
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
82418241
},
8242-
"/99e7f30a15606f77d86003b506907ee44f64af10a56007d5d24f8a47b7aed7e0.zip"
8242+
"/91095b20a1ffa4f95834cb332fde4bda534f434fcdd9ea642110a24e343c7756.zip"
82438243
]
82448244
]
82458245
},

0 commit comments

Comments
 (0)