I want do deploy a PHP app via the Google Cloud Deployment Manager. After an instance has been created, PHP (and some other Linux packages) should be installed on the VM. Is this possible within the template file? Or do I have to create a custom VM image?
I only managed to create the VM, but didn't find anything on how to automatically install packages.
{% 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
It is possible using DM, but... are you sure you want to run containers and at the same time install PHP on the host? If you're runnning containers, I'd rather add another container with PHP. It makes more sense.
Anyway, if you want to install PHP (and others) on host, you can use a metadata.startup-script (example here: https://github.com/GoogleCloudPlatform/deploymentmanager-samples/tree/master/examples/v2/metadata_from_file/jinja). As @fariya-rahmat mentioned - probably you want to use a different OS for it.