Skip to content

Commit

Permalink
Update runner-init.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
edewata committed Aug 27, 2024
1 parent a576bf1 commit 308a87a
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 70 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/build-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ jobs:

- name: Set up JSS container
run: |
tests/bin/runner-init.sh jss
env:
IMAGE: jss-builder
HOSTNAME: jss.example.com
tests/bin/runner-init.sh \
--image=jss-builder \
--hostname=jss.example.com \
jss
- name: Build with CMake
run: |
Expand Down Expand Up @@ -187,10 +187,10 @@ jobs:

- name: Set up JSS container
run: |
tests/bin/runner-init.sh jss
env:
IMAGE: jss-builder
HOSTNAME: jss.example.com
tests/bin/runner-init.sh \
--image=jss-builder \
--hostname=jss.example.com \
jss
- name: Install RPMs
run: |
Expand Down Expand Up @@ -272,10 +272,10 @@ jobs:

- name: Set up JSS container
run: |
tests/bin/runner-init.sh jss
env:
IMAGE: jss-builder
HOSTNAME: jss.example.com
tests/bin/runner-init.sh \
--image=jss-builder \
--hostname=jss.example.com \
jss
- name: Install build dependencies
run: |
Expand Down
18 changes: 8 additions & 10 deletions .github/workflows/external-application-connection-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ jobs:

- name: Set up JSS container
run: |
tests/bin/runner-init.sh jss
env:
IMAGE: jss-builder
HOSTNAME: jss.example.com

- name: Connect JSS container to network
run: docker network connect example jss --alias jss.example.com
tests/bin/runner-init.sh \
--image=jss-builder \
--hostname=jss.example.com \
--network=example \
--network-alias=jss.example.com \
jss
- name: Set up jss and database drivers
run: |
Expand Down Expand Up @@ -130,15 +129,14 @@ jobs:
run: |
docker run -d --name postgresql \
--hostname postgresql.example.com \
--network example \
--network-alias postgresql.example.com \
-e POSTGRES_PASSWORD=mysecretpassword \
-e POSTGRES_USER=jss \
postgres-ssl -c ssl=on \
-c ssl_cert_file=/var/lib/postgresql/server.crt \
-c ssl_key_file=/var/lib/postgresql/server.key
- name: Connect DB container to network
run: docker network connect example postgresql --alias postgresql.example.com

- name: Build the tests
run: docker exec jss ./build.sh --work-dir=./build

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pkcs11-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ jobs:

- name: Set up JSS container
run: |
tests/bin/runner-init.sh jss
env:
IMAGE: jss-builder
HOSTNAME: jss.example.com
tests/bin/runner-init.sh \
--image=jss-builder \
--hostname=jss.example.com \
jss
- name: Check PKCS11 constants
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pki-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:

- name: Set up JSS container
run: |
tests/bin/runner-init.sh pki
env:
HOSTNAME: pki.example.com
tests/bin/runner-init.sh \
--hostname=pki.example.com \
pki
- name: Import LDAP SDK packages
run: |
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/pki-ca-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ jobs:

- name: Set up server container
run: |
tests/bin/runner-init.sh pki
env:
HOSTNAME: pki.example.com
tests/bin/runner-init.sh \
--hostname=pki.example.com \
pki
- name: Connect server container to network
run: docker network connect example pki --alias pki.example.com --alias server.example.com
docker network connect example pki \
--alias pki.example.com \
--alias server.example.com
- name: Set up client container
run: |
tests/bin/runner-init.sh client
env:
HOSTNAME: client.example.com

- name: Connect client container to network
run: docker network connect example client --alias client.example.com
tests/bin/runner-init.sh \
--hostname=client.example.com \
--network=example \
--network-alias=client.example.com \
client
- name: Import LDAP SDK packages
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pki-tools-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:

- name: Set up JSS container
run: |
tests/bin/runner-init.sh pki
env:
HOSTNAME: pki.example.com
tests/bin/runner-init.sh \
--hostname=pki.example.com \
pki
- name: Import LDAP SDK packages
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pki-tps-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:

- name: Set up JSS container
run: |
tests/bin/runner-init.sh pki
env:
HOSTNAME: pki.example.com
tests/bin/runner-init.sh \
--hostname=pki.example.com \
pki
- name: Import LDAP SDK packages
run: |
Expand Down
22 changes: 10 additions & 12 deletions .github/workflows/tomcat-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ jobs:

- name: Set up JSS container
run: |
tests/bin/runner-init.sh server
env:
HOSTNAME: server.example.com

- name: Connect server container to network
run: docker network connect example server --alias server.example.com
tests/bin/runner-init.sh \
--hostname=server.example.com \
--network=example \
--network-alias=server.example.com \
server
- name: Import LDAP SDK packages
run: |
Expand Down Expand Up @@ -129,12 +128,11 @@ jobs:
- name: Set up client container
run: |
tests/bin/runner-init.sh client
env:
HOSTNAME: client.example.com

- name: Connect client container to network
run: docker network connect example client --alias client.example.com
tests/bin/runner-init.sh \
--hostname=client.example.com \
--network=example \
--network-alias=client.example.com \
client
- name: Install dependencies
run: docker exec client dnf install -y sslscan
Expand Down
126 changes: 114 additions & 12 deletions tests/bin/runner-init.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,83 @@
#!/bin/bash -ex
#!/bin/bash -e

SCRIPT_PATH=$(readlink -f "$0")
SCRIPT_NAME=$(basename "$SCRIPT_PATH")

VERBOSE=
DEBUG=

usage() {
echo "Usage: $SCRIPT_NAME [OPTIONS] <name>"
echo
echo "Options:"
echo " --image=<image> Container image (default: jss-runner)"
echo " --hostname=<hostname> Container hostname"
echo " --network=<network> Container network"
echo " --network-alias=<alias> Container network alias"
echo " -v,--verbose Run in verbose mode."
echo " --debug Run in debug mode."
echo " --help Show help message."
}

while getopts v-: arg ; do
case $arg in
v)
VERBOSE=true
;;
-)
LONG_OPTARG="${OPTARG#*=}"

case $OPTARG in
image=?*)
IMAGE="$LONG_OPTARG"
;;
hostname=?*)
HOSTNAME="$LONG_OPTARG"
;;
network=?*)
NETWORK="$LONG_OPTARG"
;;
network-alias=?*)
ALIAS="$LONG_OPTARG"
;;
verbose)
VERBOSE=true
;;
debug)
VERBOSE=true
DEBUG=true
;;
help)
usage
exit
;;
'')
break # "--" terminates argument processing
;;
suffix* | base-dn*)
echo "ERROR: Missing argument for --$OPTARG option" >&2
exit 1
;;
*)
echo "ERROR: Illegal option --$OPTARG" >&2
exit 1
;;
esac
;;
\?)
exit 1 # getopts already reported the illegal option
;;
esac
done

# remove parsed options and args from $@ list
shift $((OPTIND-1))

NAME=$1

if [ "$NAME" == "" ]
then
echo "Usage: runner-init.sh <name>"
echo "ERROR: Missing container name"
exit 1
fi

Expand All @@ -13,16 +86,45 @@ then
IMAGE=jss-runner
fi

docker run \
--name=${NAME} \
--hostname=${HOSTNAME} \
--detach \
--privileged \
--tmpfs /tmp \
--tmpfs /run \
-v ${GITHUB_WORKSPACE}:${SHARED} \
-i \
${IMAGE}
if [ "$DEBUG" = true ]
then
echo "NAME: $NAME"
echo "IMAGE: $IMAGE"
echo "HOSTNAME: $HOSTNAME"
echo "NETWORK: $NETWORK"
echo "ALIAS: $ALIAS"
fi

OPTIONS=()
OPTIONS+=(--name "$NAME")
OPTIONS+=(--hostname "$HOSTNAME")
OPTIONS+=(--tmpfs /tmp)
OPTIONS+=(--tmpfs /run)
OPTIONS+=(-v "$GITHUB_WORKSPACE:$SHARED")

# required to run Podman in container
OPTIONS+=(-v /var/lib/containers:/var/lib/containers)

OPTIONS+=(--detach)
OPTIONS+=(--privileged)
OPTIONS+=(-i)

if [ "$NETWORK" != "" ]
then
OPTIONS+=(--network "$NETWORK")
fi

if [ "$ALIAS" != "" ]
then
OPTIONS+=(--network-alias "$ALIAS")
fi

if [ "$VERBOSE" = true ]
then
echo "Starting $NAME container"
fi

docker run "${OPTIONS[@]}" $IMAGE "/usr/sbin/init"

# Pause 5 seconds to let the container start up.
# The container uses /usr/sbin/init as its entrypoint which requires few seconds
Expand Down

0 comments on commit 308a87a

Please sign in to comment.