Skip to content

Commit

Permalink
Add the GCP Jinja template for clustering deployment.
Browse files Browse the repository at this point in the history
  • Loading branch information
muratugureminoglu committed Apr 22, 2024
1 parent ce65ec6 commit 2852c04
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 0 deletions.
45 changes: 45 additions & 0 deletions gcp-jinja-template/antmedia-firewall-template.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{#
Copyright 2016 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#}

resources:
- type: compute.v1.firewall
name: ams-mongodb-internal
properties:
network: $(ref.antmedia-vpc-network.selfLink)
sourceRanges:
- 10.0.0.0/16
targetTags:
- antmedia-mongodb
allowed:
- IPProtocol: tcp
ports:
- "27017"
- "22"

- type: compute.v1.firewall
name: ams-antmedia-external
properties:
network: $(ref.antmedia-vpc-network.selfLink)
sourceRanges:
- 0.0.0.0/0
targetTags:
- antmedia
allowed:
- IPProtocol: tcp
ports:
- "5080"
- "22"
- "1935"

25 changes: 25 additions & 0 deletions gcp-jinja-template/antmedia-instance-group-template.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
resources:
- name: origin-instance-group
type: compute.v1.instanceGroupManager
properties:
zone: {{ default_zone }}
targetSize: 1
baseInstanceName: my-instance
instanceTemplate: projects/{{ env["project"] }}/global/instanceTemplates/ams-origin-template
namedPorts:
- name: http
port: 5080

- name: origin-autoscaler
type: compute.v1.autoscaler
properties:
zone: {{ default_zone }}
target: $(ref.origin-instance-group.selfLink)
autoscalingPolicy:
minNumReplicas: 1
maxNumReplicas: 10
coolDownPeriodSec: 60
cpuUtilization:
utilizationTarget: 0.6


60 changes: 60 additions & 0 deletions gcp-jinja-template/antmedia-instance-template.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
resources:
- name: ams-origin-template
type: compute.v1.instanceTemplate
properties:
properties:
zone: {{ properties["zone"] }}
machineType: {{ properties["origin_machine_type"] }}
metadata:
items:
- key: startup-script
value: |-
#!/bin/bash
rm -rf /usr/local/antmedia/conf/instanceId
rm -rf /usr/local/antmedia/*.db.*
rm -rf /usr/local/antmedia/*.db
cd /usr/local/antmedia
./change_server_mode.sh cluster $(ref.{{ env["deployment"] }}-mongodb.networkInterfaces[0].networkIP)
disks:
- deviceName: boot
type: PERSISTENT
boot: true
autoDelete: true
initializeParams:
sourceImage: projects/antmedia-public-385620/global/images/ams-marketplace282
networkInterfaces:
- network: $(ref.antmedia-vpc-network.selfLink)
subnetwork: $(ref.origin-subnet.selfLink)
accessConfigs:
- name: External NAT
type: ONE_TO_ONE_NAT

- name: ams-edge-template
type: compute.v1.instanceTemplate
properties:
properties:
zone: {{ properties["zone"] }}
machineType: {{ properties["edge_machine_type"] }}
metadata:
items:
- key: startup-script
value: |-
#!/bin/bash
rm -rf /usr/local/antmedia/conf/instanceId
rm -rf /usr/local/antmedia/*.db.*
rm -rf /usr/local/antmedia/*.db
cd /usr/local/antmedia
./change_server_mode.sh cluster $(ref.{{ env["deployment"] }}-mongodb.networkInterfaces[0].networkIP)
disks:
- deviceName: boot
type: PERSISTENT
boot: true
autoDelete: true
initializeParams:
sourceImage: projects/antmedia-public-385620/global/images/ams-marketplace282
networkInterfaces:
- network: $(ref.antmedia-vpc-network.selfLink)
subnetwork: $(ref.edge-subnet.selfLink)
accessConfigs:
- name: External NAT
type: ONE_TO_ONE_NAT
47 changes: 47 additions & 0 deletions gcp-jinja-template/antmedia-mongodb-template.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{#
Copyright 2016 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#}

resources:
- type: compute.v1.instance
name: {{ env["deployment"] }}-mongodb
properties:
zone: {{ properties["zone"] }}
machineType: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/zones/{{ properties["zone"] }}/machineTypes/{{ properties["machine_type"] }}
metadata:
items:
# For more ways to use startup scripts on an instance, see:
# https://cloud.google.com/compute/docs/startupscript
- key: startup-script
value: |
#!/bin/bash
wget https://raw.githubusercontent.com/ant-media/Scripts/master/install_mongodb.sh
bash ./install_mongodb.sh
disks:
- deviceName: boot
type: PERSISTENT
boot: true
autoDelete: true
initializeParams:
sourceImage: https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/family/ubuntu-2204-lts
networkInterfaces:
- network: $(ref.antmedia-vpc-network.selfLink)
subnetwork: $(ref.origin-subnet.selfLink)
# Access Config required to give the instance a public IP address
accessConfigs:
- name: External NAT
type: ONE_TO_ONE_NAT
tags:
items:
- antmedia-mongodb
33 changes: 33 additions & 0 deletions gcp-jinja-template/antmedia-vpc-template.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resources:
- name: antmedia-vpc-network
type: compute.v1.network
properties:
region: {{ properties["region"] }}
autoCreateSubnetworks: false

- name: origin-subnet
type: compute.v1.subnetwork
properties:
ipCidrRange: 10.0.1.0/24
network: $(ref.antmedia-vpc-network.selfLink)
region: {{ properties["region"] }}

- name: edge-subnet
type: compute.v1.subnetwork
properties:
ipCidrRange: 10.0.2.0/24
network: $(ref.antmedia-vpc-network.selfLink)
region: {{ properties["region"] }}

- name: firewall-rule
type: compute.v1.firewall
properties:
network: $(ref.antmedia-vpc-network.selfLink)
sourceRanges:
- 0.0.0.0/0
allowed:
- IPProtocol: tcp
ports:
- "80"
- "443"
- "22"
43 changes: 43 additions & 0 deletions gcp-jinja-template/antmedia.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{#
Copyright 2016 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#}

{% set default_zone = "us-central1-a" %}
{% set default_region = "us-central1" %}
{% set mongodb_machine_type = "e2-standard-2" %}
{% set origin_machine_type = "e2-standard-2" %}
{% set edge_machine_type = "e2-standard-2" %}


resources:
- name: antmedia-mongodb
type: antmedia-mongodb-template.jinja
properties:
zone: {{ default_zone }}
machine_type: {{ mongodb_machine_type }}
- name: antmedia-instance
type: antmedia-instance-template.jinja
properties:
zone: {{ default_zone }}
origin_machine_type: {{ origin_machine_type }}
edge_machine_type: {{ edge_machine_type }}
- name: antmedia-firewall
type: antmedia-firewall-template.jinja
properties:
zone: {{ default_zone}}
- name: antmedia-vpc-network
type: antmedia-vpc-template.jinja
properties:
region: {{ default_region}}
autoCreateSubnetworks: false
25 changes: 25 additions & 0 deletions gcp-jinja-template/antmedia.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

imports:
- path: antmedia-mongodb-template.jinja
- path: antmedia-instance-template.jinja
- path: antmedia-firewall-template.jinja
- path: antmedia-vpc-template.jinja
- path: antmedia.jinja

resources:
- name: antmedia
type: antmedia.jinja

16 changes: 16 additions & 0 deletions gcp-jinja-template/backend.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
# Your resource definitions go here under resources key
resources:
- name: my-backend-service # Replace with your desired name
type: compute.v1.backendService # Adjust type based on resource
properties:
portName: http
protocol: HTTP
backend:
group: origin-instance-group # Assuming your instance group name
healthChecks:
- https://www.googleapis.com/compute/v1/healthChecks/default

# You can add other outputs here if needed
output:
# ...

0 comments on commit 2852c04

Please sign in to comment.