Skip to content

Commit 468b83b

Browse files
authored
ci: samcli with qemu+vz (runfinch#354)
Some fixes to workflows following issues in emulation for cross-arch images and updates in SAMcli. Signed-off-by: ayush-panta <ayushkp@amazon.com>
1 parent 4891207 commit 468b83b

File tree

11 files changed

+138
-51
lines changed

11 files changed

+138
-51
lines changed

.github/workflows/finch-vm-test.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ jobs:
2121
- name: Clean macOS runner workspace
2222
run: |
2323
rm -rf ${{ github.workspace }}/*
24+
# Clean up any leftover Finch VM state
25+
su ec2-user -c 'finch vm remove -f' || true
26+
sudo pkill -f socket_vmnet || true
27+
sudo rm -rf /private/var/run/finch-lima/*.sock || true
28+
sudo rm -rf /Applications/Finch/lima/data/finch/_cache || true
29+
# Clean up containers and images via Finch CLI
30+
su ec2-user -c 'finch system prune -f' || true
31+
2432
- name: Configure Git for ec2-user
2533
run: |
2634
git config --global --add safe.directory "*"
@@ -77,12 +85,18 @@ jobs:
7785
- name: Checkout finch-daemon PR
7886
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
7987
with:
80-
ref: ${{ github.head_ref }}
88+
ref: ${{ github.event.pull_request.head.sha || 'main' }}
89+
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
8190
fetch-depth: 0
8291
persist-credentials: false
8392
submodules: recursive
8493
path: finch-daemon-pr
8594

95+
- name: Check Finch configuration
96+
run: |
97+
echo "Config (finch.yaml):"
98+
su ec2-user -c 'cat ~/.finch/finch.yaml || echo "No config file found"'
99+
86100
- name: Build and setup Finch VM
87101
run: ./finch-daemon-pr/scripts/build-and-setup-finch-vm.sh
88102

.github/workflows/samcli-direct.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: start-api
3535
env:
3636
AWS_DEFAULT_REGION: "${{ secrets.REGION }}"
37-
DOCKER_HOST: unix:///run/finch.sock
37+
DOCKER_HOST: unix:///var/run/finch.sock
3838
DOCKER_CONFIG: $HOME/.finch
3939
BY_CANARY: true # allows full testing
4040
SAM_CLI_DEV: 1
@@ -63,6 +63,7 @@ jobs:
6363
- name: Checkout finch-daemon
6464
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
6565
with:
66+
ref: ${{ github.head_ref }}
6667
fetch-depth: 0
6768
persist-credentials: false
6869
submodules: recursive
@@ -93,12 +94,19 @@ jobs:
9394
sudo bin/finch-daemon --debug --socket-owner $UID 2>&1 | tee finch-daemon.log &
9495
sleep 10
9596
97+
- name: Get latest SAM CLI tag
98+
id: sam-tag
99+
run: |
100+
TAG=$(curl -s https://api.github.com/repos/aws/aws-sam-cli/releases/latest | jq -r .tag_name)
101+
echo "tag=$TAG" >> $GITHUB_OUTPUT
102+
96103
- name: Checkout SAM CLI
97104
uses: actions/checkout@v4
98105
with:
99106
repository: aws/aws-sam-cli
100107
submodules: recursive
101108
path: aws-sam-cli
109+
ref: ${{ steps.sam-tag.outputs.tag }}
102110

103111
- name: Set up SAM CLI from source
104112
working-directory: aws-sam-cli

.github/workflows/samcli-vm.yaml

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ jobs:
3434
sudo rm -rf /private/var/run/finch-lima/*.sock || true
3535
sudo rm -rf /Applications/Finch/lima/data/finch/_cache || true
3636
# Clean up containers and images via Finch CLI
37-
su ec2-user -c 'finch container prune -f' || true
38-
su ec2-user -c 'finch image prune -a -f' || true
37+
su ec2-user -c 'finch system prune -f' || true
3938
4039
- name: Configure Git for ec2-user
4140
run: |
@@ -111,9 +110,44 @@ jobs:
111110
submodules: recursive
112111
path: finch-daemon-pr
113112

113+
- name: Configure Finch
114+
run: |
115+
echo "Original config:"
116+
su ec2-user -c 'cat ~/.finch/finch.yaml || echo "No config file found"'
117+
echo "Configuring Finch to use QEMU+VZ"
118+
su ec2-user -c 'yq eval ".vmType = \"vz\"" -i ~/.finch/finch.yaml'
119+
su ec2-user -c 'yq eval ".rosetta = false" -i ~/.finch/finch.yaml'
120+
echo "Updated config:"
121+
su ec2-user -c 'cat ~/.finch/finch.yaml'
122+
114123
- name: Build and setup Finch VM
115124
run: ./finch-daemon-pr/scripts/build-and-setup-finch-vm.sh
116125

126+
- name: Verify Finch socket
127+
run: |
128+
# Test socket connectivity
129+
if su ec2-user -c 'curl -s --unix-socket /Applications/Finch/lima/data/finch/sock/finch.sock http://localhost/version' > /dev/null; then
130+
echo "✓ Finch daemon is accessible"
131+
else
132+
echo "✗ Finch daemon connection failed"
133+
ls -la /Applications/Finch/lima/data/finch/sock/ || echo "Socket directory not found"
134+
exit 1
135+
fi
136+
137+
- name: Ensure Docker is not available (force Finch usage)
138+
run: |
139+
echo "Ensuring Docker is not accessible to force SAM CLI to use Finch..."
140+
# Remove docker binaries from PATH
141+
sudo rm -f /usr/local/bin/docker /opt/homebrew/bin/docker || true
142+
# Verify docker is not accessible
143+
if su ec2-user -c 'which docker' > /dev/null 2>&1; then
144+
echo "WARNING: Docker is still accessible"
145+
su ec2-user -c 'which docker'
146+
else
147+
echo "SUCCESS: Docker is not accessible - SAM CLI will use Finch"
148+
fi
149+
shell: bash
150+
117151
- name: Configure AWS credentials
118152
uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df # v4.2.1
119153
with:
@@ -122,23 +156,19 @@ jobs:
122156
aws-region: ${{ secrets.REGION }}
123157
role-duration-seconds: 14400
124158

125-
- name: Install Docker CLI for SAM CLI compatibility
159+
- name: Get latest SAM CLI tag
160+
id: sam-tag
126161
run: |
127-
echo "Checking Docker CLI installation..."
128-
if ! su ec2-user -c 'which docker' > /dev/null 2>&1; then
129-
echo "Installing Docker CLI..."
130-
su ec2-user -c 'source /Users/ec2-user/.brewrc && brew install --formula docker'
131-
else
132-
echo "Docker CLI already installed"
133-
fi
134-
shell: bash
162+
TAG=$(curl -s https://api.github.com/repos/aws/aws-sam-cli/releases/latest | jq -r .tag_name)
163+
echo "tag=$TAG" >> $GITHUB_OUTPUT
135164
136165
- name: Checkout SAM CLI
137166
uses: actions/checkout@v4
138167
with:
139168
repository: aws/aws-sam-cli
140169
submodules: recursive
141170
path: aws-sam-cli
171+
ref: ${{ steps.sam-tag.outputs.tag }}
142172

143173
- name: Set up SAM CLI from source
144174
run: |
@@ -154,33 +184,26 @@ jobs:
154184
shell: bash
155185

156186
- name: Run unit tests
157-
timeout-minutes: 30
158187
run: ./finch-daemon-pr/scripts/samcli-vm/run-unit-tests.sh
159188

160-
- name: Patch SAM CLI for Docker image cleanup
161-
run: |
162-
# Apply patch to handle ImageNotFound exceptions for all Docker tests
163-
su ec2-user -c 'cd /Users/ec2-user/aws-sam-cli && patch -p1 tests/integration/local/invoke/test_integrations_cli.py < ${{ github.workspace }}/finch-daemon-pr/scripts/samcli-vm/invoke-teardown.patch'
164-
shell: bash
165-
166189
- name: Run invoke tests
167190
timeout-minutes: 40
168191
run: ./finch-daemon-pr/scripts/samcli-vm/run-invoke-tests.sh
169192

170193
- name: Run start-api tests
171-
timeout-minutes: 70
194+
timeout-minutes: 60
172195
run: ./finch-daemon-pr/scripts/samcli-vm/run-start-api-tests.sh
173196

174197
- name: Run sync tests
175198
timeout-minutes: 20
176199
run: ./finch-daemon-pr/scripts/samcli-vm/run-sync-tests.sh
177200

178201
- name: Run package tests
179-
timeout-minutes: 10
202+
timeout-minutes: 5
180203
run: ./finch-daemon-pr/scripts/samcli-vm/run-package-tests.sh
181204

182205
- name: Run start-lambda tests
183-
timeout-minutes: 30
206+
timeout-minutes: 20
184207
run: ./finch-daemon-pr/scripts/samcli-vm/run-start-lambda-tests.sh
185208

186209
# ensuring resources are clean post-test

scripts/samcli-direct/run-invoke-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e
33

44
cd aws-sam-cli
55

6-
python -m pytest tests/integration/local/invoke -k 'not Terraform' -v --tb=short > invoke_output.txt 2>&1 || true
6+
python -m pytest tests/integration/local/invoke -k 'not Terraform' -v --tb=short 2>&1 | tee invoke_output.txt || true
77

88
# test_invoke_with_error_during_image_build: Build error message differs from expected.
99
# test_invoke_with_timeout_set_X_TimeoutFunction: Returns timeout message instead of empty string,

scripts/samcli-direct/run-start-api-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44
cd aws-sam-cli
55

66
ulimit -n 65536
7-
python -m pytest tests/integration/local/start_api -k 'not Terraform' -v --tb=short > start_api_output.txt 2>&1 || true
7+
python -m pytest tests/integration/local/start_api -k 'not Terraform' -v --tb=short 2>&1 | tee start_api_output.txt || true
88

99
# test_can_invoke_lambda_layer_successfully: Uses random port, fails occasionally.
1010
# Only 1 test of 386 total, acceptable failure rate.

scripts/samcli-direct/run-unit-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44
cd aws-sam-cli
55

66
ulimit -n 65536
7-
make test > unit_test_output.txt 2>&1 || true
7+
make test 2>&1 | tee unit_test_output.txt || true
88

99
echo ""
1010
echo "=== PASSES ==="

scripts/samcli-vm/run-package-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e
33

44
echo "=== PACKAGE TESTS - Started at $(date) ==="
55
touch /tmp/package_test_output.txt
6-
chown ec2-user:staff /tmp/package_output.txt
6+
chown ec2-user:staff /tmp/package_test_output.txt
77
su ec2-user -c "
88
cd /Users/ec2-user/aws-sam-cli && \
99
export PATH='/Users/ec2-user/Library/Python/$PYTHON_VERSION/bin:$PATH' && \

scripts/samcli-vm/run-start-api-tests.sh

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,9 @@ set -e
33

44
echo "=== START-API TESTS - Started at $(date) ==="
55
touch /tmp/start_api_test_output.txt
6-
chown ec2-user:staff /tmp/start_api_output.txt
6+
chown ec2-user:staff /tmp/start_api_test_output.txt
77

8-
# Start background monitor to show progress
9-
(
10-
while true; do
11-
sleep 30
12-
echo "[$(date)] Progress check - Last 20 lines:"
13-
tail -20 /tmp/start_api_test_output.txt 2>/dev/null || echo "No output yet"
14-
echo "---"
15-
done
16-
) &
17-
MONITOR_PID=$!
18-
19-
# Run tests (output to file only, show progress via monitor)
8+
# Run tests with live output
209
su ec2-user -c "
2110
cd /Users/ec2-user/aws-sam-cli && \
2211
export PATH='/Users/ec2-user/Library/Python/$PYTHON_VERSION/bin:$PATH' && \
@@ -27,10 +16,7 @@ su ec2-user -c "
2716
SAM_CLI_DEV='$SAM_CLI_DEV' \
2817
SAM_CLI_TELEMETRY='$SAM_CLI_TELEMETRY' \
2918
'$PYTHON_BINARY' -m pytest tests/integration/local/start_api -k 'not Terraform' -v --tb=short
30-
" > /tmp/start_api_test_output.txt 2>&1 || true
31-
32-
# Stop monitor
33-
kill $MONITOR_PID 2>/dev/null || true
19+
" 2>&1 | tee /tmp/start_api_test_output.txt || true
3420
echo "=== START-API TESTS - Finished at $(date) ==="
3521

3622
# test_can_invoke_lambda_layer_successfully: Uses random port, fails occasionally.

scripts/samcli-vm/run-start-lambda-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e
33

44
echo "=== START-LAMBDA TESTS - Started at $(date) ==="
55
touch /tmp/start_lambda_test_output.txt
6-
chown ec2-user:staff /tmp/start_lambda_output.txt
6+
chown ec2-user:staff /tmp/start_lambda_test_output.txt
77
su ec2-user -c "
88
cd /Users/ec2-user/aws-sam-cli && \
99
export PATH='/Users/ec2-user/Library/Python/$PYTHON_VERSION/bin:$PATH' && \

scripts/samcli-vm/run-unit-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ su ec2-user -c "
1616
SAM_CLI_DEV='$SAM_CLI_DEV' \
1717
SAM_CLI_TELEMETRY='$SAM_CLI_TELEMETRY' \
1818
make test
19-
" > /tmp/unit_test_output.txt 2>&1 || true
19+
" 2>&1 | tee /tmp/unit_test_output.txt || true
2020

2121
echo ""
2222
echo "=== PASSES ==="

0 commit comments

Comments
 (0)