docker entrypoint script #894

Avoinna
3 vuotta sitten avasi pwFoo · 5 kommenttia

Hi,
here is a entrypoint script for plume sqlite version. Need to be improved and extended for postgresql database initialization / check.

#!/bin/sh

set -x

# generate ".env" file by "PLUME_*" environment variables
> .env
for env in $(printenv |grep ^PLUME_.* | sed 's/PLUME_//g'); do
    echo $env >> .env
done


# check plume database url is a existing file (sqlite)
# ToDo: postgres??
INITIALIZE=0
if [ ! -f $(printenv PLUME_DATABASE_URL) ]; then
    INITIALIZE=1
fi


# run migrate during each startup
plm migration run


# init plume search index if not exists OR ELSE refill during startup
if [ -z "$(ls -A $(printenv PLUME_SEARCH_INDEX))" ]; then
    plm search init
else
    plm search refill
fi


# initialize instance and admin user
# PLM_INSTANCE_*
# PLM_ADMIN_*
if [ $INITIALIZE -eq 1 ]; then
    LICENSE=$(printenv PLM_INSTANCE_LICENSE)
    LICENSE=${LICENSE:-"CC-BY-SA"}
    DOMAIN=$(printenv PLM_INSTANCE_DOMAIN)
    DOMAIN=${DOMAIN:-$(printenv PLUME_BASE_URL)}
    plm instance new --domain $DOMAIN --name "$(printenv PLM_INSTANCE_NAME)" --default-license $LICENSE
    plm users new --admin --username "$(printenv PLM_ADMIN_USER)"  --display-name "$(printenv PLM_ADMIN_NAME)" --bio "$(printenv PLM_ADMIN_BIO)" --password "$(printenv PLM_ADMIN_PASS)" --email "$(printenv PLM_ADMIN_EMAIL)"
fi


# start plume
exec plume

Suggestions for improvements?

Hi, here is a entrypoint script for plume sqlite version. Need to be improved and extended for postgresql database initialization / check. ``` #!/bin/sh set -x # generate ".env" file by "PLUME_*" environment variables > .env for env in $(printenv |grep ^PLUME_.* | sed 's/PLUME_//g'); do echo $env >> .env done # check plume database url is a existing file (sqlite) # ToDo: postgres?? INITIALIZE=0 if [ ! -f $(printenv PLUME_DATABASE_URL) ]; then INITIALIZE=1 fi # run migrate during each startup plm migration run # init plume search index if not exists OR ELSE refill during startup if [ -z "$(ls -A $(printenv PLUME_SEARCH_INDEX))" ]; then plm search init else plm search refill fi # initialize instance and admin user # PLM_INSTANCE_* # PLM_ADMIN_* if [ $INITIALIZE -eq 1 ]; then LICENSE=$(printenv PLM_INSTANCE_LICENSE) LICENSE=${LICENSE:-"CC-BY-SA"} DOMAIN=$(printenv PLM_INSTANCE_DOMAIN) DOMAIN=${DOMAIN:-$(printenv PLUME_BASE_URL)} plm instance new --domain $DOMAIN --name "$(printenv PLM_INSTANCE_NAME)" --default-license $LICENSE plm users new --admin --username "$(printenv PLM_ADMIN_USER)" --display-name "$(printenv PLM_ADMIN_NAME)" --bio "$(printenv PLM_ADMIN_BIO)" --password "$(printenv PLM_ADMIN_PASS)" --email "$(printenv PLM_ADMIN_EMAIL)" fi # start plume exec plume ``` Suggestions for improvements?
Omistaja

Briefly looks good! Thanks.

A few things:

We don't need generate .env file. Variable in .env are read by Plume program as they are environemnt variables. If you may get vars from environment variables directly, you don't need write them down to the file.

How about running plm migration run optional? Sometime the command places burdon on database. Administrators should want to choose when they run it.

Briefly looks good! Thanks. A few things: We don't need generate `.env` file. Variable in `.env` are read by Plume program as they are environemnt variables. If you may get vars from environment variables directly, you don't need write them down to the file. How about running `plm migration run` optional? Sometime the command places burdon on database. Administrators should want to choose when they run it.
Tekijä

Hi,
I'll change and test that. Also will extend the official postgres image for some tests with my entrypoint script. My own postgres image (musl static) still fails to build.

Hi, I'll change and test that. Also will extend the official postgres image for some tests with my entrypoint script. My own postgres image (musl static) still fails to build.
Tekijä

Updated script

  • run migrate only during initialization or if set to environment
  • added postgres check with a ENV workaround ($PLM_INSTALL) because can't check pgsql tables with plumeorg/plume or plm (related to #901)

Postgres instance installed and reachable, but need a way to check pgsql initialized or not instead of a ENV VAR needed just first time... I don't like such a variable and also don't like to install pg cli tools for just such a simple check. Maybe it could be done by add db subcommands to plm (#901)?

#!/bin/sh

set -x

# generate ".env" file by "PLUME_*" environment variables
> .env
for env in $(printenv |grep ^PLUME_.* | sed 's/PLUME_//g'); do
    echo $env >> .env
done


# check plume database url is a existing file (sqlite)
# ToDo: Check DB initialized instead of use "PLM_INSTALL" ENV VAR flag...
INITIALIZE=0
if [[ $PLUME_DATABASE_URL =~ ^postgres:// ]] && [ ! -z "$PLM_INSTALL" ]; then
    echo Check if Postgres DB is initialized...
    # IF not initialized 
    INITIALIZE=1
elif [ ! -f $(printenv PLUME_DATABASE_URL) ]; then
    INITIALIZE=1
fi


# run migrate during each startup
if [ $INITIALIZE -eq 1 ] || [ ! -z "$PLM_MIGRATE_RUN" ]; then
    plm migration run
fi


# init plume search index if not exists OR ELSE refill during startup
if [ -z "$(ls -A $(printenv PLUME_SEARCH_INDEX))" ] || [ $INITIALIZE -eq 1 ]; then
    plm search init
else
    plm search refill
fi


# initialize instance and admin user
# PLM_INSTANCE_*
# PLM_ADMIN_*
if [ $INITIALIZE -eq 1 ]; then
    LICENSE=$(printenv PLM_INSTANCE_LICENSE)
    LICENSE=${LICENSE:-"CC-BY-SA"}
    DOMAIN=$(printenv PLM_INSTANCE_DOMAIN)
    DOMAIN=${DOMAIN:-$(printenv PLUME_BASE_URL)}
    # initialize plume
    plm instance new --domain $DOMAIN --name "$(printenv PLM_INSTANCE_NAME)" --default-license $LICENSE
    plm users new --admin --username "$(printenv PLM_ADMIN_USER)"  --display-name "$(printenv PLM_ADMIN_NAME)" --bio "$(printenv PLM_ADMIN_BIO)" --password "$(printenv PLM_ADMIN_PASS)" --email "$(printenv PLM_ADMIN_EMAIL)"
fi


# start plume
exec plume

It works with plumeorg/plume:latest image and postgres db. Create a test image

FROM    plumeorg/plume:latest

COPY    plume_entrypoint /usr/local/bin/plume_entrypoint

CMD     [ "/usr/local/bin/plume_entrypoint" ]
Updated script * run migrate only during initialization or if set to environment * added postgres check with a ENV workaround (`$PLM_INSTALL`) because can't check pgsql tables with plumeorg/plume or plm (related to #901) Postgres instance installed and reachable, but need a way to check pgsql initialized or not instead of a ENV VAR needed just first time... I don't like such a variable and also don't like to install pg cli tools for just such a simple check. Maybe it could be done by add db subcommands to plm (#901)? ``` #!/bin/sh set -x # generate ".env" file by "PLUME_*" environment variables > .env for env in $(printenv |grep ^PLUME_.* | sed 's/PLUME_//g'); do echo $env >> .env done # check plume database url is a existing file (sqlite) # ToDo: Check DB initialized instead of use "PLM_INSTALL" ENV VAR flag... INITIALIZE=0 if [[ $PLUME_DATABASE_URL =~ ^postgres:// ]] && [ ! -z "$PLM_INSTALL" ]; then echo Check if Postgres DB is initialized... # IF not initialized INITIALIZE=1 elif [ ! -f $(printenv PLUME_DATABASE_URL) ]; then INITIALIZE=1 fi # run migrate during each startup if [ $INITIALIZE -eq 1 ] || [ ! -z "$PLM_MIGRATE_RUN" ]; then plm migration run fi # init plume search index if not exists OR ELSE refill during startup if [ -z "$(ls -A $(printenv PLUME_SEARCH_INDEX))" ] || [ $INITIALIZE -eq 1 ]; then plm search init else plm search refill fi # initialize instance and admin user # PLM_INSTANCE_* # PLM_ADMIN_* if [ $INITIALIZE -eq 1 ]; then LICENSE=$(printenv PLM_INSTANCE_LICENSE) LICENSE=${LICENSE:-"CC-BY-SA"} DOMAIN=$(printenv PLM_INSTANCE_DOMAIN) DOMAIN=${DOMAIN:-$(printenv PLUME_BASE_URL)} # initialize plume plm instance new --domain $DOMAIN --name "$(printenv PLM_INSTANCE_NAME)" --default-license $LICENSE plm users new --admin --username "$(printenv PLM_ADMIN_USER)" --display-name "$(printenv PLM_ADMIN_NAME)" --bio "$(printenv PLM_ADMIN_BIO)" --password "$(printenv PLM_ADMIN_PASS)" --email "$(printenv PLM_ADMIN_EMAIL)" fi # start plume exec plume ``` It works with plumeorg/plume:latest image and postgres db. Create a test image ``` FROM plumeorg/plume:latest COPY plume_entrypoint /usr/local/bin/plume_entrypoint CMD [ "/usr/local/bin/plume_entrypoint" ] ```
Omistaja

The change about migration looks good.

Can you create a pull request, though this is second time saying? It's difficult for me to track changes from issue comments. Surely learning Git is not easy. But adding entry script and continuing to modify it is easy even if you are not familiar with Git because Gitea allows you to edit files in your browser.

Gitea itself doesn't have documentation for that. But GitHub's ones are so helpful:

Can you consider it? Thanks.

The change about migration looks good. Can you create a pull request, though this is second time saying? It's difficult for me to track changes from issue comments. Surely learning Git is not easy. But adding entry script and continuing to modify it is easy even if you are not familiar with Git because Gitea allows you to edit files in your browser. Gitea itself doesn't have documentation for that. But GitHub's ones are so helpful: * [Creating a pull request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request) * [Editing files in your repository](https://docs.github.com/en/github/managing-files-in-a-repository/editing-files-in-your-repository) Can you consider it? Thanks.
Tekijä

I'll take a look and create a pull request, but need some time to finish other tasks first.
I have to learnhow to useh git and create pull requests anyway :)

I'll take a look and create a pull request, but need some time to finish other tasks first. I have to learnhow to useh git and create pull requests anyway :)
Sign in to join this conversation.
Ei merkkipaalua
Ei käsittelijää
2 osallistujaa
Ilmoitukset
Määräpäivä
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

Määräpäivää ei asetettu.

Riippuvuudet

Riippuvuuksia ei asetettu.

Reference: Plume/Plume#894
Ladataan…
Sisältöä ei vielä ole.