Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
6 changes: 6 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ includes:
docker-redis:
taskfile: ./docker-redis/Taskfile.yml
dir: ./docker-redis
docker-couchdb:
taskfile: ./docker-couchdb/Taskfile.yml
dir: ./docker-couchdb
kube-kind:
taskfile: ./kube-kind/Taskfile.yml
dir: ./kube-kind
kube-redis:
taskfile: ./kube-redis/Taskfile.yml
dir: ./kube-redis
kube-couchdb:
taskfile: ./kube-couchdb/Taskfile.yml
dir: ./kube-couchdb

tasks:
default: task --list-all
94 changes: 94 additions & 0 deletions docker-couchdb/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
version: 3

vars:
IMAGE: couchdb:latest
CONTAINER_NAME: couchdb-server
PORT: "5984"
COUCHDB_USER: admin
COUCHDB_PASSWORD: admin
ENDPOINT: http://{{.COUCHDB_USER}}:{{.COUCHDB_PASSWORD}}@localhost:{{.PORT}}

includes:
variables:
taskfile: ../variables/Taskfile.yml
dir: ../variables

tasks:
default: task --list-all

dbcliprereq:
silent: true
cmds:
- test -x "$(which curl)" || { echo "curl not available"; exit 1; }

create:
desc: Run the Couchdb container
cmds:
- docker run -d --name {{.CONTAINER_NAME}} -e COUCHDB_USER={{.COUCHDB_USER}} -e COUCHDB_PASSWORD={{.COUCHDB_PASSWORD}} -p {{.PORT}}:{{.PORT}} {{.IMAGE}}
silent: true

stop:
desc: Stop the Couchdb container
cmds:
- docker stop {{.CONTAINER_NAME}}
silent: true

remove:
desc: Remove the Couchdb container
cmds:
- docker rm -f {{.CONTAINER_NAME}}
silent: true

logs:
desc: View the logs of the Couchdb container
cmds:
- docker logs {{.CONTAINER_NAME}}
silent: false

status:
desc: Check the status of the Couchdb container
cmds:
- docker ps -a --filter "name={{.CONTAINER_NAME}}"
silent: true

start:
desc: Start the Couchdb container
cmds:
- |
if docker ps -a --format '{{`{{.Names}}`}}' | grep -q '^{{.CONTAINER_NAME}}$'; then
if [ "$(docker inspect -f '{{`{{.State.Status}}`}}' {{.CONTAINER_NAME}})" = "exited" ]; then
docker start {{.CONTAINER_NAME}}
else
echo "Container is already running or in different state"
fi
else
echo "Container does not exist. Use 'task create' first"
fi
silent: true

listdbs:
desc: List the Couchdb databases
cmds:
- task: dbcliprereq
- curl '{{.ENDPOINT}}/_all_dbs'
silent: true

createdb:
desc: Create a couchdb database
vars:
DB_NAME: '{{.DB_NAME | default ""}}'
cmds:
- task: dbcliprereq
- task: variables:check-var
vars: { VAR_NAME: "DB_NAME", VAR_VALUE: "{{.DB_NAME}}" }
- curl -XPUT '{{.ENDPOINT}}/{{.DB_NAME}}'

test:
desc: Run a test command in the Couchdb container
cmds:
- task: create
- task: status
- task: logs
- task: remove
- task: status
silent: false
98 changes: 98 additions & 0 deletions kube-couchdb/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
version: 3

vars:
COUCHDB_USER: admin
COUCHDB_PASSWORD: admin
COUCHDB_USER_B64:
sh: 'echo -n "{{.COUCHDB_USER}}" | base64'
COUCHDB_PASSWORD_B64:
sh: 'echo -n "{{.COUCHDB_PASSWORD}}" | base64'
IMAGE: couchdb:latest
POD_NAME: couchdb-server
NAMESPACE: default

tasks:

default: task --list-all

render-secret:
desc: Generates couchdb secret
env:
COUCHDB_USER: "{{.COUCHDB_USER_B64}}"
COUCHDB_PASSWORD: "{{.COUCHDB_PASSWORD_B64}}"
POD_NAME: "{{.POD_NAME}}"
NAMESPACE: "{{.NAMESPACE}}"
cmds:
- envsubst < couchdb-secret.tmpl.yaml > couchdb-secret.yaml
internal: true

render-deployment:
desc: Render couchdb deployment manifest
env:
COUCHDB_USER: "{{.COUCHDB_USER_B64}}"
COUCHDB_PASSWORD: "{{.COUCHDB_PASSWORD_B64}}"
POD_NAME: "{{.POD_NAME}}"
NAMESPACE: "{{.NAMESPACE}}"
IMAGE: "{{.IMAGE}}"
cmds:
- echo "Rendering manifest..."
- envsubst < couchdb.tmpl.yaml > couchdb.yaml
internal: true

render-templates:
internal: true
cmds:
- task: render-secret
- task: render-deployment

create:
desc: Run the Couchdb pod
cmds:
- task: render-templates
- kubectl --dry-run=server apply -f couchdb-secret.yaml
- kubectl --dry-run=server apply -f couchdb.yaml
silent: true

status:
desc: Check the status of the Couchdb pod
cmds:
- kubectl get pods -l app=couchdb
silent: true

wait:
desc: Wait for the Couchdb pod to be ready
cmds:
- kubectl wait --for=condition=Ready pod -l app=couchdb --timeout=60s
silent: true

remove:
desc: Remove the Couchdb pod
cmds:
- kubectl delete -f couchdb.tmpl.yaml
silent: true

logs:
desc: View the logs of the Couchdb pod
cmds:
- kubectl logs -l app=couchdb
silent: false

cli:
vars:
POD:
sh: |
kubectl get pods -l app=couchdb -o jsonpath='{.items[0].metadata.name}'
desc: Open a shell in the Couchdb pod
cmds:
- kubectl exec -it {{.POD}} -- couchdb-cli
silent: false

test:
desc: Run a test command in the Couchdb pod
cmds:
- task: create
- task: wait
- task: status
- task: logs
- task: remove
silent: false
9 changes: 9 additions & 0 deletions kube-couchdb/couchdb-secret.tmpl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: ${POD_NAME}-secret
namespace: ${NAMESPACE}
type: Opaque
data:
username: ${COUCHDB_USER}
password: ${COUCHDB_PASSWORD}
9 changes: 9 additions & 0 deletions kube-couchdb/couchdb-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: couchdb-server-secret
namespace: default
type: Opaque
data:
username: YWRtaW4=
password: YWRtaW4=
15 changes: 15 additions & 0 deletions variables/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 3

tasks:
check-var:
desc: "Checks if a required variable is set"
cmds:
- |
VAR_NAME="{{.VAR_NAME}}"
VAR_VALUE="{{.VAR_VALUE}}"

if [ -z "$VAR_VALUE" ]; then
printf "Error: required variable '%s' is not set or empty.\n" "$VAR_NAME" >&2
exit 1
fi
silent: true