Skip to content

Commit 3345b57

Browse files
goruhaJonathan Chan
andauthored
Use atmos instead of makefile (#102)
* Use atmos instead of makefile * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * updating README, executing tests * Debugging test * adding more debug * Fix typo * testing if it is a timing race condition issue * making the test more resilient and wait until the service is up * debugging ssh permission denied error * attempt to make bastion test container persistent * removing extraneous sleep * cleaning up code, making sure everything is happy --------- Co-authored-by: Jonathan Chan <jonathan@rentwayhome.com>
1 parent 7863d5a commit 3345b57

File tree

8 files changed

+73
-12
lines changed

8 files changed

+73
-12
lines changed

.atmos/cache.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
installation_id: f67dcc7a-7060-475c-8933-19f2620f819b
2+
last_checked: 0
3+
telemetry_disclosure_shown: false

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ test:
3434

3535
cleantest:
3636
cd test && docker compose down
37+
38+
readme:
39+
@atmos readme
40+
41+
readme/build:
42+
@atmos readme

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
<!-- markdownlint-disable -->
44
<a href="https://cpco.io/homepage"><img src="https://github.com/cloudposse/bastion/blob/main/.github/banner.png?raw=true" alt="Project Banner"/></a><br/>
5-
<p align="right">
6-
<a href="https://github.com/cloudposse/bastion/releases/latest"><img src="https://img.shields.io/github/release/cloudposse/bastion.svg" alt="Latest Release"/></a><a href="https://github.com/cloudposse/bastion/actions/workflows/integration-tests.yml"><img src="https://github.com/cloudposse/bastion/actions/workflows/integration-tests.yml/badge.svg" alt="Build & Test Status"/></a><a href="https://slack.cloudposse.com"><img src="https://slack.cloudposse.com/badge.svg" alt="Slack Community"/></a></p>
5+
6+
7+
<p align="right"><a href="https://github.com/cloudposse/bastion/releases/latest"><img src="https://img.shields.io/github/release/cloudposse/bastion.svg" alt="Latest Release"/></a><a href="https://github.com/cloudposse/bastion/actions/workflows/integration-tests.yml"><img src="https://github.com/cloudposse/bastion/actions/workflows/integration-tests.yml/badge.svg" alt="Build & Test Status"/></a><a href="https://slack.cloudposse.com"><img src="https://slack.cloudposse.com/badge.svg" alt="Slack Community"/></a>
8+
9+
</p>
710
<!-- markdownlint-restore -->
811

912
<!--
@@ -15,8 +18,8 @@
1518
**
1619
** This file was automatically generated by the `cloudposse/build-harness`.
1720
** 1) Make all changes to `README.yaml`
18-
** 2) Run `make init` (you only need to do this once)
19-
** 3) Run`make readme` to rebuild this file.
21+
** 2) Install [atmos](https://atmos.tools/install/) (you only need to do this once)
22+
** 3) Run`atmos readme` to rebuild this file.
2023
**
2124
** (We maintain HUNDREDS of open source projects. This is how we maintain our sanity.)
2225
**
@@ -207,6 +210,10 @@ The first time you connect, you'll be asked to setup your MFA device. Subsequent
207210

208211

209212

213+
214+
215+
216+
210217
## ✨ Contributing
211218

212219
This project is under active development, and we encourage contributions from our community.

atmos.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import:
2+
- https://raw.githubusercontent.com/cloudposse/.github/refs/heads/main/.github/atmos/github-action.yaml

test/docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ services:
1313
MFA_PROVIDER: "google-authenticator"
1414
healthcheck:
1515
test: ["CMD", "nc", "-z", "localhost", "22"]
16-
interval: 10s
17-
timeout: 5s
18-
retries: 3
16+
interval: 20s
17+
timeout: 10s
18+
retries: 10
1919

2020
test:
2121
build: "."
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
#!/bin/sh
22
ping -c 1 -w 5 bastion > /dev/null
33

4+
# Wait for SSH to be available on port 22
5+
max_attempts=10
6+
attempt=1
7+
while [ $attempt -le $max_attempts ]; do
8+
if nc -z -w 2 bastion 22 2>/dev/null; then
9+
break
10+
fi
11+
if [ $attempt -eq $max_attempts ]; then
12+
echo "Error: SSH port 22 not available on bastion after $max_attempts attempts" >&2
13+
exit 1
14+
fi
15+
attempt=$((attempt + 1))
16+
sleep 1
17+
done
18+
419
# Add -vv for debugging.
520
sshpass \
621
-P 'Verification code:' \
722
-f ./code \
823
ssh bastion@bastion \
24+
-i /root/.ssh/id_rsa \
925
-o StrictHostKeyChecking=no \
26+
-o IdentitiesOnly=yes \
1027
-- echo 'this is a test.'
28+

test/fixtures/client_scripts/sshrc_kill_test.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/bin/sh
2-
ping -c 1 -w 5 bastion
2+
ping -c 1 -w 5 bastion > /dev/null
3+
4+
# Wait for SSH to be available on port 22
5+
max_attempts=10
6+
attempt=1
7+
while [ $attempt -le $max_attempts ]; do
8+
if nc -z -w 2 bastion 22 2>/dev/null; then
9+
break
10+
fi
11+
if [ $attempt -eq $max_attempts ]; then
12+
echo "Error: SSH port 22 not available on bastion after $max_attempts attempts" >&2
13+
exit 1
14+
fi
15+
attempt=$((attempt + 1))
16+
sleep 1
17+
done
18+
319

420
# Add -vv for debugging.
521
sshpass \

test/test.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ green=`tput setaf 2`
77
reset=`tput sgr0`
88

99
# Generating temp keys
10+
echo "Generating test ssh keys..."
1011
rm -rf fixtures/auth/ida_rsa*
1112
ssh-keygen -q -f fixtures/auth/ida_rsa -N ""
1213
chmod 600 fixtures/auth/ida_rsa
14+
echo "ssh keys generated."
1315

1416
docker compose down
15-
docker compose up -d --build bastion
17+
docker compose up --wait -d --build bastion
1618
docker compose build test
1719

1820
# wait until bastion is up
@@ -22,7 +24,6 @@ echo "Bastion sshd service started."
2224

2325
docker compose exec bastion /scripts/setup.sh
2426

25-
2627
# greping for the first line of the left alignment square in the generated QR Code
2728
docker compose exec bastion /scripts/google_auth_qr_code_generator_test.sh |grep -F " " > /dev/null
2829

@@ -36,12 +37,17 @@ else
3637
fi
3738

3839

39-
docker compose run --remove-orphans test /scripts/google_auth_test.sh
40+
# Ensure bastion is running before running test
41+
docker compose up -d --no-recreate bastion
42+
43+
docker compose run --no-deps --rm test /scripts/google_auth_test.sh
4044

4145
retVal=$?
4246

4347
if [ $retVal -ne 0 ]; then
4448
echo "${red}* Google Authenticator/SSH Test Failed${reset}"
49+
echo "Logs from bastion (executed before the failure):"
50+
docker logs test-bastion-1
4551
exit $retVal
4652
else
4753
echo "${green}* Google Authenticator/SSH Test Succeeded${reset}"
@@ -70,7 +76,10 @@ else
7076
echo "${green}* Slack API Connection Test Succeeded${reset}"
7177
fi
7278

73-
export SSHRC_KILL_OUTPUT=`docker compose run --remove-orphans test /scripts/sshrc_kill_test.sh`
79+
# Ensure bastion is running before running test
80+
docker compose up -d --no-recreate bastion
81+
82+
export SSHRC_KILL_OUTPUT=`docker compose run --no-deps --rm test /scripts/sshrc_kill_test.sh`
7483

7584
if [[ "$SSHRC_KILL_OUTPUT" == *"this output should never print"* ]]; then
7685
echo "${red}* Failure to quit after non-zero exit code in sshrc${reset}"

0 commit comments

Comments
 (0)