diff --git a/app.yaml b/app.yaml new file mode 100644 index 0000000..5d06555 --- /dev/null +++ b/app.yaml @@ -0,0 +1,18 @@ +# [START appengine_websockets_yaml] +runtime: nodejs +env: flex + +# Use only a single instance, so that this local-memory-only chat app will work +# consistently with multiple users. To work across multiple instances, an +# extra-instance messaging system or data store would be needed. +manual_scaling: + instances: 1 + +# [START network] +network: + instance_tag: websocket + forwarded_ports: + - 65080 + session_affinity: true +# [END network] +# [END appengine_websockets_yaml] diff --git a/docker/api/api.fifa.sauravmh.com.conf b/docker/api/api.fifa.sauravmh.com.conf new file mode 100644 index 0000000..e087f50 --- /dev/null +++ b/docker/api/api.fifa.sauravmh.com.conf @@ -0,0 +1,27 @@ +upstream socket-server-upstream { + ip_hash; + server http-api:8080; + server socketio-api:65080; + keepalive 16; +} + +server { + listen 80; + server_name api.fifa.sauravmh.com; + error_log /var/log/nginx/error.log; + access_log /var/log/nginx/access.log; + root /app; + + location / { + proxy_pass http://localhost:8080/; + proxy_http_version 1.1; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + + proxy_cache_bypass $http_upgrade; + proxy_hide_header X-Powered-By; + } +} diff --git a/docker/api/socker.fifa.sauravmh.com.conf b/docker/api/socker.fifa.sauravmh.com.conf new file mode 100644 index 0000000..312c2d5 --- /dev/null +++ b/docker/api/socker.fifa.sauravmh.com.conf @@ -0,0 +1,54 @@ +upstream socket-server-upstream { + ip_hash; + server http-api:8080; + server socketio-api:65080; + keepalive 16; +} + +server { + listen 443 ssl; + server_name api.mydomain.com; + + include conf.d/error-pages.conf; + include conf.d/url-filter*.conf; + + root /home/saurav/my_application; + + location / { + proxy_pass http://localhost:3000/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + proxy_hide_header X-Powered-By; + } + +} + +server { + listen 80; + index index.html; + server_name currently-viewing-app.dev; + error_log /var/log/nginx/error.log; + access_log /var/log/nginx/access.log; + root /app; + + location / { + try_files $uri /index.html; + } + + location /socket.io/ { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_set_header X-NginX-Proxy true; + + proxy_pass http://socket-server-upstream/socket.io/; + proxy_redirect off; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } +} diff --git a/shared/shared.tf b/shared/shared.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/dev/.terraform.lock.hcl b/terraform/dev/.terraform.lock.hcl new file mode 100644 index 0000000..efe30d6 --- /dev/null +++ b/terraform/dev/.terraform.lock.hcl @@ -0,0 +1,22 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/google" { + version = "3.5.0" + constraints = "3.5.0" + hashes = [ + "h1:g1dSPkP3+HREeNKoGGRVqeWMl5AonGy8MtOpuhr3rGc=", + "zh:1bd907d58a05ec25d48294f6a0d7ab215d7243daa8a100ee983981ca641d2ce9", + "zh:334c0ac7599da444434d5cd1045171b8decf4eec1d01a69dd9a343e62ca8ffc0", + "zh:738c0808e29d14e9508f121c1966fa557b3db83fb5b0ce9b32ffebfbcc610dbe", + "zh:8b4c910d558d3176f96c50bca9c3484edd0df2a7429bf1609cd5aca2cf1aeab8", + "zh:a1e3d0057158267c2d86a5fc46cfa50e86cf70a60f242a96c66710c48d97bc04", + "zh:a718d621c671cb6d1d951e070ed9f52710a2441fa14e1aee7c00e14396142f9a", + "zh:ac1381f6e42de469a2842af8ba110787c9a7c1a1b250a53fe0831b70f54a56f6", + "zh:af979d49936061c0c37c1df7ddfbf1bca6b1f347562c8917b4e063ac7c354af7", + "zh:af9a7e94706d4155f88b2547620edc2ebfeaf2c4bb8f670a75e04ab7470c6640", + "zh:d820fb164d3f7da15aa4963a59f05134362b28c983d0cfc30ee3e325bc3362cb", + "zh:e1cd06c6ed45dd0d644b4afec7b8499e7be6337d45f4b802c933dd0016efc326", + "zh:fe6e7ea5f1a1d7876ac9939eb8cfc1376536d25ad7ecc86f5d6660c5b09a9de3", + ] +} diff --git a/terraform/dev/main.tf b/terraform/dev/main.tf new file mode 100644 index 0000000..f8cdbe6 --- /dev/null +++ b/terraform/dev/main.tf @@ -0,0 +1,64 @@ +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "3.5.0" + } + } +} + +provider "google" { + project = var.project_name + region = var.region + zone = var.region_zone + credentials = file("${var.credentials_file_path}") +} + +resource "google_compute_http_health_check" "default" { + name = "tf-www-basic-check" + request_path = "/" + check_interval_sec = 1 + healthy_threshold = 1 + unhealthy_threshold = 10 + timeout_sec = 1 +} + +resource "google_compute_instance" "app_server" { + name = "fifa-server" + machine_type = "e2-small" + tags = ["ssh", "http-server", "https-server"] + + metadata = { + user-data = module.container-server.cloud_config # 👈 + } + + service_account { + email = google_service_account.default.email + scopes = ["https://www.googleapis.com/auth/cloud-platform"] + } + + boot_disk { + initialize_params { + image = data.google_compute_image.cos.self_link + } + } + + network_interface { + subnetwork = var.subnet_name + subnetwork_project = var.project + + access_config { + nat_ip = google_compute_address.static.address + } + } + + scheduling { + automatic_restart = true + } + + allow_stopping_for_update = true + + lifecycle { + ignore_changes = [attached_disk] + } +} diff --git a/terraform/dev/variables.tf b/terraform/dev/variables.tf new file mode 100644 index 0000000..f68e42a --- /dev/null +++ b/terraform/dev/variables.tf @@ -0,0 +1,21 @@ +variable "region" { + default = "asia-south1" +} + +variable "region_zone" { + default = "asia-south1-c" +} + +variable "project_name" { + description = "turn-multiplayer-game" +} + +variable "credentials_file_path" { + description = "Path to the JSON file used to describe your account credentials" + default = "google-compute-engine-account.json" +} + +variable "public_key_path" { + description = "Path to file containing public key" + default = "~/.ssh/gcloud_id_rsa.pub" +}