Skip to content

Commit

Permalink
ci: add GitHub Actions workflow for container IP setup
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
appleboy committed Jun 6, 2024
1 parent 90639f8 commit a369394
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ipv6.yaml
Original file line number Diff line number Diff line change
@@ -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 }}"

0 comments on commit a369394

Please sign in to comment.