Skip to content

Commit e2825a0

Browse files
authored
Merge pull request ckan#25 from qld-gov-au/QOL-9055-py3-amazon-linux-2
QOL-9055 Add Python 3 compatibility and continuous integration testing
2 parents 8bc6854 + 6dc87cd commit e2825a0

71 files changed

Lines changed: 1193 additions & 1085 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.ahoy.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ commands:
8080
usage: Install a site.
8181
cmd: |
8282
ahoy title "Installing a fresh site"
83-
ahoy cli "./scripts/init.sh"
83+
ahoy cli '$APP_DIR/scripts/init.sh'
8484
8585
clean:
8686
usage: Remove containers and all build files.
@@ -109,6 +109,13 @@ commands:
109109
ahoy cli "flake8 ${@:-ckanext}" || \
110110
[ "${ALLOW_LINT_FAIL:-0}" -eq 1 ]
111111
112+
copy-local-files:
113+
usage: Update files from local repo.
114+
cmd: |
115+
docker cp . $(docker-compose ps -q ckan):/app/
116+
docker cp .docker/scripts/ckan_cli $(docker-compose ps -q ckan):/app/ckan/default/bin/
117+
ahoy cli 'chmod u+x $VENV_DIR/bin/ckan_cli; cp .docker/test.ini $CKAN_INI'
118+
112119
test-unit:
113120
usage: Run unit tests.
114121
cmd: |
@@ -120,7 +127,7 @@ commands:
120127
cmd: |
121128
ahoy start-ckan-job-worker &
122129
sleep 5 &&
123-
ahoy cli "behave ${*:-test/features} --tags=-format_autocomplete" || \
130+
ahoy cli "behave -k ${*:-test/features} --tags=-format_autocomplete" || \
124131
[ "${ALLOW_BDD_FAIL:-0}" -eq 1 ]
125132
ahoy stop-ckan-job-worker
126133

.circleci/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ jobs:
2323
at: /workspace
2424
- checkout
2525
- *step_setup_remote_docker
26-
- run: .circleci/build.sh
26+
- run:
27+
command: .circleci/build.sh
28+
environment:
29+
CKAN_VERSION: ckan-2.9.5
2730
- run: .circleci/test.sh
2831
- run:
2932
name: Process artifacts
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ FROM amazeeio/python:2.7-ckan-21.8.0
22

33
ARG SITE_URL=http://ckan:3000/
44
ARG CKAN_REPO=ckan/ckan
5-
ARG CKAN_VERSION=2.8.8
5+
ARG CKAN_VERSION=ckan-2.9.5
6+
ENV PYTHON_VERSION=py2
67
ENV SITE_URL="${SITE_URL}"
78
ENV VENV_DIR=/app/ckan/default
89
ENV APP_DIR=/app
@@ -11,16 +12,16 @@ ENV CKAN_INI=/app/ckan/default/production.ini
1112
WORKDIR "${APP_DIR}"
1213

1314
ENV DOCKERIZE_VERSION v0.6.1
14-
RUN echo 'http://dl-4.alpinelinux.org/alpine/v3.11/main' >> /etc/apk/repositories && apk add --no-cache curl build-base \
15-
&& curl -s -L -O https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz \
15+
RUN apk add --no-cache curl build-base postgresql-client \
16+
&& curl -sLO https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz \
1617
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz \
1718
&& rm dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz
1819

1920
# Install CKAN.
2021

2122
RUN . ${VENV_DIR}/bin/activate \
2223
&& pip install setuptools==36.1 \
23-
&& pip install -e "git+https://github.com/${CKAN_REPO}.git@ckan-${CKAN_VERSION}#egg=ckan" \
24+
&& pip install -e "git+https://github.com/${CKAN_REPO}.git@${CKAN_VERSION}#egg=ckan" \
2425
&& sed -i "s/psycopg2==2.4.5/psycopg2==2.7.7/g" "${VENV_DIR}/src/ckan/requirements.txt" \
2526
&& ((test -f "${VENV_DIR}/src/ckan/requirements-py2.txt" && \
2627
pip install -r "${VENV_DIR}/src/ckan/requirements-py2.txt") || \
@@ -32,15 +33,13 @@ RUN . ${VENV_DIR}/bin/activate \
3233

3334
COPY .docker/test.ini $CKAN_INI
3435

35-
# Add current extension and files.
3636
COPY . ${APP_DIR}/
3737

3838
COPY .docker/scripts ${APP_DIR}/scripts
3939

4040
COPY .docker/scripts/ckan_cli ${VENV_DIR}/bin/
4141

42-
RUN chmod +x ${APP_DIR}/scripts/*.sh\
43-
&& chmod +x ${VENV_DIR}/bin/ckan_cli
42+
RUN chmod +x ${APP_DIR}/scripts/*.sh ${VENV_DIR}/bin/ckan_cli
4443

4544
# Init current extension.
4645
RUN ${APP_DIR}/scripts/init-ext.sh

.docker/Dockerfile-py3.ckan

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM amazeeio/python:3.8-22.7.0
2+
3+
ARG SITE_URL=http://ckan:3000/
4+
ARG CKAN_REPO=ckan/ckan
5+
ARG CKAN_VERSION=ckan-2.9.5
6+
ENV PYTHON_VERSION=py3
7+
ENV SITE_URL="${SITE_URL}"
8+
ENV VENV_DIR=/app/ckan/default
9+
ENV APP_DIR=/app
10+
ENV CKAN_INI=/app/ckan/default/production.ini
11+
12+
WORKDIR "${APP_DIR}"
13+
14+
ENV DOCKERIZE_VERSION v0.6.1
15+
RUN apk add --no-cache curl build-base git libxml2-dev libxslt-dev postgresql postgresql-client postgresql-dev \
16+
&& curl -sLO https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz \
17+
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz \
18+
&& rm dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz
19+
20+
# Install CKAN.
21+
22+
RUN mkdir -p ${VENV_DIR} \
23+
&& virtualenv ${VENV_DIR} \
24+
&& . ${VENV_DIR}/bin/activate \
25+
&& pip install setuptools==44.1.0 \
26+
&& pip install -e "git+https://github.com/${CKAN_REPO}.git@${CKAN_VERSION}#egg=ckan" \
27+
&& pip install -r "${VENV_DIR}/src/ckan/requirements.txt" \
28+
&& ln -s "${VENV_DIR}/src/ckan/who.ini" "${VENV_DIR}/who.ini" \
29+
&& deactivate \
30+
&& ln -s ${APP_DIR}/ckan /usr/lib/ckan \
31+
&& fix-permissions ${APP_DIR}/ckan
32+
33+
COPY .docker/test.ini $CKAN_INI
34+
35+
COPY . ${APP_DIR}/
36+
37+
COPY .docker/scripts ${APP_DIR}/scripts
38+
39+
COPY .docker/scripts/ckan_cli ${VENV_DIR}/bin/
40+
41+
RUN chmod +x ${APP_DIR}/scripts/*.sh ${VENV_DIR}/bin/ckan_cli
42+
43+
# Init current extension.
44+
RUN ${APP_DIR}/scripts/init-ext.sh
45+
46+
ENTRYPOINT ["/sbin/tini", "--", "/lagoon/entrypoints.sh"]
47+
CMD ["/app/scripts/serve.sh"]

.docker/scripts/ckan_cli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ else
5757
fi
5858

5959
if [ "$COMMAND" = "ckan" ]; then
60-
echo "Using 'ckan' command from $ENV_DIR with config ${CKAN_INI}..." >&2
6160
# adjust args to match ckan expectations
6261
COMMAND=$(echo "$1" | sed -e 's/create-test-data/seed/')
62+
echo "Using 'ckan' command from $ENV_DIR with config ${CKAN_INI} to run $COMMAND..." >&2
6363
shift
6464
exec $ENV_DIR/ckan -c ${CKAN_INI} $COMMAND "$@" $CLICK_ARGS
6565
elif [ "$COMMAND" = "paster" ]; then
66-
echo "Using 'paster' command from $ENV_DIR with config ${CKAN_INI}..." >&2
6766
# adjust args to match paster expectations
6867
COMMAND=$1
68+
echo "Using 'paster' command from $ENV_DIR with config ${CKAN_INI} to run $COMMAND..." >&2
6969
shift
7070
if [ "$1" = "show" ]; then shift; fi
7171
exec $ENV_DIR/paster --plugin=$PASTER_PLUGIN $COMMAND "$@" -c ${CKAN_INI}

.docker/scripts/create-test-data.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
#
55
set -e
66

7+
CKAN_USER_NAME="${CKAN_USER_NAME:-admin}"
8+
CKAN_DISPLAY_NAME="${CKAN_DISPLAY_NAME:-Administrator}"
9+
CKAN_USER_EMAIL="${CKAN_USER_EMAIL:-admin@localhost}"
710
CKAN_ACTION_URL=http://ckan:3000/api/action
811

912
if [ "$VENV_DIR" != "" ]; then
1013
. ${VENV_DIR}/bin/activate
1114
fi
1215

13-
CKAN_USER_NAME="${CKAN_USER_NAME:-admin}"
14-
CKAN_DISPLAY_NAME="${CKAN_DISPLAY_NAME:-Administrator}"
15-
CKAN_USER_EMAIL="${CKAN_USER_EMAIL:-admin@localhost}"
16-
1716
add_user_if_needed () {
1817
echo "Adding user '$2' ($1) with email address [$3]"
1918
ckan_cli user show "$1" | grep "$1" || ckan_cli user add "$1"\
@@ -25,7 +24,6 @@ add_user_if_needed () {
2524
add_user_if_needed "$CKAN_USER_NAME" "$CKAN_DISPLAY_NAME" "$CKAN_USER_EMAIL"
2625
ckan_cli sysadmin add "${CKAN_USER_NAME}"
2726

28-
# We know the "admin" sysadmin account exists, so we'll use her API KEY to create further data
2927
API_KEY=$(ckan_cli user show "${CKAN_USER_NAME}" | tr -d '\n' | sed -r 's/^(.*)apikey=(\S*)(.*)/\2/')
3028
if [ "$API_KEY" = "None" ]; then
3129
echo "No API Key found on ${CKAN_USER_NAME}, generating API Token..."
@@ -45,17 +43,18 @@ add_user_if_needed test_org_admin "Test Admin" test_org_admin@localhost
4543
add_user_if_needed test_org_editor "Test Editor" test_org_editor@localhost
4644
add_user_if_needed test_org_member "Test Member" test_org_member@localhost
4745

48-
echo "Creating ${TEST_ORG_TITLE} Organisation:"
46+
echo "Creating ${TEST_ORG_TITLE} organisation:"
4947

5048
TEST_ORG=$( \
5149
curl -LsH "Authorization: ${API_KEY}" \
5250
--data "name=${TEST_ORG_NAME}&title=${TEST_ORG_TITLE}" \
5351
${CKAN_ACTION_URL}/organization_create
5452
)
53+
echo "${TEST_ORG_TITLE} organisation is: ${TEST_ORG}"
5554

56-
TEST_ORG_ID=$(echo $TEST_ORG | sed -r 's/^(.*)"id": "(.*)",(.*)/\2/')
55+
TEST_ORG_ID=$(echo $TEST_ORG | python $APP_DIR/scripts/extract-id.py)
5756

58-
echo "Assigning test users to ${TEST_ORG_TITLE} Organisation:"
57+
echo "Assigning test users to '${TEST_ORG_TITLE}' organisation (${TEST_ORG_ID}):"
5958

6059
curl -LsH "Authorization: ${API_KEY}" \
6160
--data "id=${TEST_ORG_ID}&object=test_org_admin&object_type=user&capacity=admin" \

.docker/scripts/doctor.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ main() {
7575
# - container:amazeeio-ssh-agent
7676
# ```
7777
# 4. When CLI container starts, the volume is mounted and an entrypoint script
78-
# adds SHH key into agent.
78+
# adds SSH key into agent.
7979
# @see https://github.com/amazeeio/lagoon/blob/master/images/php/cli/10-ssh-agent.sh
8080
#
8181
# Running `ssh-add -L` within CLI container should show that the SSH key

.docker/scripts/extract-id.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# encoding: utf-8
2+
import json
3+
import sys
4+
5+
print(json.loads(sys.stdin.read())['result']['id'])

.docker/scripts/init-ext.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ set -e
77
if [ "$VENV_DIR" != "" ]; then
88
. ${VENV_DIR}/bin/activate
99
fi
10-
pip install -r "requirements.txt"
11-
pip install -r "dev-requirements.txt"
12-
if [ "$CKAN_VERSION" = "2.8.8" ]; then
10+
pip install -r "requirements.txt" -r "dev-requirements.txt"
11+
if [ "$CKAN_VERSION" = "ckan-2.8.8" ]; then
1312
pip install -r "dev-requirements-2.8.txt"
1413
fi
1514
python setup.py develop

.docker/test.ini

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,6 @@ ckan.datastore.default_fts_index_method = gist
5555
## Site Settings.
5656
ckan.site_url = http://ckan:3000/
5757

58-
## Authorization Settings
59-
60-
ckan.auth.anon_create_dataset = false
61-
ckan.auth.create_unowned_dataset = false
62-
ckan.auth.create_dataset_if_not_in_organization = false
63-
ckan.auth.user_create_groups = false
64-
ckan.auth.user_create_organizations = false
65-
ckan.auth.user_delete_groups = true
66-
ckan.auth.user_delete_organizations = true
67-
ckan.auth.create_user_via_api = false
68-
ckan.auth.create_user_via_web = true
69-
ckan.auth.roles_that_cascade_to_sub_groups = admin
70-
ckan.auth.public_user_details = False
71-
72-
7358
## Search Settings
7459

7560
ckan.site_id = default
@@ -97,7 +82,6 @@ ckan.redis.url = redis://redis:6379
9782
# Add ``datapusher`` to enable DataPusher
9883
# Add ``resource_proxy`` to enable resource proxying and get around the
9984
# same origin policy
100-
# @todo:setup Cleanup the list to use only required plugins.
10185
ckan.plugins = validation scheming_datasets
10286

10387
scheming.dataset_schemas = ckanext.validation.examples:ckan_default_schema.json

0 commit comments

Comments
 (0)