From 304d5b156cfb40ea9c97b35541c206c83fccd110 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Thu, 27 Jun 2024 17:05:26 +0100 Subject: [PATCH 1/4] feat(docker): Update entrypoint - Allow arbitrary Django commands - Remove redundant commands - Remove deprecated `go_to_sleep` --- api/scripts/run-docker.sh | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/api/scripts/run-docker.sh b/api/scripts/run-docker.sh index 7fa0ff47dda9..547a82b8b27c 100755 --- a/api/scripts/run-docker.sh +++ b/api/scripts/run-docker.sh @@ -1,10 +1,6 @@ #!/bin/bash set -e -# The script can take 2 optional arguments: -# 1. The django target to run -# 2. For migrate, serve and migrate-and-serve, the number of seconds to sleep before running - function migrate () { python manage.py waitfordb && python manage.py migrate && python manage.py createcachetable } @@ -40,9 +36,6 @@ function run_task_processor() { --numthreads ${TASK_PROCESSOR_NUM_THREADS:-5} \ --queuepopsize ${TASK_PROCESSOR_QUEUE_POP_SIZE:-10} } -function migrate_identities(){ - python manage.py migrate_to_edge "$1" -} function migrate_analytics_db(){ # if `$ANALYTICS_DATABASE_URL` or DJANGO_DB_NAME_ANALYTICS is set # run the migration command @@ -51,47 +44,25 @@ function migrate_analytics_db(){ fi python manage.py migrate --database analytics } -function import_organisation_from_s3(){ - python manage.py importorganisationfroms3 "$1" "$2" -} -function dump_organisation_to_s3(){ - python manage.py dumporganisationtos3 "$1" "$2" "$3" -} -function dump_organisation_to_local_fs(){ - python manage.py dumporganisationtolocalfs "$1" "$2" -} function bootstrap(){ python manage.py bootstrap } -# Note: `go_to_sleep` is deprecated and will be removed in a future release. -function go_to_sleep(){ - echo "Sleeping for ${1} seconds before startup" - sleep ${1} +function default(){ + python manage.py "$@" } if [ "$1" == "migrate" ]; then - if [ $# -eq 2 ]; then go_to_sleep "$2"; fi migrate migrate_analytics_db elif [ "$1" == "serve" ]; then - if [ $# -eq 2 ]; then go_to_sleep "$2"; fi serve elif [ "$1" == "run-task-processor" ]; then run_task_processor elif [ "$1" == "migrate-and-serve" ]; then - if [ $# -eq 2 ]; then go_to_sleep "$2"; fi migrate migrate_analytics_db bootstrap serve -elif [ "$1" == "migrate-identities" ]; then - migrate_identities "$2" -elif [ "$1" == "import-organisation-from-s3" ]; then - import_organisation_from_s3 "$2" "$3" -elif [ "$1" == "dump-organisation-to-s3" ]; then - dump_organisation_to_s3 "$2" "$3" "$4" -elif [ "$1" == "dump-organisation-to-local-fs" ]; then - dump_organisation_to_local_fs "$2" "$3" else - echo "ERROR: unrecognised command '$1'" + default fi From 193894fdd3dac52ae18a4016dc002862e52410d3 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Fri, 28 Jun 2024 08:33:00 +0100 Subject: [PATCH 2/4] fix args --- api/scripts/run-docker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/scripts/run-docker.sh b/api/scripts/run-docker.sh index 547a82b8b27c..d563b8946dc9 100755 --- a/api/scripts/run-docker.sh +++ b/api/scripts/run-docker.sh @@ -64,5 +64,5 @@ elif [ "$1" == "migrate-and-serve" ]; then bootstrap serve else - default + default "$@" fi From 0386413344f457d164c16233b80981b7250a9051 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Fri, 12 Jul 2024 10:57:00 +0200 Subject: [PATCH 3/4] update ECS task --- .github/actions/api-deploy-ecs/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/api-deploy-ecs/action.yml b/.github/actions/api-deploy-ecs/action.yml index e6a367a830a3..a9b2dc984bfb 100644 --- a/.github/actions/api-deploy-ecs/action.yml +++ b/.github/actions/api-deploy-ecs/action.yml @@ -130,7 +130,7 @@ runs: }, "InputTransformer": { "InputPathsMap":{"project_id":"$.detail.project_id"}, - "InputTemplate": "{ \"containerOverrides\": [ { \"name\": \"flagsmith-api-migration\", \"command\": [\"migrate-identities\", ], \" environment \":[{\"PROJECT_METADATA_TABLE_NAME_DYNAMO\":\"flagsmith_project_metadata\"}]}]}" + "InputTemplate": "{ \"containerOverrides\": [ { \"name\": \"flagsmith-api-migration\", \"command\": [\"migrate_to_edge\", ], \" environment \":[{\"PROJECT_METADATA_TABLE_NAME_DYNAMO\":\"flagsmith_project_metadata\"}]}]}" } } ]' From bdcfdd7d894c003879b21609da7b8b41908dc1fc Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Fri, 12 Jul 2024 10:57:07 +0200 Subject: [PATCH 4/4] update docs --- .../importing-and-exporting/organisations.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/docs/system-administration/importing-and-exporting/organisations.md b/docs/docs/system-administration/importing-and-exporting/organisations.md index 461002711813..0c184ea25cdd 100644 --- a/docs/docs/system-administration/importing-and-exporting/organisations.md +++ b/docs/docs/system-administration/importing-and-exporting/organisations.md @@ -116,7 +116,7 @@ services: environment: DATABASE_URL: postgresql://postgres:password@postgres:5432/flagsmith command: - - 'dump-organisation-to-local-fs' + - 'dumporganisationtolocalfs' - '1' - '/tmp/flagsmith-exporter/org-1.json' depends_on: @@ -164,13 +164,13 @@ This is coming soon - see https://github.com/Flagsmith/flagsmith/issues/2512 for ### Option 2 - S3 bucket ```bash -python manage.py import-organisation-from-s3 +python manage.py importorganisationfroms3 ``` e.g. ```bash -python manage.py import-organisation-from-s3 my-export-bucket exports/organisation-1.json +python manage.py importorganisationfroms3 my-export-bucket exports/organisation-1.json ``` #### Using localstack to achieve local/test imports with s3 can be done using