diff --git a/action.yml b/action.yml index 3d7abf2..555f4dd 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,15 @@ inputs: description: 'Version of CouchDB to use.' required: false default: 'latest' + couchdb user: + description: 'Username name of the admin user.' + required: false + couchdb password: + description: 'Password of the admin user.' + required: false +outputs: + couchdb-url: + description: 'Base URL to make requests to CouchDB.' runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index 6f0d2c5..136f8e4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,15 @@ #!/bin/sh +if [[ -z "$INPUT_COUCHDB_USER" ]] || [[ -z "$INPUT_COUCHDB_PASSWORD" ]]; then + echo ">> CouchDB admin credentials not defined - ADMIN PARTY is not supported on 3.x" +else + echo ">> CouchDB admin credentials provided" + CFG_COUCHDB_ADMIN="-e COUCHDB_USER=$INPUT_COUCHDB_USER -e COUCHDB_PASSWORD=$INPUT_COUCHDB_PASSWORD" + CURL_CREDENTIALS="-u $INPUT_COUCHDB_USER:$INPUT_COUCHDB_PASSWORD" +fi + echo "Starting Docker..." -sh -c "docker run -d -p 5984:5984 -p 5986:5986 --tmpfs /ram_disk couchdb:$INPUT_COUCHDB_VERSION" +sh -c "docker run -d -p 5984:5984 -p 5986:5986 --tmpfs /ram_disk $CFG_COUCHDB_ADMIN couchdb:$INPUT_COUCHDB_VERSION" # CouchDB container name export NAME=`docker ps --format "{{.Names}}" --last 1` @@ -22,6 +30,9 @@ wait_for_couchdb # Set up system databases echo "Setting up CouchDB system databases..." -docker exec $NAME curl -sS 'http://127.0.0.1:5984/_users' -X PUT -H 'Content-Type: application/json' --data '{"id":"_users","name":"_users"}' > /dev/null -docker exec $NAME curl -sS 'http://127.0.0.1:5984/_global_changes' -X PUT -H 'Content-Type: application/json' --data '{"id":"_global_changes","name":"_global_changes"}' > /dev/null -docker exec $NAME curl -sS 'http://127.0.0.1:5984/_replicator' -X PUT -H 'Content-Type: application/json' --data '{"id":"_replicator","name":"_replicator"}' > /dev/null +docker exec $NAME curl -sS $CURL_CREDENTIALS 'http://127.0.0.1:5984/_users' -X PUT -H 'Content-Type: application/json' --data '{"id":"_users","name":"_users"}' > /dev/null +docker exec $NAME curl -sS $CURL_CREDENTIALS 'http://127.0.0.1:5984/_global_changes' -X PUT -H 'Content-Type: application/json' --data '{"id":"_global_changes","name":"_global_changes"}' > /dev/null +docker exec $NAME curl -sS $CURL_CREDENTIALS 'http://127.0.0.1:5984/_replicator' -X PUT -H 'Content-Type: application/json' --data '{"id":"_replicator","name":"_replicator"}' > /dev/null + +COUCHDB_URL="http://$INPUT_COUCHDB_USER:$INPUT_COUCHDB_PASSWORD@127.0.0.1:5984/" +echo "couchdb-url=$(echo $COUCHDB_URL)" >> $GITHUB_OUTPUT