Skip to content

Commit

Permalink
Refactored OpenFisca rules as code to download tagged versions of the…
Browse files Browse the repository at this point in the history
… Country Template instead of manually managing Country Template package and rules
  • Loading branch information
MarkCalvert committed Jan 24, 2024
1 parent ece51de commit 6f6b17b
Show file tree
Hide file tree
Showing 46 changed files with 73 additions and 1,484 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
name: Deploy images

on:
- push

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
delploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker image
id: meta_openfisca
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./images/rules-as-code
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta_openfisca.outputs.tags }}
34 changes: 17 additions & 17 deletions images/rules-as-code/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
FROM uselagoon/python-3.9:latest as build
FROM uselagoon/python-3.11:latest

WORKDIR /app/

RUN apk add gcc libc-dev g++ linux-headers yaml-dev
RUN pip wheel --wheel-dir=/app/wheel numpy==1.20.* numexpr==2.8.* psutil PyYAML


FROM uselagoon/python-3.9:latest
ENV COUNTRY_TEMPLATE_VERSION=6.0.1
ENV OPENFISCA_CORE_VERSION=41.4.1
ENV COUNTRY_NAME=rules

EXPOSE 3000
WORKDIR /app

ARG PROJECT_NAME=rule
COPY openfisca_$PROJECT_NAME /app/openfisca_$PROJECT_NAME
COPY README.md setup.cfg setup.py /app/
# Install OpenFisca-Core dependencies
RUN apk add build-base linux-headers yaml-dev

WORKDIR /app/
# Install OpenFisca-Core
RUN pip install OpenFisca-Core[web-api]==$OPENFISCA_CORE_VERSION

COPY --from=build /app/ /app/
COPY README.md /app/openfisca_$PROJECT_NAME
RUN apk add gcc libc-dev g++ linux-headers yaml-dev libffi-dev
RUN pip install --no-index --find-links=/app/wheel numpy numexpr psutil PyYAML
RUN pip install -e /app
# Install country-template
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

# Copy bootstrap.sh to country-template and run it
COPY bootstrap.sh /app
RUN . /app/bootstrap.sh

ENTRYPOINT ["openfisca", "serve", "--bind", "0.0.0.0:3000"]
23 changes: 23 additions & 0 deletions images/rules-as-code/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/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 .
41 changes: 0 additions & 41 deletions images/rules-as-code/openfisca_rules/__init__.py

This file was deleted.

64 changes: 0 additions & 64 deletions images/rules-as-code/openfisca_rules/entities.py

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions images/rules-as-code/openfisca_rules/reforms/__init__.py

This file was deleted.

Loading

0 comments on commit 6f6b17b

Please sign in to comment.