Skip to content

Commit 365e9cf

Browse files
authored
fix enabling erlang query server (#11)
1 parent 7474dc7 commit 365e9cf

File tree

6 files changed

+52
-25
lines changed

6 files changed

+52
-25
lines changed

.github/workflows/test.yml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@ name: Test
22
on:
33
push:
44
branches:
5-
- master
5+
- master
66
pull_request:
77
branches:
8-
- master
8+
- master
99
jobs:
1010
tests:
1111
runs-on: ubuntu-latest
12+
timeout-minutes: 2
1213
steps:
13-
- uses: actions/checkout@v1
14-
- name: Set up CouchDB
15-
uses: ./
16-
with:
17-
couchdb version: '2.3.1'
18-
- name: Test that CouchDB can be accessed
19-
run: curl -sS -f http://127.0.0.1:5984/
20-
- name: Test that system databases are there
21-
run: curl -sS -f http://127.0.0.1:5984/_users
22-
- name: Test that the Erlang query server is enabled
23-
run: |
24-
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"}'
25-
curl -sS -f 'http://127.0.0.1:5984/_users/_design/test/_view/test'
14+
- uses: actions/checkout@v1
15+
- name: Set up CouchDB
16+
uses: ./
17+
with:
18+
couchdb version: "2.3.1"
19+
- name: Test that CouchDB can be accessed
20+
run: curl -sS -f http://127.0.0.1:5984/
21+
- name: Test that system databases are there
22+
run: curl -sS -f http://127.0.0.1:5984/_users
23+
- name: Test that the Erlang query server is enabled
24+
run: |
25+
curl -sS -f 'http://admin:admin@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"}'
26+
curl -sS -f 'http://admin:admin@127.0.0.1:5984/_users/_design/test/_view/test'

01-github-action-custom.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[couchdb]
2+
database_dir = /ram_disk
3+
view_index_dir = /ram_disk
4+
delayed_commits = true
5+
6+
[httpd]
7+
socket_options = [{nodelay, true}]
8+
9+
[native_query_servers]
10+
erlang = {couch_native_process, start_link, []}
11+
12+
[admins]
13+
admin = admin

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
FROM docker:stable
2-
RUN apk add --no-cache curl
3-
4-
RUN 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
2+
RUN apk add --no-cache curl sed
53

64
COPY entrypoint.sh /entrypoint.sh
75
ENTRYPOINT ["/entrypoint.sh"]

Dockerfile.couchdb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM couchdb:COUCHDB_VERSION
2+
3+
RUN mkdir -p /opt/couchdb/etc/local.d
4+
COPY 01-github-action-custom.ini /opt/couchdb/etc/local.d/01-github-action-custom.ini

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
# CouchDB GitHub Action
22

33
This [GitHub Action](https://github.com/features/actions) sets up a CouchDB database.
4+
45
The Erlang query server is enabled.
6+
A default user "admin" with the password "admin" is created.
57

68
# Usage
79

810
See [action.yml](action.yml) and [test.yml](.github/workflows/test.yml).
911

1012
Basic:
13+
1114
```yaml
1215
steps:
1316
- name: Set up CouchDB
1417
uses: "cobot/couchdb-action@master"
1518
with:
16-
couchdb version: '2.3.1'
19+
couchdb version: "2.3.1"
1720
- name: Do something
1821
run: |
19-
curl http://127.0.0.1:5984/
20-
22+
curl http://admin:admin@127.0.0.1:5984/
2123
```
2224
2325
# Contributions

entrypoint.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
#!/bin/sh
22

33
echo "Starting Docker..."
4-
sh -c "docker run -d -p 5984:5984 -p 5986:5986 --tmpfs /ram_disk couchdb:$INPUT_COUCHDB_VERSION"
4+
sed -i "s/COUCHDB_VERSION/$INPUT_COUCHDB_VERSION/" Dockerfile.couchdb
5+
docker build --tag couchdb -f Dockerfile.couchdb .
6+
docker run -d -p 5984:5984 -p 5986:5986 --tmpfs /ram_disk couchdb
57

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

911
wait_for_couchdb() {
1012
echo "Waiting for CouchDB..."
1113
hostip=$(ip route show | awk '/default/ {print $3}')
14+
retries=0
15+
max_retries=20
1216

1317
while ! curl -f http://$hostip:5984/ &> /dev/null
1418
do
19+
retries=$((retries+1))
20+
if [ $retries -ge $max_retries ]; then
21+
echo "CouchDB did not become available after $max_retries attempts. Exiting."
22+
exit 1
23+
fi
1524
echo "."
1625
sleep 1
1726
done
@@ -20,6 +29,6 @@ wait_for_couchdb
2029

2130
# Set up system databases
2231
echo "Setting up CouchDB system databases..."
23-
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
24-
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
25-
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
32+
docker exec $NAME curl -sS 'http://admin:admin@127.0.0.1:5984/_users' -X PUT -H 'Content-Type: application/json' --data '{"id":"_users","name":"_users"}' > /dev/null
33+
docker exec $NAME curl -sS 'http://admin:admin@127.0.0.1:5984/_global_changes' -X PUT -H 'Content-Type: application/json' --data '{"id":"_global_changes","name":"_global_changes"}' > /dev/null
34+
docker exec $NAME curl -sS 'http://admin:admin@127.0.0.1:5984/_replicator' -X PUT -H 'Content-Type: application/json' --data '{"id":"_replicator","name":"_replicator"}' > /dev/null

0 commit comments

Comments
 (0)