Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
service still do not reach the Ready state
Browse files Browse the repository at this point in the history
  • Loading branch information
lucj committed Dec 13, 2023
1 parent f0762d0 commit 929b6b3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 39 deletions.
17 changes: 12 additions & 5 deletions Acornfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,23 @@ args: {

services: db: {
generated: job: "setup"
default: true
}

containers: {
couchbase: {
name: "Couchbase Server"
description: "Container running a Couchbase server"
image: "couchbase:\(args.version)"
ports: {
expose: "8091/http",
}
ports: [
"8091/http",
]
probes: [
{
type: "readiness"
tcp: {
url: "tcp://localhost:8091"
}
},
]
}
}

Expand All @@ -46,6 +52,7 @@ jobs: setup: {
CB_ADMIN_USER: "secret://admin/username"
CB_ADMIN_PASS: "secret://admin/password"
}
events: ["create", "update"]
}

secrets: {
Expand Down
82 changes: 48 additions & 34 deletions scripts/init.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/bin/sh
# set -euxo pipefail

# Make sure this script is only triggered on Acorn creation events
echo "event: ${ACORN_EVENT}"
if [ "${ACORN_EVENT}" = "delete" ]; then
echo "ACORN_EVENT must be [create, update], currently is [${ACORN_EVENT}]"
exit 0
fi

# Couple of variables to make local testing simpler
termination_log="/dev/termination-log"
acorn_output="/run/secrets/output"
Expand All @@ -26,52 +33,59 @@ done

# Additional delay for server initialization
echo "Couchbase Server is up, waiting for initialization..."
sleep 20
sleep 10

couchbase-cli server-list -c $CB_HOST:$CB_PORT -u $CB_ADMIN_USER -p $CB_ADMIN_PASS >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Cluster is already initialized."
else
# Initialize the node and cluster
res=$(couchbase-cli cluster-init \
--cluster $CB_HOST:$CB_PORT \
--cluster-username $CB_ADMIN_USER \
--cluster-password $CB_ADMIN_PASS \
--cluster-name $CB_CLUSTER_NAME \
--cluster-ramsize $CB_RAMSIZE \
--services $CB_SERVICES 2>&1)

# Initialize the node and cluster
res=$(couchbase-cli cluster-init \
--cluster $CB_HOST:$CB_PORT \
--cluster-username $CB_ADMIN_USER \
--cluster-password $CB_ADMIN_PASS \
--cluster-name $CB_CLUSTER_NAME \
--cluster-ramsize $CB_RAMSIZE \
--services $CB_SERVICES 2>&1)
if [ $? -ne 0 ]; then
echo "cluster init failed"
echo $res | tee ${termination_log}
exit 1
fi

if [ $? -ne 0 ]; then
echo "cluster init failed"
echo $res | tee ${termination_log}
exit 1
echo "Couchbase Server has been initialized and configured!"
fi

echo "Couchbase Server has been initialized and configured!"
couchbase-cli bucket-list -c $CB_HOST:$CB_PORT -u $CB_ADMIN_USER -p $CB_ADMIN_PASS | grep -q "$CB_BUCKET_NAME" 2>&1
if [ $? -eq 0 ];then
echo "Bucket $BUCKET_NAME exists."
else
res=$(couchbase-cli bucket-create \
--cluster $CB_HOST:$CB_PORT \
--username $CB_ADMIN_USER \
--password $CB_ADMIN_PASS \
--bucket $CB_BUCKET_NAME \
--bucket-type $CB_BUCKET_TYPE \
--bucket-ramsize $CB_BUCKET_RAMSIZE \
--bucket-replica $CB_BUCKET_REPLICA)

# Create a bucket
res=$(couchbase-cli bucket-create \
--cluster $CB_HOST:$CB_PORT \
--username $CB_ADMIN_USER \
--password $CB_ADMIN_PASS \
--bucket $CB_BUCKET_NAME \
--bucket-type $CB_BUCKET_TYPE \
--bucket-ramsize $CB_BUCKET_RAMSIZE \
--bucket-replica $CB_BUCKET_REPLICA)
if [ $? -ne 0 ]; then
echo "bucket creation failed"
echo $res | tee ${termination_log}
exit 1
fi

if [ $? -ne 0 ]; then
echo "bucket creation failed"
echo $res | tee ${termination_log}
exit 1
echo "Bucket $CB_BUCKET_NAME has been created."
fi

echo "Bucket $CB_BUCKET_NAME has been created."

# Define service
cat > /run/secrets/output<<EOF
cat > $acorn_output<<EOF
services: db: {
container: "couchbase"
default: true
container: "couchbase"
secrets: ["admin"]
ports: [
"8091",
]
ports: "8091"
data: {
bucketName: "${CB_BUCKET_NAME}"
}
Expand Down

0 comments on commit 929b6b3

Please sign in to comment.