Skip to content

ci: add GitHub Actions workflow for container IP setup #1

ci: add GitHub Actions workflow for container IP setup

ci: add GitHub Actions workflow for container IP setup #1

Workflow file for this run

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 }}"