Skip to content

Commit

Permalink
enable erlang query server (#2)
Browse files Browse the repository at this point in the history
* optional, via input
  • Loading branch information
langalex authored Oct 25, 2019
1 parent b440378 commit badc96c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ jobs:
- uses: actions/checkout@v1
- name: Set up CouchDB
id: couchdb
uses: "cobot/couchdb-action@master"
uses: cobot/couchdb-action@master
with:
couchdb version: '2.3.1'
- name: Run test
erlang query server: true
- name: Test that CouchDB can be accessed
run: curl -sS -f http://${{steps.couchdb.outputs.ip}}:5984/
- name: Test that system databases are there
run: curl -sS -f http://${{steps.couchdb.outputs.ip}}:5984/_users
- name: Test that the Erlang query server is enabled
run: |
curl -sS -f http://${{steps.couchdb.outputs.ip}}:5984/
curl -sS -f http://${{steps.couchdb.outputs.ip}}:5984/_users
curl -sS -f 'http://${{steps.couchdb.outputs.ip}}:5984/_users/_design/test' -X PUT -H 'Content-Type: application/json' --data '{"views":{"test":{"map":"fun({Doc}) -> Emit(proplists:get_value(<<\"name\">>, Doc, null), 1) end."}},"language":"erlang"}'
curl -sS -f 'http://${{steps.couchdb.outputs.ip}}:5984/_users/_design/test/_view/test'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ steps:
uses: "cobot/couchdb-action@master"
with:
couchdb version: '2.3.1'
erlang query server: true|false
- name: Do something
run: |
curl http://${{steps.couchdb.outputs.ip}}:5984/
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ inputs:
description: 'Version of CouchDB to use.'
required: false
default: 'latest'
erlang query server:
description: 'Enable Erlang query server.'
required: false
default: true
outputs:
ip:
description: IP address of CouchDB
Expand Down
20 changes: 15 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@
echo "Starting Docker..."
sh -c "docker run -d -p 5984:5984 -p 5986:5986 couchdb:$INPUT_COUCHDB_VERSION"

echo "Waiting for CouchDB..."
hostip=$(ip route show | awk '/default/ {print $3}')
# CouchDB container name
export NAME=`docker ps --format "{{.Names}}" --last 1`

# Enable Erlang query server
if [ "$INPUT_ERLANG_QUERY_SERVER" = 'true' ]
then
echo "Enabling Erlang query server..."
docker exec $NAME mkdir -p /opt/couchdb/etc/local.d
docker exec $NAME sh -c 'echo "[native_query_servers]\nerlang = {couch_native_process, start_link, []}" >> /opt/couchdb/etc/local.d/15-erlang-query-server.ini'
# docker exec $NAME service couchdb restart
fi

wait_for_couchdb() {
echo "Waiting for CouchDB..."
hostip=$(ip route show | awk '/default/ {print $3}')

while ! curl -f http://$hostip:5984/ &> /dev/null
do
echo "."
Expand All @@ -15,10 +27,8 @@ wait_for_couchdb() {
}
wait_for_couchdb

# CouchDB container name
export NAME=`docker ps --format "{{.Names}}" --last 1`

# 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
Expand Down

0 comments on commit badc96c

Please sign in to comment.