From 288f9e66359693c13abdf4a4034b90f77b244d25 Mon Sep 17 00:00:00 2001 From: Oisin Date: Sat, 17 Jan 2026 20:57:54 +0000 Subject: [PATCH 1/3] Parameterised n_applications logic with cons default of 20k --- generator/cons.py | 1 + generator/main.py | 3 ++- generator/utilities/commandline_interface.py | 4 ++++ generator/utilities/input_error_handling.py | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/generator/cons.py b/generator/cons.py index 25fb9e1..d3839d2 100644 --- a/generator/cons.py +++ b/generator/cons.py @@ -43,6 +43,7 @@ default_n_users = 100 default_use_random_seed = 0 default_n_itr = 1 +default_n_applications = 20000 default_registration_start_date = (date_today - datetime.timedelta(days=731)).strftime(date_date_strftime) default_registration_end_date = (date_today - datetime.timedelta(days=366)).strftime(date_date_strftime) default_transaction_start_date = (date_today - datetime.timedelta(days=365)).strftime(date_date_strftime) diff --git a/generator/main.py b/generator/main.py index 6c1a101..eabed33 100644 --- a/generator/main.py +++ b/generator/main.py @@ -35,7 +35,7 @@ ( input_params_dict['n_users'], None if input_params_dict['use_random_seed'] == 0 else itr, - 20000, + input_params_dict['n_applications'], input_params_dict['registration_start_date'], input_params_dict['registration_end_date'], input_params_dict['transaction_start_date'], @@ -49,6 +49,7 @@ gen_random_telecom_data( n_users=input_params_dict['n_users'], random_seed=input_params_dict['use_random_seed'], + n_applications=input_params_dict['n_applications'], registration_start_date=input_params_dict['registration_start_date'], registration_end_date=input_params_dict['registration_end_date'], transaction_start_date=input_params_dict['transaction_start_date'], diff --git a/generator/utilities/commandline_interface.py b/generator/utilities/commandline_interface.py index 0b72757..515ec43 100644 --- a/generator/utilities/commandline_interface.py +++ b/generator/utilities/commandline_interface.py @@ -21,6 +21,8 @@ def commandline_interface() -> Dict[str, object]: Use a set random seed for reproducible results; must be either 0 or 1. n_itr : int Number of iterations to run. + n_applications : int + The number of applications to generate random telecom payments data for. registration_start_date : str The start date for registrations. registration_end_date : str @@ -41,6 +43,7 @@ def commandline_interface() -> Dict[str, object]: parser.add_argument("--n_users", action="store", dest="n_users", type=int, default=cons.default_n_users, help="Integer, the number of users to generate random telecom payments data for",) parser.add_argument("--use_random_seed", action="store", dest="use_random_seed", type=int, default=cons.default_use_random_seed, choices=[0, 1], help="Integer, use a set random seed for reproducible results; must be either 0 or 1",) parser.add_argument("--n_itr", action="store", dest="n_itr", type=int, default=cons.default_n_itr, help="Integer, number of iterations to run",) + parser.add_argument("--n_applications", action="store", dest="n_applications", type=int, default=cons.default_n_applications, help="Integer, the number of applications to generate random telecom payments data for",) parser.add_argument("--registration_start_date", action="store", dest="registration_start_date", type=str, default=cons.default_registration_start_date, help="String, the start date for registrations",) parser.add_argument("--registration_end_date", action="store", dest="registration_end_date", type=str, default=cons.default_registration_end_date, help="String, the end date for registrations",) parser.add_argument("--transaction_start_date", action="store", dest="transaction_start_date", type=str, default=cons.default_transaction_start_date, help="String, the start date for transactions",) @@ -53,6 +56,7 @@ def commandline_interface() -> Dict[str, object]: input_params_dict["n_users"] = args.n_users input_params_dict["use_random_seed"] = args.use_random_seed input_params_dict["n_itr"] = args.n_itr + input_params_dict["n_applications"] = args.n_applications input_params_dict["registration_start_date"] = args.registration_start_date input_params_dict["registration_end_date"] = args.registration_end_date input_params_dict["transaction_start_date"] = args.transaction_start_date diff --git a/generator/utilities/input_error_handling.py b/generator/utilities/input_error_handling.py index 20c93cc..6ebb7ab 100644 --- a/generator/utilities/input_error_handling.py +++ b/generator/utilities/input_error_handling.py @@ -29,3 +29,6 @@ def input_error_handling( # check if the number of iterations is greater than or equal to 1 if not ((input_params_dict["n_itr"] >= 1) and (isinstance(input_params_dict["n_itr"], int))): raise ValueError(f"Invalid n_itr parameter value {input_params_dict['n_itr']}; must be an integer >= 1.") + # check if the number of applications is positive + if not ((input_params_dict["n_applications"] >= 1) and (isinstance(input_params_dict["n_applications"], int))): + raise ValueError(f"Invalid n_applications parameter value {input_params_dict['n_applications']}; must be a integer >= 1.") From cebc90a0a920c754bee19715b072e235446eb8d3 Mon Sep 17 00:00:00 2001 From: Oisin Date: Sat, 17 Jan 2026 21:18:06 +0000 Subject: [PATCH 2/3] Added unified git action pipelines --- .github/workflows/deploy-main-push.yml | 88 +++++++++++++++++++ ...unittest-dev.yml => dev-pull-requests.yml} | 23 +++-- .github/workflows/dockerhub-main-push.yml | 26 ------ .github/workflows/unittest-main-pr.yml | 32 ------- .github/workflows/unittest-main-push.yml | 32 ------- 5 files changed, 104 insertions(+), 97 deletions(-) create mode 100644 .github/workflows/deploy-main-push.yml rename .github/workflows/{unittest-dev.yml => dev-pull-requests.yml} (64%) delete mode 100644 .github/workflows/dockerhub-main-push.yml delete mode 100644 .github/workflows/unittest-main-pr.yml delete mode 100644 .github/workflows/unittest-main-push.yml diff --git a/.github/workflows/deploy-main-push.yml b/.github/workflows/deploy-main-push.yml new file mode 100644 index 0000000..a2b250b --- /dev/null +++ b/.github/workflows/deploy-main-push.yml @@ -0,0 +1,88 @@ +name: Deployment Workflow + +on: + push: + branches: [ main ] + +jobs: + + release-tag: + runs-on: ubuntu-latest + steps: + - name: Tag Repo + uses: richardsimko/update-tag@v1 + with: + tag_name: ${{ vars.REPO_TAG }} + env: + GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} + + trivy-fs-scan: + needs: release-tag + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run Trivy vulnerability scanner in fs mode + uses: aquasecurity/trivy-action@master + with: + scan-type: 'fs' + scan-ref: '.' + exit-code: '1' + + python-unittests: + needs: release-tag + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.12"] + steps: + - uses: actions/checkout@v4 + - name: Set environment variable + run: echo "GITHUB_ACTIONS_UNITTEST_FLAG=1" >> $GITHUB_ENV + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install python dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Test with unittest + run: | + python -m unittest discover ./generator/unittests/utilities + python -m unittest discover ./generator/unittests/objects + python -m unittest discover ./generator/unittests/app + + dockerhub-image-push: + needs: [trivy-fs-scan, python-unittests] + runs-on: ubuntu-latest + steps: + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: true + tags: ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKERHUB_REPO }}:${{ vars.DOCKERHUB_TAG }} + + trivy-image-scan: + needs: dockerhub-image-push + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run Trivy vulnerability scanner + uses: aquasecurity/trivy-action@master + with: + image-ref: ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKERHUB_REPO }}:${{ vars.DOCKERHUB_TAG }} + format: 'table' + exit-code: '1' + ignore-unfixed: true + vuln-type: 'os,library' + severity: 'CRITICAL,HIGH' \ No newline at end of file diff --git a/.github/workflows/unittest-dev.yml b/.github/workflows/dev-pull-requests.yml similarity index 64% rename from .github/workflows/unittest-dev.yml rename to .github/workflows/dev-pull-requests.yml index 6e9ce77..eec9307 100644 --- a/.github/workflows/unittest-dev.yml +++ b/.github/workflows/dev-pull-requests.yml @@ -1,20 +1,29 @@ -name: Unittest Dev +name: Development Workflow on: pull_request: - branches: [ "dev" ] - push: - branches: [ "dev" ] + branches: [ dev, main ] jobs: - build: + trivy-fs-scan: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run Trivy vulnerability scanner in fs mode + uses: aquasecurity/trivy-action@master + with: + scan-type: 'fs' + scan-ref: '.' + exit-code: '1' + + python-unittests: runs-on: ubuntu-latest strategy: fail-fast: false matrix: python-version: ["3.12"] - steps: - uses: actions/checkout@v4 - name: Set environment variable @@ -31,4 +40,4 @@ jobs: run: | python -m unittest discover ./generator/unittests/utilities python -m unittest discover ./generator/unittests/objects - python -m unittest discover ./generator/unittests/app + python -m unittest discover ./generator/unittests/app \ No newline at end of file diff --git a/.github/workflows/dockerhub-main-push.yml b/.github/workflows/dockerhub-main-push.yml deleted file mode 100644 index bed4d7b..0000000 --- a/.github/workflows/dockerhub-main-push.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: DockerHub Main Push - -on: - workflow_run: - workflows: ["Unittest Main Push"] - types: - - completed -jobs: - build: - runs-on: ubuntu-latest - steps: - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ vars.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build and push - uses: docker/build-push-action@v6 - with: - push: true - tags: oislen/randomtelecompayments:latest \ No newline at end of file diff --git a/.github/workflows/unittest-main-pr.yml b/.github/workflows/unittest-main-pr.yml deleted file mode 100644 index 7c3e2e0..0000000 --- a/.github/workflows/unittest-main-pr.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Unittest Main Pull Request - -on: - pull_request: - branches: [ "main" ] - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - python-version: ["3.12"] - - steps: - - uses: actions/checkout@v4 - - name: Set environment variable - run: echo "GITHUB_ACTIONS_UNITTEST_FLAG=1" >> $GITHUB_ENV - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install python dependencies - run: | - python -m pip install --upgrade pip - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Test with unittest - run: | - python -m unittest discover ./generator/unittests/utilities - python -m unittest discover ./generator/unittests/objects - python -m unittest discover ./generator/unittests/app diff --git a/.github/workflows/unittest-main-push.yml b/.github/workflows/unittest-main-push.yml deleted file mode 100644 index bd21ed1..0000000 --- a/.github/workflows/unittest-main-push.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Unittest Main Push - -on: - push: - branches: [ "main" ] - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - python-version: ["3.12"] - - steps: - - uses: actions/checkout@v4 - - name: Set environment variable - run: echo "GITHUB_ACTIONS_UNITTEST_FLAG=1" >> $GITHUB_ENV - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install python dependencies - run: | - python -m pip install --upgrade pip - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Test with unittest - run: | - python -m unittest discover ./generator/unittests/utilities - python -m unittest discover ./generator/unittests/objects - python -m unittest discover ./generator/unittests/app From 53cccba9a0a9da071acf693cf1d47c99f472610f Mon Sep 17 00:00:00 2001 From: Oisin Date: Sat, 17 Jan 2026 21:27:39 +0000 Subject: [PATCH 3/3] Updated dockerfile to pull from python image --- Dockerfile | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 56c54a9..ab85832 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,28 @@ # get base image -FROM ubuntu:latest +FROM python:3.12 # set environment variables -ENV user=ubuntu +ENV user=user ENV DEBIAN_FRONTEND=noninteractive # set python version ARG PYTHON_VERSION="3.12" ENV PYTHON_VERSION=${PYTHON_VERSION} # install required software and programmes for development environment -RUN apt-get update -RUN apt-get install -y apt-utils vim curl wget unzip tree htop +RUN apt-get update +RUN apt-get install -y apt-utils vim curl wget unzip tree htop adduser # set up home environment +RUN adduser ${user} RUN mkdir -p /home/${user} && chown -R ${user}: /home/${user} # copy repo -COPY . /home/ubuntu/RandomTelecomPayments +COPY . /home/${user}/RandomTelecomPayments -# add deadsnakes ppa -RUN apt-get install -y software-properties-common -RUN add-apt-repository ppa:deadsnakes/ppa -# install required python and create virtual environment -RUN apt-get install -y python${PYTHON_VERSION} python${PYTHON_VERSION}-venv -RUN python3 -m venv /opt/venv -ENV PATH="/opt/venv/bin:$PATH" -RUN /opt/venv/bin/python3 -m pip install -r /home/ubuntu/RandomTelecomPayments/requirements.txt +# install required python packages +RUN python -m pip install -v -r /home/${user}/RandomTelecomPayments/requirements.txt +# set working directory for random telecom payments app WORKDIR /home/${user}/RandomTelecomPayments -ENTRYPOINT ["/opt/venv/bin/python3", "generator/main.py"] \ No newline at end of file + +ENTRYPOINT ["python", "generator/main.py"] \ No newline at end of file