Skip to content

Commit

Permalink
feat(docker): Update entrypoint (#4262)
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 authored Jul 12, 2024
1 parent 9b927e8 commit 759e745
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/actions/api-deploy-ecs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ runs:
},
"InputTransformer": {
"InputPathsMap":{"project_id":"$.detail.project_id"},
"InputTemplate": "{ \"containerOverrides\": [ { \"name\": \"flagsmith-api-migration\", \"command\": [\"migrate-identities\", <project_id>], \" environment \":[{\"PROJECT_METADATA_TABLE_NAME_DYNAMO\":\"flagsmith_project_metadata\"}]}]}"
"InputTemplate": "{ \"containerOverrides\": [ { \"name\": \"flagsmith-api-migration\", \"command\": [\"migrate_to_edge\", <project_id>], \" environment \":[{\"PROJECT_METADATA_TABLE_NAME_DYNAMO\":\"flagsmith_project_metadata\"}]}]}"
}
}
]'
Expand Down
35 changes: 3 additions & 32 deletions api/scripts/run-docker.sh
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 <bucket-name> <key>
python manage.py importorganisationfroms3 <bucket-name> <key>
```

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
Expand Down

0 comments on commit 759e745

Please sign in to comment.