From a36939442021bf1a27dc982a8330f3f0c183561b Mon Sep 17 00:00:00 2001 From: appleboy Date: Thu, 6 Jun 2024 21:27:44 +0800 Subject: [PATCH] ci: add GitHub Actions workflow for container IP setup - Add a new GitHub Actions workflow for container IP example - Configure the workflow to run on push events - Set up a job to run on the latest Ubuntu with a Golang container - Enable IPv6 in the container - Add steps to check out the repository, set up Docker, and retrieve the container's IP address - Set the container IP as an environment variable and use it in a subsequent step Signed-off-by: appleboy --- .github/workflows/ipv6.yaml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/ipv6.yaml diff --git a/.github/workflows/ipv6.yaml b/.github/workflows/ipv6.yaml new file mode 100644 index 0000000..66d9dea --- /dev/null +++ b/.github/workflows/ipv6.yaml @@ -0,0 +1,29 @@ +name: Container IP Example + +on: [push] + +jobs: + testing: + runs-on: ubuntu-latest + container: + image: golang:1.21-alpine + options: --sysctl net.ipv6.conf.all.disable_ipv6=0 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker + run: | + # Get the container ID of the current container + CONTAINER_ID=$(cat /proc/self/cgroup | grep 'docker' | sed 's/^.*\///' | tail -n 1) + echo "Container ID: $CONTAINER_ID" + + # Get the container IP address using docker inspect + CONTAINER_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CONTAINER_ID) + echo "Container IP: $CONTAINER_IP" + + # Set the container IP as an environment variable + echo "CONTAINER_IP=$CONTAINER_IP" >> $GITHUB_ENV + + - name: Use Container IP + run: echo "The container IP is ${{ env.CONTAINER_IP }}"