Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add admin credentials input for CouchDB v3 #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
19 changes: 15 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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:[email protected]:5984/"
echo "couchdb-url=$(echo $COUCHDB_URL)" >> $GITHUB_OUTPUT