Skip to content

Commit

Permalink
fixup!chore(github-action): build cnb image - reworks
Browse files Browse the repository at this point in the history
  • Loading branch information
o-orand committed Oct 1, 2024
1 parent 81ea770 commit ac4dccf
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 92 deletions.
86 changes: 3 additions & 83 deletions .github/workflows/build-using-cnb-buildpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,89 +81,8 @@ jobs:
name: Testing app
shell: bash
run: |
./setup-prerequisite.sh #
./vcap-services-template-reformat.sh
cat vcap-service.env
echo "Starting sample app"
container_name="cnb-app-container"
container_id=$(docker run -d -e PORT=80 -p 8080:80 --env-file vcap-service.env --name "$container_name" ${CNB_IMAGE_NAME})
echo "Cnb app started (id: $container_id)"
echo "Waiting to ensure app is up and running"
while [ "$( docker container inspect -f '{{.State.Status}}' $container_name )" != "running" ]; do
echo "waiting for $container_name to be running current: $(docker inspect -f '{{.State.Status}}' $container_name)"
sleep 1
done
sleep 3 # to ensure app is up and running
#docker inspect -f '{{.HostConfig.LogConfig.Type}}' $container_id
redis_container_name="$(docker ps -f "ancestor=$SERVICE_IMAGE" --format "{{.Names}}")"
CONTAINER_APP_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $container_name)
echo "CONTAINER_APP_IP: $CONTAINER_APP_IP"
if [ $DEBUG -eq 1 ]; then
echo "----------------- $container_name --------------------"
docker inspect -f '{{json .NetworkSettings}}' $container_name
echo "----------------- $redis_container_name --------------------"
docker inspect -f '{{json .NetworkSettings}}' $redis_container_name
fi
echo "=== Redirect logs to cnb-app-container.log ==="
docker logs -f cnb-app-container &> cnb-app-container.log &
docker ps -a
echo "=== Check connectivity ==="
if nc -vz 127.0.0.1 8080;then echo "port 8080 available";else echo "port 8080 UNAVAILABLE";exit_status=1;fi
if nc -vz 127.0.0.1 ${SERVICE_PORT};then echo "port ${SERVICE_PORT} available";else echo "port ${SERVICE_PORT} UNAVAILABLE";exit_status=1;fi
echo "Checking redis server 127.0.0.1 : PING ==> $(redis-cli -a ${SERVICE_PASSWORD} -h 127.0.0.1 -p ${SERVICE_PORT} --no-auth-warning ping)"
echo "Checking redis server $SERVICE_HOST : PING ==> $(redis-cli -a ${SERVICE_PASSWORD} -h ${SERVICE_HOST} -p ${SERVICE_PORT} --no-auth-warning ping)"
function check_service() {
type="$1"
cmd="$2"
cmd_prefix="$3"
if [ -z "$cmd_prefix" ];then
cmd_prefix="curl"
fi
status=0
echo "$type using > $cmd <" 1>&2
if ! $cmd;then
echo "" 1>&2
echo "$type failed: retry in verbose mode" 1>&2
$cmd_prefix -vvv ${cmd##$cmd_prefix}
status=1
else
echo "" 1>&2
echo "$type successful" 1>&2
fi
echo "check_service - status: $status" 1>&2
return $status
}
export APP="http://127.0.0.1:8080"
set +e
exit_status=0
create_service_output="$(check_service "Create" "curl -sSLf -X PUT $APP/foo -d data=bar" )"
create_service=$?
get_service_output="$(check_service "Get" "curl -sSLf -X GET $APP/foo" )"
get_service=$?
delete_service_output="$(check_service "Delete" "curl -sSLf -X DELETE $APP/foo" )"
delete_service=$?
set -e
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
echo "create_service: $create_service"
echo "get_service: $get_service"
echo "create_service: $create_service"
exit_status=$(($create_service + $get_service + $delete_service))
echo "exit status: $exit_status"
echo "==================================================="
echo "==================================================="
echo "Dumping logs using docker logs cnb-app-container"
docker logs cnb-app-container 2>&1
ls -lrt *.log
exit $exit_status
./setup-prerequisite.sh
./run-tests.sh
-
name: Tag version ${{github.ref_name}}
if: github.ref_type == 'tag'
Expand All @@ -172,6 +91,7 @@ jobs:
-
name: Tag with common data
run: |
docker ps -a
docker tag ${{env.CNB_IMAGE_NAME}}:latest ghcr.io/${{ github.repository }}:latest
docker tag ${{env.CNB_IMAGE_NAME}}:latest ghcr.io/${{ github.repository }}:${{github.sha}}
echo "cleanup built image"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.rspec
dump.rdb
redis.log
*.log
.idea
*.iml
/vcap-service.env
80 changes: 80 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env bash
set -e

./vcap-services-template-reformat.sh
cat vcap-service.env
echo "Starting sample app"
container_name="cnb-app-container"
container_id=$(docker run -d --rm --link -e PORT=80 -p 8080:80 --env-file vcap-service.env --name "$container_name" ${CNB_IMAGE_NAME})

echo "Cnb app started (id: $container_id)"
echo "Waiting to ensure app is up and running"
while [ "$( docker container inspect -f '{{.State.Status}}' $container_name )" != "running" ]; do
echo "waiting for $container_name to be running current: $(docker inspect -f '{{.State.Status}}' $container_name)"
sleep 1
done
sleep 3 # to ensure app is up and running
#docker inspect -f '{{.HostConfig.LogConfig.Type}}' $container_id
redis_container_name="$(docker ps -f "ancestor=$SERVICE_IMAGE" --format "{{.Names}}")"
CONTAINER_APP_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $container_name)
echo "CONTAINER_APP_IP: $CONTAINER_APP_IP"

if [ $DEBUG -eq 1 ]; then
echo "----------------- $container_name --------------------"
docker inspect -f '{{json .NetworkSettings}}' $container_name

echo "----------------- $redis_container_name --------------------"
docker inspect -f '{{json .NetworkSettings}}' $redis_container_name
fi
echo "=== Redirect logs to cnb-app-container.log ==="
docker logs -f cnb-app-container &> cnb-app-container.log &
docker ps -a

echo "=== Check connectivity ==="
if nc -vz 127.0.0.1 8080;then echo "port 8080 available";else echo "port 8080 UNAVAILABLE";exit_status=1;fi
if nc -vz 127.0.0.1 ${SERVICE_PORT};then echo "port ${SERVICE_PORT} available";else echo "port ${SERVICE_PORT} UNAVAILABLE";exit_status=1;fi
echo "Checking redis server 127.0.0.1 : PING ==> $(redis-cli -a ${SERVICE_PASSWORD} -h 127.0.0.1 -p ${SERVICE_PORT} --no-auth-warning ping)"
echo "Checking redis server $SERVICE_HOST : PING ==> $(redis-cli -a ${SERVICE_PASSWORD} -h ${SERVICE_HOST} -p ${SERVICE_PORT} --no-auth-warning ping)"

function check_service() {
type="$1"
cmd="$2"
cmd_prefix="$3"
if [ -z "$cmd_prefix" ];then
cmd_prefix="curl"
fi
status=0
echo "$type using > $cmd <" 1>&2
if ! $cmd;then
echo "" 1>&2
echo "$type failed: retry in verbose mode" 1>&2
$cmd_prefix -vvv ${cmd##$cmd_prefix}
status=1
else
echo "" 1>&2
echo "$type successful" 1>&2
fi
echo "check_service - status: $status" 1>&2
return $status
}
export APP="http://127.0.0.1:8080"
set +e
exit_status=0
create_service_output="$(check_service "Create" "curl -sSLf -X PUT $APP/foo -d data=bar" )"
create_service=$?

get_service_output="$(check_service "Get" "curl -sSLf -X GET $APP/foo" )"
get_service=$?

delete_service_output="$(check_service "Delete" "curl -sSLf -X DELETE $APP/foo" )"
delete_service=$?
set -e

echo "create_service: $create_service"
exit_status=$(($create_service + $get_service + $delete_service))
echo "exit status: $exit_status"
echo "======================================================================================================"
echo "Dumping logs using docker logs cnb-app-container"
docker logs cnb-app-container 2>&1
ls -lrt *.log
exit $exit_status
24 changes: 16 additions & 8 deletions start-cnd-app-locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
set -e

source local.env

source ./setup-prerequisite.sh

./vcap-services-template-reformat.sh >vcap-service.env
cat vcap-service.env
echo ""
echo "Starting app using ${CNB_IMAGE_NAME}"
#docker run -it --rm -e PORT=8081 --env-file vcap-service.env -p 8080:8081 --name "cnb-app" ${CNB_IMAGE_NAME}
docker run --rm -e PORT=80 --env-file vcap-service.env -p 8080:80 --name "cnb-app" ${CNB_IMAGE_NAME}
#docker run -d --rm -e PORT=8081 --env-file vcap-service.env -p 8080:8081 --name "cnb-app" ${CNB_IMAGE_NAME}
for c in cnb-app-container redis-service;do
if docker container stop $c;then
docker container rm -f $c
fi
done
./run-tests.sh



#./vcap-services-template-reformat.sh >vcap-service.env
#cat vcap-service.env
#echo ""
#echo "Starting app using ${CNB_IMAGE_NAME}"
##docker run -it --rm -e PORT=8081 --env-file vcap-service.env -p 8080:8081 --name "cnb-app" ${CNB_IMAGE_NAME}
#docker run --rm -e PORT=80 --env-file vcap-service.env -p 8080:80 --name "cnb-app" ${CNB_IMAGE_NAME}
##docker run -d --rm -e PORT=8081 --env-file vcap-service.env -p 8080:8081 --name "cnb-app" ${CNB_IMAGE_NAME}

0 comments on commit ac4dccf

Please sign in to comment.