-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup!test: rework to share principles with redis sample
- Loading branch information
Showing
10 changed files
with
165 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,14 @@ on: | |
- "v?[0-9]+.[0-9]+.[0-9]+*" | ||
env: | ||
CNB_IMAGE_NAME: cnb-app | ||
SERVICE_NAME: 'mongodb' | ||
SERVICE_VERSION: '6.0' | ||
SERVICE_IMAGE: "mongo:7.0.14" | ||
SERVICE_PORT: 27017 # Default value: 27017 | ||
SERVICE_USERNAME: '22032e25-4aba-417f-a394-8bbd78d920cd' | ||
SERVICE_PASSWORD: 'StbQ4EovUpwQjD0cT1Hr7PKBG' | ||
DATABASE_NAME: my-mongo-db | ||
DEBUG: 0 | ||
|
||
jobs: | ||
package-app: | ||
|
@@ -40,65 +43,31 @@ jobs: | |
- | ||
name: Setup pack for ${{ github.repository }} | ||
uses: buildpacks/github-actions/[email protected] | ||
- | ||
name: Start MongoDB testing server | ||
uses: supercharge/[email protected] | ||
with: | ||
mongodb-version: ${{ env.SERVICE_VERSION }} | ||
mongodb-port: ${{env.SERVICE_PORT}} | ||
mongodb-username: ${{env.SERVICE_USERNAME}} | ||
mongodb-password: ${{env.SERVICE_PASSWORD}} | ||
mongodb-db: ${{env.DATABASE_NAME}} | ||
# mongodb-container-name: mongodb-${{ env.SERVICE_VERSION }} | ||
# - | ||
# name: Start MongoDB testing server | ||
# uses: supercharge/[email protected] | ||
# with: | ||
# mongodb-version: ${{ env.SERVICE_VERSION }} | ||
# mongodb-port: ${{env.SERVICE_PORT}} | ||
# mongodb-username: ${{env.SERVICE_USERNAME}} | ||
# mongodb-password: ${{env.SERVICE_PASSWORD}} | ||
# mongodb-db: ${{env.DATABASE_NAME}} | ||
## mongodb-container-name: mongodb-${{ env.SERVICE_VERSION }} | ||
|
||
- | ||
name: Packaging app from ${{ github.repository }} pushed by ${{ github.actor }} | ||
shell: bash | ||
run: | | ||
echo "Pack Build ${{env.CNB_IMAGE_NAME}} (${{github.repository}})" | ||
pack build ${{env.CNB_IMAGE_NAME}} --builder paketobuildpacks/builder-jammy-base | ||
pack build ${{env.CNB_IMAGE_NAME}} | ||
echo "Pack Inspect ${{env.CNB_IMAGE_NAME}} (${{github.repository}})" | ||
pack inspect ${{env.CNB_IMAGE_NAME}} | ||
- | ||
name: Testing app | ||
shell: bash | ||
run: | | ||
cat vcap-services-template.sh|envsubst >vcap-service.env | ||
cat vcap-service.env | ||
echo "Starting sample app" | ||
container_id=$(docker run -d -e PORT=80 --env-file vcap-service.env -p 8080:80 --name "cnb-app-container" ${{env.CNB_IMAGE_NAME}}) | ||
echo "Cnb app started (id: $container_id)" | ||
docker inspect -f '{{.HostConfig.LogConfig.Type}}' $container_id | ||
# docker run -e PORT=80 --env-file vcap-service.env -p 8080:80 --name "cnb-app-container" ${{env.CNB_IMAGE_NAME}} | ||
docker logs -f cnb-app-container &> cnb-app-container.log & | ||
docker logs mongodb | ||
cat /etc/hosts | ||
docker ps -a | ||
env|sort | ||
export APP="http://127.0.0.1:8080" | ||
exit_status=0 | ||
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 | ||
if mongosh --version;then echo "mongosh available";else echo "mongosh UNAVAILABLE";fi | ||
echo "Create using 'curl -X POST $APP/myCollection'" | ||
if ! curl -vvv -X POST $APP/myCollection -H 'Content-Length: 0';then | ||
echo "Create failed" | ||
exit_status=1 | ||
else | ||
echo "Create successful" | ||
fi | ||
echo "Delete using 'curl -X DELETE $APP/myCollection'" | ||
if ! curl -vvv -X DELETE $APP/myCollection;then | ||
echo "Delete failed" | ||
exit_status=1 | ||
else | ||
echo "Delete successful" | ||
fi | ||
cat cnb-app-container.log | ||
echo "Dumping logs using docker logs cnb-app-container" | ||
docker logs cnb-app-container | ||
ls -lrt | ||
exit $exit_status | ||
./setup-prerequisite.sh | ||
./run-tests.sh | ||
- | ||
name: Tag version ${{github.ref_name}} | ||
if: github.ref_type == 'tag' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
/vendor | ||
/tmp | ||
.idea/ | ||
*.log | ||
*.iml | ||
/vcap-service.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export CNB_IMAGE_NAME=mongodb-cnb-app | ||
export SERVICE_NAME=mongodb | ||
export SERVICE_HEALTH_CMD=mongo | ||
export SERVICE_PORT=27001 | ||
export DATABASE_NAME=myCollection | ||
export SERVICE_IMAGE="mongo:7.0.14" | ||
export SERVICE_HOST="dynamically_generated" | ||
export SERVICE_PASSWORD=my-passwwwwwwwword15; | ||
#export DEBUG=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[_] | ||
schema-version = "0.2" | ||
id = "com.orange-cloudfoundry.sample-apps.mongodb" | ||
name = "MongoDB sample app" | ||
#version = "1.0.0" | ||
|
||
[io.buildpacks] | ||
builder = "paketobuildpacks/builder-jammy-base" | ||
exclude = [ | ||
".github", | ||
"renovate.json", | ||
"README.md" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/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 -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 | ||
service_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 "----------------- $SERVICE_NAME: $service_container_name --------------------" | ||
docker inspect -f '{{json .NetworkSettings}}' "$service_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 POST $APP/myCollection -H 'Content-Length: 0' )" | ||
create_service=$? | ||
#get_service_output="$(check_service "Get" "curl -sSLf -X GET $APP/foo" )" | ||
#get_service=$? | ||
delete_service_output="$(check_service "Delete" "curl -sSLf DELETE $APP/myCollection" )" | ||
delete_service=$? | ||
set -e | ||
exit_status=$(($create_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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
service_container_id=$(docker run -d -p $SERVICE_PORT:$SERVICE_PORT \ | ||
-e MONGO_INITDB_ROOT_USERNAME="$SERVICE_USERNAME" \ | ||
-e MONGO_INITDB_ROOT_PASSWORD="$SERVICE_PASSWORD" \ | ||
-e MONGO_INITDB_DATABASE="$DATABASE_NAME" \ | ||
--name "$SERVICE_NAME-service" \ | ||
--health-cmd "$SERVICE_HEALTH_CMD" \ | ||
--health-interval 10s --health-timeout 5s --health-retries 5 \ | ||
${SERVICE_IMAGE}) | ||
service_container_name="$(docker ps -f "ancestor=$SERVICE_IMAGE" --format "{{.Names}}")" | ||
SERVICE_CONTAINER_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$service_container_name") | ||
echo "$SERVICE_CONTAINER_IP: $SERVICE_CONTAINER_IP" | ||
export SERVICE_HOST=$SERVICE_CONTAINER_IP | ||
docker exec -i "$service_container_name" 'if mongosh --version;then echo "mongosh available";else echo "mongosh UNAVAILABLE";fi' | ||
echo "SERVICE_HOST: $SERVICE_HOST" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
for c in cnb-app-container mongodb-service;do | ||
if docker container stop $c;then | ||
docker container rm -f $c | ||
fi | ||
done | ||
|
||
source local.env | ||
source ./setup-prerequisite.sh | ||
./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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
echo VCAP_SERVICES="$(cat vcap-services-template.json|jq -c '.'|envsubst)" > vcap-service.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters