【问题标题】:GC Deployment Manager install PHP with Jinja templateGC Deployment Manager 使用 Jinja 模板安装 PHP
【发布时间】:2021-10-09 10:20:29
【问题描述】:

我想通过 Google Cloud Deployment Manager 部署 PHP 应用程序。创建实例后,应在 VM 上安装 PHP(和其他一些 Linux 软件包)。这可能在模板文件中吗?还是我必须创建自定义 VM 映像?

我只设法创建了虚拟机,但没有找到有关如何自动安装软件包的任何信息。

{% set COMPUTE_URL_BASE = 'https://www.googleapis.com/compute/v1/' %}
{% set BASE_NAME = env['deployment'] + '-' + env['name'] %}

{% macro GlobalComputeUrl(project, collection, name) -%}
{{ COMPUTE_URL_BASE }}projects/{{ project }}/global/{{ collection }}/{{ name }}
{%- endmacro %}

{% macro ZonalComputeUrl(project, zone, collection, name) -%}
{{ COMPUTE_URL_BASE }}projects/{{ project }}/zones/{{ zone }}/{{ collection }}/{{ name }}
{%- endmacro %}

resources:
- name: {{ BASE_NAME }}
  type: compute.v1.instance
  properties:
    zone: {{ properties['zone'] }}
    machineType: {{ ZonalComputeUrl(env['project'], properties['zone'], 'machineTypes', 'e2-micro') }}
    metadata:
      items:
        - key: gce-container-declaration
          value: |
            {{ imports[properties['containerManifest']]|indent(12) }}
    disks:
      - deviceName: boot
        type: PERSISTENT
        autoDelete: true
        boot: true
        initializeParams:
          diskName: {{ BASE_NAME }}-disk
          sourceImage: {{ GlobalComputeUrl('cos-cloud', 'images', properties['containerImage']) }}
    networkInterfaces:
      - accessConfigs:
          - name: external-nat
            type: ONE_TO_ONE_NAT
        network: {{ GlobalComputeUrl(env['project'],  'networks', 'default') }}
    serviceAccounts:
      - email: default
        scopes:
        - https://www.googleapis.com/auth/logging.write
        - https://www.googleapis.com/auth/monitoring.write

【问题讨论】:

    标签: google-cloud-platform config google-deployment-manager


    【解决方案1】:

    可以使用 DM,但是...您确定要运行容器并同时在主机上安装 PHP 吗?如果您正在运行容器,我宁愿使用 PHP 添加另一个容器。这更有意义。

    无论如何,如果您想在主机上安装 PHP(和其他),您可以使用 metadata.startup-script(此处示例:https://github.com/GoogleCloudPlatform/deploymentmanager-samples/tree/master/examples/v2/metadata_from_file/jinja)。正如@fariya-rahmat 提到的那样——可能你想为它使用不同的操作系统。

    【讨论】:

      【解决方案2】:

      根据documentation

      您需要在 Container-Optimized OS 上为某些任务(例如调试)安装额外的软件包或工具。尽管 Container-Optimized OS 不包括包管理器,但您可以使用预安装的 toolbox 实用程序来安装任何其他包 或您需要的工具。使用 /usr/bin/toolbox 是安装和运行一次性调试工具的首选方法。

      Container-Optimized OS 不包括包管理器;因此,您将无法直接在实例上安装软件包。但是,您可以使用CoreOS toolbox 在隔离容器中安装和运行调试和管理工具。

      参考链接here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多