diff --git a/.github/workflows/dev-cd.yml b/.github/workflows/dev-cd.yml index 7942d0fd0..714edfc4d 100644 --- a/.github/workflows/dev-cd.yml +++ b/.github/workflows/dev-cd.yml @@ -194,8 +194,17 @@ jobs: if [ "$UPSTREAM_PORT" = "8080" ]; then NEW_MGMT_PORT=8081; else NEW_MGMT_PORT=9081; fi + PRIVATE_IP=$(ssh -i deploy_key.pem -o StrictHostKeyChecking=no \ + "${{ secrets.DEV_USERNAME }}@${{ secrets.DEV_HOST }}" \ + "TOKEN=\$(curl -sf -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600') && curl -sf -H \"X-aws-ec2-metadata-token: \$TOKEN\" http://169.254.169.254/latest/meta-data/local-ipv4") + + if [ -z "$PRIVATE_IP" ]; then + echo "Failed to retrieve private IP" >&2 + exit 1 + fi + ssh -i monitoring_key.pem -o StrictHostKeyChecking=no \ "${{ secrets.MONITORING_USERNAME }}@${{ secrets.MONITORING_HOST }}" \ - "echo '[{\"targets\":[\"${{ secrets.DEV_HOST }}:${NEW_MGMT_PORT}\"]}]' \ + "echo '[{\"targets\":[\"${PRIVATE_IP}:${NEW_MGMT_PORT}\"]}]' \ | tee ~/solid-connection-monitor/prometheus/targets/stage.json > /dev/null \ - && echo 'Prometheus target updated: ${{ secrets.DEV_HOST }}:${NEW_MGMT_PORT}'" + && echo 'Prometheus target updated: ${PRIVATE_IP}:${NEW_MGMT_PORT}'" diff --git a/.github/workflows/prod-cd.yml b/.github/workflows/prod-cd.yml index 03025ab5f..1e60d0db4 100644 --- a/.github/workflows/prod-cd.yml +++ b/.github/workflows/prod-cd.yml @@ -205,8 +205,17 @@ jobs: if [ "$UPSTREAM_PORT" = "8080" ]; then NEW_MGMT_PORT=8081; else NEW_MGMT_PORT=9081; fi + PRIVATE_IP=$(ssh -i deploy_key.pem -o StrictHostKeyChecking=no \ + "${{ secrets.USERNAME }}@${{ secrets.HOST }}" \ + "TOKEN=\$(curl -sf -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600') && curl -sf -H \"X-aws-ec2-metadata-token: \$TOKEN\" http://169.254.169.254/latest/meta-data/local-ipv4") + + if [ -z "$PRIVATE_IP" ]; then + echo "Failed to retrieve private IP" >&2 + exit 1 + fi + ssh -i monitoring_key.pem -o StrictHostKeyChecking=no \ "${{ secrets.MONITORING_USERNAME }}@${{ secrets.MONITORING_HOST }}" \ - "echo '[{\"targets\":[\"${{ secrets.HOST }}:${NEW_MGMT_PORT}\"]}]' \ + "echo '[{\"targets\":[\"${PRIVATE_IP}:${NEW_MGMT_PORT}\"]}]' \ | tee ~/solid-connection-monitor/prometheus/targets/prod.json > /dev/null \ - && echo 'Prometheus target updated: ${{ secrets.HOST }}:${NEW_MGMT_PORT}'" + && echo 'Prometheus target updated: ${PRIVATE_IP}:${NEW_MGMT_PORT}'"