Skip to content

Commit

Permalink
Remove machine from internet network and allocate public ip on-demand
Browse files Browse the repository at this point in the history
  • Loading branch information
robertvolkmann committed Jan 9, 2025
1 parent c9ae490 commit b91d5ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ _privatenet: env

.PHONY: machine
machine: _privatenet
docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl machine create --description test --name test --hostname test --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image $(MACHINE_OS) --size v1-small-x86 --userdata "@/tmp/ignition.json" --networks internet-mini-lab,$(shell docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}')
docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl machine create --description test --name test --hostname test --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image $(MACHINE_OS) --size v1-small-x86 --userdata "@/tmp/ignition.json" --networks $(shell docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}')

.PHONY: firewall
firewall: _privatenet
docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl firewall create --description fw --name fw --hostname fw --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image firewall-ubuntu-3.0 --size v1-small-x86 --userdata "@/tmp/ignition.json" --firewall-rules-file=/tmp/rules.yaml --networks internet-mini-lab,$(shell docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}')

.PHONY: public-ip
public-ip:
@docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network ip list --name test --network internet-mini-lab -o template --template "{{ .ipaddress }}"
@docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network ip create --name test --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 -o template --template "{{ .ipaddress }}"

.PHONY: ls
ls: env
Expand Down Expand Up @@ -249,7 +249,6 @@ ssh-machine:

.PHONY: test-connectivity-to-external-service
test-connectivity-to-external-service:
@echo "Test connectivity to container external_service..."
@for i in $$(seq 1 $(MAX_RETRIES)); do \
if $(MAKE) ssh-machine COMMAND="sudo curl --connect-timeout 1 --fail --silent http://203.0.113.10" > /dev/null 2>&1; then \
echo "Connected successfully"; \
Expand Down
19 changes: 18 additions & 1 deletion test/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ echo "Test connectivity to outside"
make test-connectivity-to-external-service

echo "Test connectivity from outside"
ssh -F files/ssh/config metal@$(make public-ip) -C exit
public_ip=$(make public-ip)
make ssh-machine COMMAND="sudo ip addr add ${public_ip}/32 dev lo"

for i in $(seq 1 10); do
if ssh -F files/ssh/config metal@"${public_ip}" -C exit > /dev/null 2>&1; then
echo "Connected successfully"
break
else
echo "Connection failed"
if [ $i -lt 10 ]; then
echo "Retrying in 1 second..."
sleep 1
else
echo "Max retries reached"
exit 1
fi
fi
done

echo "Successfully started mini-lab"

0 comments on commit b91d5ca

Please sign in to comment.