forked from ckan/ckan-docker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.ahoy.yml
216 lines (187 loc) · 7.52 KB
/
.ahoy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
---
ahoyapi: v2
entrypoint:
- bash
- "-c"
- "-e"
- |
[ -f .env ] && [ -s .env ] && export $(grep -v '^#' .env | xargs) && if [ -f .env.local ] && [ -s .env.local ]; then export $(grep -v '^#' .env.local | xargs); fi
bash -e -c "$0" "$@"
- "{{cmd}}"
- "{{name}}"
commands:
init:
usage: Initialise the codebase on first-time setup (ahoy init)
cmd: |
echo "Creating project variables."
cp .env.dbca .env
echo "Install local development extensions."
sh src/dbca_install_extensions.sh
up:
usage: Build project.
cmd: |
docker compose -f $DOCKER_COMPOSE up -d "$@"
ahoy info;
down:
usage: Delete project (CAUTION).
cmd: |
if [ "$1" == "y" ]; then
docker compose -f $DOCKER_COMPOSE down --volumes
else
ahoy confirm "Running this command will destroy your current site, database and build? Are you sure you didn't mean ahoy stop?" &&
# Run this if confirm returns true
docker compose -f $DOCKER_COMPOSE down --volumes ||
# Run this if confirm returns false
echo "OK, probably a wise choice..."
fi
build:
usage: Build project.
cmd: |
if [ "$DOCKER_COMPOSE" = "docker-compose.dev.yml" ]; then
CKAN_CONTAINER_NAME=ckan-dev
WORKER_CONTAINER_NAME=ckan-dev-worker
fi
docker compose -f $DOCKER_COMPOSE build "$@"
cli:
usage: Start a shell inside container.
cmd: |
if [ "$DOCKER_COMPOSE" = "docker-compose.dev.yml" ]; then
CKAN_CONTAINER_NAME=ckan-dev
fi
docker compose -f $DOCKER_COMPOSE exec ${1:-$CKAN_CONTAINER_NAME} sh
run:
usage: Run command inside container.
cmd: |
if [[ $# -eq 2 ]]; then
SERVICE=$1
COMMAND=$2
else
if [ "$DOCKER_COMPOSE" = "docker-compose.dev.yml" ]; then
CKAN_CONTAINER_NAME=ckan-dev
fi
SERVICE=$CKAN_CONTAINER_NAME
COMMAND=$1
fi;
docker compose -f $DOCKER_COMPOSE exec -T $SERVICE sh -c "$COMMAND"
logs:
usage: Show Docker logs.
cmd: |
TAIL=100
if [[ $# -eq 2 ]]; then
SERVICE=$1
TAIL=$2
else
SERVICE=$1
fi;
docker compose -f $DOCKER_COMPOSE logs -f --tail=$TAIL $SERVICE
ps:
usage: List running Docker containers.
cmd: docker compose -f $DOCKER_COMPOSE ps
restart:
usage: Restart Docker containers.
cmd: |
docker compose -f $DOCKER_COMPOSE restart "$@"
ahoy info;
stop:
usage: Stop Docker containers.
cmd: docker compose -f $DOCKER_COMPOSE stop "$@"
attach:
usage: Attach to a running container
cmd: docker attach $(docker compose -f $DOCKER_COMPOSE ps -q "$@")
recreate:
usage: Recreate a local container | ahoy recreate ckan
cmd: |
docker compose -f $DOCKER_COMPOSE up -d --force-recreate --no-deps --build "${1}"
info:
usage: Print information about this project.
cmd: |
if [ "$DOCKER_COMPOSE" = "docker-compose.dev.yml" ]; then
SITE_URL="http://localhost:${CKAN_PORT_HOST}"
else
SITE_URL="https://localhost:${NGINX_SSLPORT_HOST}"
fi
echo "Site local URL : ${SITE_URL}"
if [ "$DOCKER_COMPOSE" = "docker-compose.dev.yml" ]; then
echo "CKAN DB port on host : $(docker port $(docker compose -f $DOCKER_COMPOSE ps -q $POSTGRESQL_CONTAINER_NAME) 5432 | cut -d : -f 2)"
echo "SOLR port on host : $(docker port $(docker compose -f $DOCKER_COMPOSE ps -q $SOLR_CONTAINER_NAME) 8983 | cut -d : -f 2)"
fi
db-import:
usage: Pipe in a postgres dump file. `ahoy db-import local.dump`
cmd: |
if [ -e "$@" ] ; then
if [ "$DOCKER_COMPOSE" = "docker-compose.dev.yml" ]; then
CKAN_CONTAINER_NAME=ckan-dev
fi
SERVICE=$CKAN_CONTAINER_NAME
# Clean the database
ahoy run "ckan db clean --yes"
# Import the database
docker compose -f $DOCKER_COMPOSE exec -T $POSTGRESQL_CONTAINER_NAME sh -c 'pg_restore -U $CKAN_DB_USER -d $CKAN_DB --clean --if-exists -v --no-owner --no-privileges' < "$@"
# Initialise plugin tables
docker compose -f $DOCKER_COMPOSE exec -T $CKAN_CONTAINER_NAME sh -c 'rm /tmp/container_ready && export CKAN__PLUGINS=$(grep "^ckan\.plugins" $APP_DIR/config/dbca.ini | cut -d"=" -f2) && bash /docker-entrypoint.d/02_setup_dbca.sh'
# Rebuild the Solr index
ahoy reindex-solr
else
echo "Provided sql file" "$@" "does not exist"
fi
import-db:
usage: Import the DB from an environment into your local dev environment | ahoy import-db ENVIRONMENT
cmd: |
source ./scripts/messages.sh
#
# Check the correct arguments are supplied
#
if [[ "$1" != "staging" ]] && [[ "$1" != "production" ]]; then
error "Invalid environment. Please use 'staging' or 'production'. eg ahoy import-db ENVIRONMENT"
exit 1
fi
ENVIRONMENT=$1
info "Dumping DB from $ENVIRONMENT"
if [[ "$1" == "staging" ]]; then
docker compose -f $DOCKER_COMPOSE exec -T $POSTGRESQL_CONTAINER_NAME sh -c 'cd /tmp && pg_dump "postgresql://'"$AZURE_POSTGRES_STAGING_USER"':'"$AZURE_POSTGRES_STAGING_PASSWORD"'@'"$AZURE_POSTGRES_STAGING_HOST"'/'"$AZURE_POSTGRES_STAGING_DB"'" --format=custom -v > latest.dump'
else
docker compose -f $DOCKER_COMPOSE exec -T $POSTGRESQL_CONTAINER_NAME sh -c 'cd /tmp && pg_dump "postgresql://'"$AZURE_POSTGRES_PROD_USER"':'"$AZURE_POSTGRES_PROD_PASSWORD"'@'"$AZURE_POSTGRES_PROD_HOST"'/'"$AZURE_POSTGRES_PROD_DB"'" --exclude-table=dbca_spatial --format=custom -v > latest.dump'
fi
info "Importing DB from $ENVIRONMENT"
docker compose -f $DOCKER_COMPOSE exec -T $POSTGRESQL_CONTAINER_NAME sh -c 'pg_restore -U $CKAN_DB_USER -d $CKAN_DB --clean --if-exists --no-owner --no-privileges -v < /tmp/latest.dump'
info "Rebuilding Solr Index"
ahoy reindex-solr
success "Database import successful"
reindex-solr:
usage: Re-runs the Solr index, e.g. after running `db-import` command
cmd: ahoy run "ckan search-index rebuild"
db-dump:
usage: Dump data out into a file. `ahoy db-dump local.dump`
cmd: docker compose -f $DOCKER_COMPOSE exec -T $POSTGRESQL_CONTAINER_NAME sh -c 'pg_dump -U $CKAN_DB_USER -d $CKAN_DB --format=custom -v' > "$@"
confirm:
cmd: read -r -p "${@} [y/N] " response; [ ${response} = "y" ]
hide: true
generate-extension:
usage: Generates a new CKAN extension into the src directory
cmd: ahoy run cli 'ckan generate extension -o ${SRC_DIR}'
open:
usage: Open the site in your default browser
cmd: |
if [ "$DOCKER_COMPOSE" = "docker-compose.dev.yml" ]; then
SITE_URL="http://localhost:${CKAN_PORT_HOST}"
else
SITE_URL="http://localhost:${NGINX_SSLPORT_HOST}"
fi
open $SITE_URL
download-ckan-logs:
usage: Download CKAN logs
cmd: |
if [ -z "$AZURE_FILE_SHARE_URL" ] || [ -z "$AZURE_FILE_SHARE_SAS_TOKEN" ]; then
echo "AZURE_FILE_SHARE_URL or AZURE_FILE_SHARE_SAS_TOKEN is not set"
exit 1
fi
echo "Downloading ckan_logs from:$AZURE_FILE_SHARE_URL"
LOG_FILE="ckan-worker.log"
echo "Downloading $LOG_FILE"
FULL_URL="$AZURE_FILE_SHARE_URL/ckan_logs/$LOG_FILE?$AZURE_FILE_SHARE_SAS_TOKEN"
curl -L -o dbca/ckan_logs/$LOG_FILE "$FULL_URL"
LOG_FILE="supervisord.log"
echo "Downloading $LOG_FILE"
FULL_URL="$AZURE_FILE_SHARE_URL/ckan_logs/$LOG_FILE?$AZURE_FILE_SHARE_SAS_TOKEN"
curl -L -o dbca/ckan_logs/$LOG_FILE "$FULL_URL"
echo "CKAN logs downloaded to dbca/ckan_logs"