diff --git a/images/rules-as-code/Dockerfile b/images/rules-as-code/Dockerfile index 55229f9..3d07cdb 100644 --- a/images/rules-as-code/Dockerfile +++ b/images/rules-as-code/Dockerfile @@ -1,8 +1,8 @@ FROM uselagoon/python-3.11:latest -ENV COUNTRY_TEMPLATE_VERSION=6.0.1 -ENV OPENFISCA_CORE_VERSION=41.4.3 -ENV COUNTRY_NAME=rules +ENV COUNTRY_TEMPLATE_VERSION=7.1.8 +ENV OPENFISCA_CORE_VERSION=43.2.2 +ENV JURISDICTION_NAME=rules # tells the local development environment on which port we are running ENV LAGOON_LOCALDEV_HTTP_PORT=8800 @@ -10,7 +10,7 @@ EXPOSE 8800 WORKDIR /app # Install OpenFisca-Core dependencies -RUN apk add build-base linux-headers yaml-dev +RUN apk add build-base linux-headers yaml-dev bash git # Install OpenFisca-Core RUN pip install OpenFisca-Core[web-api]==$OPENFISCA_CORE_VERSION @@ -19,10 +19,10 @@ RUN pip install OpenFisca-Core[web-api]==$OPENFISCA_CORE_VERSION ADD https://github.com/openfisca/country-template/archive/refs/tags/$COUNTRY_TEMPLATE_VERSION.tar.gz /app RUN tar -xzf /app/$COUNTRY_TEMPLATE_VERSION.tar.gz -C /app && \ rm /app/$COUNTRY_TEMPLATE_VERSION.tar.gz && \ - mv /app/country-template-$COUNTRY_TEMPLATE_VERSION /app/country-template + mv /app/country-template-$COUNTRY_TEMPLATE_VERSION /app/openfisca-$JURISDICTION_NAME -# Copy bootstrap.sh to country-template and run it -COPY bootstrap.sh /app -RUN . /app/bootstrap.sh +# Copy first-time-setup.sh to country-template and run it +COPY first-time-setup.sh /app/ +RUN . /app/first-time-setup.sh -CMD ["openfisca", "serve", "--bind", "0.0.0.0:8800"] +CMD ["openfisca", "serve", "--country-package", "openfisca_rules", "--bind", "0.0.0.0:8800"] diff --git a/images/rules-as-code/bootstrap.sh b/images/rules-as-code/bootstrap.sh deleted file mode 100644 index 9036cc5..0000000 --- a/images/rules-as-code/bootstrap.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -set -e - -lowercase_country_name=$(echo $COUNTRY_NAME | tr '[:upper:]' '[:lower:]') - -mv country-template openfisca-$lowercase_country_name -cd openfisca-$lowercase_country_name -all_module_files=`find openfisca_country_template -type f ! -name "*.DS_Store"` - -set -x - -# Use intermediate backup files (`-i`) with a weird syntax due to lack of portable 'no backup' option. See https://stackoverflow.com/q/5694228/594053. -sed -i.template "s|country_template|$lowercase_country_name|g" setup.py setup.cfg Makefile MANIFEST.in $all_module_files -sed -i.template "s|Country-Template|$COUNTRY_NAME|g" setup.py $all_module_files -find . -name "*.template" -type f -delete - -set +x - -mv openfisca_country_template openfisca_$lowercase_country_name - -# Install OpenFisca country template -pip install -e . \ No newline at end of file diff --git a/images/rules-as-code/first-time-setup.sh b/images/rules-as-code/first-time-setup.sh new file mode 100644 index 0000000..d7d8b82 --- /dev/null +++ b/images/rules-as-code/first-time-setup.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# Cut down updated version of the original script https://github.com/openfisca/country-template/blob/main/first-time-setup.sh + +set -e +GREEN='\033[0;32m' +PURPLE='\033[1;35m' +YELLOW='\033[0;33m' +BLUE='\033[1;34m' +JURISDICTION_NAME=${JURISDICTION_NAME:-$COUNTRY_NAME} # backwards compatibility + +lowercase_jurisdiction_name=$(echo $JURISDICTION_NAME | tr '[:upper:]' '[:lower:]' | sed 'y/āáǎàēéěèīíǐìōóǒòūúǔùǖǘǚǜĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛ/aaaaeeeeiiiioooouuuuüüüüAAAAEEEEIIIIOOOOUUUUÜÜÜÜ/') +NO_SPACES_JURISDICTION_LABEL=$(echo $lowercase_jurisdiction_name | sed -r 's/[ ]+/_/g') # allow for hyphens to be used in jurisdiction names +SNAKE_CASE_JURISDICTION=$(echo $NO_SPACES_JURISDICTION_LABEL | sed -r 's/[-]+/_/g') # remove hyphens for use in Python +package_name="openfisca_$SNAKE_CASE_JURISDICTION" + +echo -e "${PURPLE}Jurisdiction title set to: \033[0m${BLUE}$JURISDICTION_NAME\033[0m" +# Removes hyphens for python environment +echo -e "${PURPLE}Jurisdiction Python label: \033[0m${BLUE}$SNAKE_CASE_JURISDICTION\033[0m" + +cd openfisca-$NO_SPACES_JURISDICTION_LABEL + +all_module_files=`find openfisca_country_template -type f ! -name "*.DS_Store"` +echo -e "${PURPLE}* ${PURPLE}Replace default country_template references\033[0m" +# Use intermediate backup files (`-i`) with a weird syntax due to lack of portable 'no backup' option. See https://stackoverflow.com/q/5694228/594053. +sed -i.template "s|openfisca-country_template|openfisca-$NO_SPACES_JURISDICTION_LABEL|g" README.md Makefile pyproject.toml CONTRIBUTING.md +sed -i.template "s|country_template|$SNAKE_CASE_JURISDICTION|g" README.md pyproject.toml Makefile MANIFEST.in $all_module_files +sed -i.template "s|Country-Template|$JURISDICTION_NAME|g" README.md pyproject.toml .github/PULL_REQUEST_TEMPLATE.md CONTRIBUTING.md + +echo -e "${PURPLE}* ${PURPLE}Prepare \033[0m${BLUE}pyproject.toml\033[0m" +sed -i.template 's|:: 5 - Production/Stable|:: 1 - Planning|g' pyproject.toml +sed -i.template 's|^version = "[0-9.]*"|version = "0.0.1"|g' pyproject.toml +find . -name "*.template" -type f -delete + +mv openfisca_country_template $package_name + +# Install OpenFisca country template +pip install -e . + +echo -e "${YELLOW}*\033[0m Bootstrap complete for $package_name.\033[0m" \ No newline at end of file