From 06b3bb5c4d8d4cc4b969ab463744cbce62b9d2a5 Mon Sep 17 00:00:00 2001 From: Ramin Vazir Date: Thu, 15 Oct 2026 16:13:40 +0100 Subject: [PATCH] added floci support --- README.md | 11 ++++ scripts/commodities.rb | 3 + scripts/docker/floci/Dockerfile | 6 ++ scripts/docker/floci/compose-fragment.yml | 7 +++ scripts/provision_floci.rb | 73 +++++++++++++++++++++++ scripts/update_apps.rb | 6 +- snippets/app_configuration.yml | 2 +- snippets/floci-init-fragment.sh | 3 + 8 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 scripts/docker/floci/Dockerfile create mode 100644 scripts/docker/floci/compose-fragment.yml create mode 100644 scripts/provision_floci.rb create mode 100644 snippets/floci-init-fragment.sh diff --git a/README.md b/README.md index c617428..84ddbc8 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,7 @@ The list of allowable commodity values is: 20. prometheus 21. grafana 22. govuk-one-login +23. floci The file may optionally also indicate that one or more services are resource intensive ("expensive") when starting up. The dev env will start those containers seperately - 3 at a time - and wait until each are declared healthy (or crash and get restarted 10 times) before starting any more. @@ -390,6 +391,16 @@ The GOV.UK One Login simulator is a development tool that lets you run end-to-en See [documentation](https://github.com/govuk-one-login/simulator). +###### floci + +**`/fragments/floci-init-fragment.sh`** + +[Floci](https://floci.io/) is a cloud stack testing and mocking framework for developing against various AWS services. + +For any configuration (such as new buckets) necessary before application startup, you can use a `floci-init-fragment.sh` to perform this provisioning; like [this example](snippets/floci-init-fragment.sh). Floci provisioning is performed using the aws cli. + +Floci is available at  within the Docker network, and on the host. + #### Other files **`/fragments/custom-provision.sh`** diff --git a/scripts/commodities.rb b/scripts/commodities.rb index 8182937..b71ef6b 100644 --- a/scripts/commodities.rb +++ b/scripts/commodities.rb @@ -8,6 +8,7 @@ require_relative 'provision_elasticsearch7' require_relative 'provision_wiremock' require_relative 'provision_localstack' +require_relative 'provision_floci' require 'fileutils' require 'open3' @@ -150,6 +151,8 @@ def provision_commodities(root_loc, new_containers) provision_hosts(root_loc) # Localstack provision_localstack(root_loc, new_containers) + # floci + provision_floci(root_loc, new_containers) end def container_to_commodity(container_name) diff --git a/scripts/docker/floci/Dockerfile b/scripts/docker/floci/Dockerfile new file mode 100644 index 0000000..0da9df6 --- /dev/null +++ b/scripts/docker/floci/Dockerfile @@ -0,0 +1,6 @@ +FROM floci/floci:2.3.0-compat@sha256:ecfd33bb98d3e0ce0e11d528730f0827c08ab18c9b331865203d67ec65c10c07 + +ENV AWS_ENDPOINT_URL=http://floci:4566 \ +AWS_DEFAULT_REGION=us-east-1 \ +AWS_ACCESS_KEY_ID=test \ +AWS_SECRET_ACCESS_KEY=test diff --git a/scripts/docker/floci/compose-fragment.yml b/scripts/docker/floci/compose-fragment.yml new file mode 100644 index 0000000..834a96d --- /dev/null +++ b/scripts/docker/floci/compose-fragment.yml @@ -0,0 +1,7 @@ +services: + # Notice how the service name, container name and repo directory (where the Dockerfile lives) all match. + floci: + container_name: floci + build: ../scripts/docker/floci/ + ports: + - 4566:4566 \ No newline at end of file diff --git a/scripts/provision_floci.rb b/scripts/provision_floci.rb new file mode 100644 index 0000000..b2b2f87 --- /dev/null +++ b/scripts/provision_floci.rb @@ -0,0 +1,73 @@ +require_relative 'utilities' +require_relative 'commodities' +require 'yaml' + +def provision_floci(root_loc, new_containers) + # Load configuration.yml into a Hash + config = YAML.load_file("#{root_loc}/dev-env-config/configuration.yml") + return unless config['applications'] + + # Did the container previously exist, if not then we MUST provision regardless of .commodities value + new_container = false + if new_containers.include?('floci') + new_container = true + puts colorize_yellow('The Floci container has been newly created - '\ + 'provision status in .commodities will be ignored') + end + + floci_initialised = false + + config['applications'].each_key do |appname| + # To help enforce the accuracy of the app's dependency file, only search for init script + # if the app specifically specifies floci in it's commodity list + next unless File.exist?("#{root_loc}/apps/#{appname}/configuration.yml") + next unless commodity_required?(root_loc, appname, 'floci') + + # Load any init fragments contained in the apps into the docker commands list + if File.exist?("#{root_loc}/apps/#{appname}/fragments/floci-init-fragment.sh") + process_floci_fragment(root_loc, appname, floci_initialised, new_container) + end + end +end + +def process_floci_fragment(root_loc, appname, floci_initialised, new_container) + result = floci_initialised + puts colorize_pink("Found a Floci init fragment in #{appname}") + if commodity_provisioned?(root_loc, appname, 'floci') && !new_container + puts colorize_yellow("Floci has previously been provisioned for #{appname}, skipping") + else + unless floci_initialised + init_floci + result = true + end + init_floci_sh(root_loc, appname) + end + result +end + +def init_floci_sh(root_loc, appname) + # See comments in provision_postgres.rb for why we are doing it this way + run_command('tar -c' \ + " -C #{root_loc}/apps/#{appname}/fragments" \ + ' floci-init-fragment.sh' \ + ' | docker cp - floci:/') + + cmd = 'docker exec floci bash -c "sh /floci-init-fragment.sh"' + exit_code = run_command(cmd) + + puts colorize_lightblue("Completed #{appname} Floci fragment") + + if ![0].include?(exit_code) + # if exit_code != 0 + puts colorize_red("Something went wrong with the Floci setup. Exitcode - #{exit_code}") + else + puts colorize_yellow("Floci initialised correctly. Exitcode - #{exit_code}.") + set_commodity_provision_status(root_loc, appname, 'floci', true) + end +end + +def init_floci + # Start floci + run_command("#{ENV['DC_CMD']} up -d floci") + puts colorize_green('Floci is ready') +end diff --git a/scripts/update_apps.rb b/scripts/update_apps.rb index a76f1c8..08c8a67 100644 --- a/scripts/update_apps.rb +++ b/scripts/update_apps.rb @@ -108,9 +108,9 @@ def update_app(appconfig, root_loc, appname) output_lines ).zero? return ( - # Attempt to merge our remote branch into our local branch, if it's straightforward - output_lines += merge(root_loc, appname) - ) + # Attempt to merge our remote branch into our local branch, if it's straightforward + output_lines += merge(root_loc, appname) + ) end # If there is a git error we should let them know but carry on diff --git a/snippets/app_configuration.yml b/snippets/app_configuration.yml index 29f66c2..a0bea81 100644 --- a/snippets/app_configuration.yml +++ b/snippets/app_configuration.yml @@ -1,5 +1,5 @@ --- -commodities: ["postgres-17", "elasticsearch5", "rabbitmq-4", "db2_community"] +commodities: ["postgres-17", "elasticsearch5", "rabbitmq-4", "db2_community", "floci"] # Optional expensive_startup: - compose_service: name-of-service-from-compose-fragment diff --git a/snippets/floci-init-fragment.sh b/snippets/floci-init-fragment.sh new file mode 100644 index 0000000..80b8cc1 --- /dev/null +++ b/snippets/floci-init-fragment.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +aws s3 mb s3://test-bucket \ No newline at end of file