Skip to content

Commit

Permalink
changes entrypoint of packetrusher and adds image info automation (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
avrodriguezgrad authored Mar 4, 2024
1 parent 4a87fe2 commit fbc9535
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion images/packetrusher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ To be able to run this image, you have to:
- Run the container with cap_add=all
- Run the container with privileged=true

The image uses the basic mode of PacketRusher: 1 gNB and 1 UE.
The image receives the mode of PacketRusher (ue, multi-ue...) as a command. entrypoint can be seen to understand how it works.

You can change the config file using env variables.
8 changes: 7 additions & 1 deletion images/packetrusher/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

set -ex

if [ $# -lt 1 ]
then
echo "Usage : $0 [ue | multi-ue -n N]"
exit
fi

if [[ -z "${GNB_NGAP_ADDR}" ]] ; then
export GNB_NGAP_ADDR=$(ip addr show $GNB_NGAP_DEV | grep -Po 'inet \K[\d.]+')
fi
Expand All @@ -16,4 +22,4 @@ fi

envsubst < config/config.yml > config.yml

./packetrusher --config config.yml ue
./packetrusher --config config.yml $@
3 changes: 3 additions & 0 deletions images/packetrusher/image_info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IMAGE_TAG=97f9f0c
#comma separated list of platforms. If empty, image will not be multiarch.
PLATFORMS=
36 changes: 36 additions & 0 deletions images/packetrusher/update_current_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#/bin/bash

REMOTE_REPO_URL="https://api.github.com/repos/HewlettPackard/PacketRusher/commits?sha=main"

GH="https://api.github.*"
GL="https://gitlab.*"

# Fetch the last version available on the remote repository
if [[ ${REMOTE_REPO_URL} =~ ${GH} ]] ; then
CURRENT_TAG=$( curl -sSL ${REMOTE_REPO_URL} | jq -r '.[0].sha' | sed 's/^\(.\{7\}\).*/\1/' )
# sed explanation
# -n dont print anything
# /v[0-9.]\+/h; every match with "v[0-9.]\+" gets stored on hold
# $g; replace contents of pattern space with hold space, adds last match as last line to buffer
# s//\1/; replace pattern, removes everything around version
# $p only last line is printed
elif [[ ${REMOTE_REPO_URL} =~ ${GL} ]] ; then
CURRENT_TAG=$( curl -sSL ${REMOTE_REPO_URL} | jq -r '.[0].sha' | sed 's/^\(.\{7\}\).*/\1/' )
else
echo "Error Reading URL"
exit 1
fi

# Load IMAGE_TAG
[[ -f image_info.sh ]] && source image_info.sh || exit 1


# Compare CURRENT_TAG with saved IMAGE_TAG
[[ ${CURRENT_TAG} == ${IMAGE_TAG} ]] || {
echo "Updating old TAG ${IMAGE_TAG} with new TAG ${CURRENT_TAG}"
sed -i "/IMAGE_TAG/s/=.*$/=${CURRENT_TAG}/" image_info.sh
exit 0
}

# Fail otherwise
exit 1

0 comments on commit fbc9535

Please sign in to comment.