Skip to content

Commit

Permalink
Upgraded OpenFisca versions to the latest
Browse files Browse the repository at this point in the history
Update Dockerfile and scripts for OpenFisca configuration and setup
  • Loading branch information
MarkCalvert committed Nov 12, 2024
1 parent 2bf728d commit 2904540
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 32 deletions.
18 changes: 9 additions & 9 deletions images/rules-as-code/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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

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
Expand All @@ -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"]
23 changes: 0 additions & 23 deletions images/rules-as-code/bootstrap.sh

This file was deleted.

39 changes: 39 additions & 0 deletions images/rules-as-code/first-time-setup.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 2904540

Please sign in to comment.