how to run shell commands in wp-cli kubernetes job to configure wordpress container?

梦想与她 提交于 2020-06-17 09:44:29

问题


Job yaml file for the wp-cli commands in the wordpress helm chart folder:

{{ if and .Release.IsInstall .Values.job.autoCreateCluster }}
apiVersion: batch/v1
kind: Job
metadata:
  name: "{{ .Release.Name }}"
  labels:
    app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
    app.kubernetes.io/instance: {{ .Release.Name | quote }}
    app.kubernetes.io/version: {{ .Chart.AppVersion }}
    helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
  annotations:
    # This is what defines this resource as a hook. Without this line, the
    # job is considered part of the release.
    "helm.sh/hook": post-install
    "helm.sh/hook-weight": "-3"
    "helm.sh/hook-delete-policy": before-hook-creation
spec:
  template:
    metadata:
      name: "{{.Release.Name}}"
      labels:
        app.kubernetes.io/managed-by: {{.Release.Service | quote }}
        app.kubernetes.io/instance: {{.Release.Name | quote }}
        helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}"
    spec:
      securityContext:
        runAsUser: 82
        runAsGroup: 82
        fsGroup: 82 # www-data
      restartPolicy: OnFailure
      imagePullSecrets:
        - name: {{ .Values.job.pullSecrets }}
      volumes:
        - name: wordpress-data
          {{- if .Values.persistence.enabled }}
          persistentVolumeClaim:
            claimName: {{ .Values.persistence.existingClaim | default (include "wordpress.fullname" .) }}
          {{- else }}
          emptyDir: {}
          {{ end }}
        {{- if .Values.extraVolumes }}
        {{- include "wordpress.tplValue" (dict "value" .Values.extraVolumes "context" $) | nindent 8 }}
        {{- end }}
      containers:
        - name: post-install-job
          image: {{ .Values.job.image }}
          imagePullPolicy: {{ .Values.job.pullPolicy }}
          volumeMounts:
            - mountPath: /bitnami/wordpress
              name: wordpress-data
          command: ["bin/sh/"]
          args: ["-c", "sleep 30
                 && test -e .INSTALLED
                 && cat /tmp/tracker2.js >> header_snippet.php
                 && echo \"<?php\" >> header_snippet.php
                 && cat header_snippet.php >> wp-content/themes/twentyseventeen/functions.php
                 && wp rewrite structure '/%postname%/'
                 && cat /tmp/ad_widget.html | xargs -0 -I {}  wp widget add custom_html sidebar-1 --title='Ads by test' --content={} --user=user
                 && wp post create --porcelain --post_type=page --post_status=publish --post_title='Ad Conversion' /tmp/ad_converted.html > /tmp/p
                 && wp theme delete twentyfifteen twentysixteen
                 && wp plugin delete akismet hello-dolly
                 && wp plugin install amp --activate
                 && wp plugin install leaky-paywall --activate
                 && wp option add issuem-leaky-paywall </tmp/leaky-paywall.json --format=json
                 && wp post create --porcelain --post_type=page --post_status=publish --post_title='Login' --post_content='[leaky_paywall_login]' > /tmp/p
                 && wp option patch update issuem-leaky-paywall page_for_login < /tmp/p --format=json
                 && wp post create --porcelain  --post_type=page --post_status=publish --post_title='Subscribe' --post_content='[leaky_paywall_subscription]' > /tmp/p
                 && wp option patch update issuem-leaky-paywall page_for_subscription < /tmp/p --format=json
                 && wp post create --porcelain --post_type=page --post_status=publish --post_title='Register' --post_content='[leaky_paywall_register_form]' > /tmp/p
                 && wp option patch update issuem-leaky-paywall page_for_register < /tmp/p --format=json
                 && wp post create --porcelain --post_type=page --post_status=publish --post_title='Profile' --post_content='[leaky_paywall_profile]' > /tmp/p
                 && wp option patch update issuem-leaky-paywall page_for_profile < /tmp/p --format=json
                 && wp post create --porcelain --post_type=page --post_status=publish --post_title='Success' /tmp/transaction.js > /tmp/p
                 && wp option patch update issuem-leaky-paywall page_for_after_subscribe < /tmp/p --format=json
                 && wp post create --post_type=post --post_status=publish --post_title='A sample post'
                 && echo done >> .INSTALLED"]
{{ end }}

I am trying to run these commands in a wp-cli image to configure the wordpress container (using Bitnami's wordpress helm chart). However, the scripts are not being run so my wordpress site is not being updated. Currently, both the pod created from this job and the wordpress container are using the same volume. Is there something I am missing? Thanks.

来源:https://stackoverflow.com/questions/62273543/how-to-run-shell-commands-in-wp-cli-kubernetes-job-to-configure-wordpress-contai

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!