diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ffdd645..db132ad 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,17 +9,25 @@ on: jobs: tests: runs-on: ubuntu-latest + strategy: + matrix: + couchdb: ["3.3", "3.2", "3.1", "2.3"] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Set up CouchDB uses: ./ with: - couchdb version: '2.3.1' + couchdb version: ${{ matrix.couchdb }} + env: + NODENAME: localhost + ERL_NATOVE_QUERY: true + COUCHDB_USER: admin + COUCHDB_PASSWORD: password - name: Test that CouchDB can be accessed - run: curl -sS -f http://127.0.0.1:5984/ + run: curl -sS -f http://admin:password@localhost:5984/ - name: Test that system databases are there - run: curl -sS -f http://127.0.0.1:5984/_users + run: curl -sS -f http://admin:password@localhost:5984/_users - name: Test that the Erlang query server is enabled run: | - curl -sS -f 'http://127.0.0.1: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://127.0.0.1:5984/_users/_design/test/_view/test' + curl -sS -f 'http://admin:password@localhost: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://admin:password@localhost:5984/_users/_design/test/_view/test' -v diff --git a/README.md b/README.md index 770553f..43f5eae 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,9 @@ steps: uses: "cobot/couchdb-action@master" with: couchdb version: '2.3.1' + env: + COUCHDB_USER: admin + COUCHDB_PASSWORD: password - name: Do something run: | curl http://127.0.0.1:5984/ diff --git a/entrypoint.sh b/entrypoint.sh index 6f0d2c5..86e61b2 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,27 +1,40 @@ #!/bin/sh echo "Starting Docker..." -sh -c "docker run -d -p 5984:5984 -p 5986:5986 --tmpfs /ram_disk couchdb:$INPUT_COUCHDB_VERSION" +ERL_QUERIES="${ERL_NATIVE_QUERY:-true}" +NODENAME="${NODENAME:-localhost}" + +sh -c "docker run -d -p 5984:5984 -p 5986:5986 -e \"NODENAME=${NODENAME}\" -e \"COUCHDB_USER=${COUCHDB_USER}\" -e \"COUCHDB_PASSWORD=${COUCHDB_PASSWORD}\" --tmpfs /ram_disk couchdb:${INPUT_COUCHDB_VERSION}" # CouchDB container name export NAME=`docker ps --format "{{.Names}}" --last 1` -docker exec $NAME sh -c 'mkdir -p /opt/couchdb/etc/local.d && echo "[couchdb]\ndatabase_dir = /ram_disk\nview_index_dir = /ram_disk\ndelayed_commits = true\n[httpd]\nsocket_options = [{nodelay, true}]\n[native_query_servers]\nerlang = {couch_native_process, start_link, []}" >> /opt/couchdb/etc/local.d/01-github-action-custom.ini' +docker exec $NAME sh -c "mkdir -p /opt/couchdb/etc/local.d && echo \"[couchdb]\ndatabase_dir = /ram_disk\nview_index_dir = /ram_disk\ndelayed_commits = true\n[httpd]\nsocket_options = [{nodelay, true}]\nbind_address = 0.0.0.0\n[native_query_servers]\nenable_erlang_query_server=${ERL_QUERIES}\" >> /opt/couchdb/etc/local.d/01-github-action-custom.ini" wait_for_couchdb() { - echo "Waiting for CouchDB..." - hostip=$(ip route show | awk '/default/ {print $3}') + hostip=$(ip route | awk '/default/ {print $3}') + + echo "Waiting for CouchDB at ${hostip}..." + + curl -I http://$hostip:5984/ - while ! curl -f http://$hostip:5984/ &> /dev/null - do - echo "." + for i in {1..60}; do + if curl -s http://$hostip:5984/ >/dev/null; then + echo "CouchDB is up" + return 0 + fi + + echo "Still waiting ($i)..." sleep 1 done + + echo "CouchDB did not become available after 60 seconds" + exit 1 } 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 "http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@localhost:5984/_users" -X PUT -H 'Content-Type: application/json' --data '{"id":"_users","name":"_users"}' > /dev/null +docker exec $NAME curl -sS "http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@localhost: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://${COUCHDB_USER}:${COUCHDB_PASSWORD}@localhost:5984/_replicator" -X PUT -H 'Content-Type: application/json' --data '{"id":"_replicator","name":"_replicator"}' > /dev/null