2017-10-20 127 views
0

我用django-ex模板在Openshift v3 PRO上構建了django的應用程序。它效果很好。我使用POSTGRESQL和持久存儲。CronJob,Django和環境變量

我需要一個計劃的cron作業來每小時觸發一些django管理命令。我正在使用CronJob吊艙。

我的問題是這樣的:我需要創建具有相同的環境變量Django的吊艙與(DATABASE_ ,DJANGO_,和其他人)創建的cronjob工作,但沒有看到一個簡單的方法來做到這一點。

任何幫助將不勝感激。

回答

1

您應該能夠在作業的模板規範中包含一個環境變量列表,作爲containers定義的一部分。我不能正確地提取在OpenShift 3.6使用oc explain的,因爲它是註冊的方式CronJob資源定義,但我希望的領域是相似的:

CronJob.spec.jobTemplate.spec.template.spec.containers.env 

RESOURCE: env <[]Object> 

DESCRIPTION: 
    List of environment variables to set in the container. Cannot be updated. 

    EnvVar represents an environment variable present in a Container. 

FIELDS: 
    name <string> -required- 
    Name of the environment variable. Must be a C_IDENTIFIER. 

    value <string> 
    Variable references $(VAR_NAME) are expanded using the previous defined 
    environment variables in the container and any service environment 
    variables. If a variable cannot be resolved, the reference in the input 
    string will be unchanged. The $(VAR_NAME) syntax can be escaped with a 
    double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, 
    regardless of whether the variable exists or not. Defaults to "". 

    valueFrom <Object> 
    Source for the environment variable's value. Cannot be used if value is not 
    empty. 
+0

格雷厄姆,感謝您的答覆。那麼你會建議我將它添加到創建整個應用程序的初始模板(即django-ex/openshift/django.json)或稍後添加它?我以爲我在過去的問題上遇到了麻煩,上面的規範在模板中是不允許的。再次感謝您的幫助。 – YoFlynn

+0

原始模板不包含任何作業。你是否建議增加工作?如果您的應用程序已經部署,這沒有幫助。如果您打算將應用程序映像用於作業,那麼您將不得不使用某些技巧來讓作業使用它。在這裏包含您的cronjob規範,以便我可以看到它。 –

+0

是的,我仍然在POC階段如何讓我的django應用程序從OS2 - > OS3移動,因此將它添加到應用程序模板不是問題。無法張貼評論我的代碼,這在SO中並不太容易。 – YoFlynn