Skip to content

Commit 28e23e4

Browse files
committed
cleaning readme
1 parent 5fe9841 commit 28e23e4

File tree

9 files changed

+172
-37
lines changed

9 files changed

+172
-37
lines changed

samples/bookstore-demo/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ buildNumber.properties
5252

5353
.terraform*
5454
terraform.tfstate
55-
terraform.tfstate.backup
55+
terraform.tfstate.backup
56+
.tfvars
57+
.idea

samples/bookstore-demo/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ If you want to run the whole thing within docker (the project itself as well as
1212
docker compose up
1313
```
1414

15+
### Remotely
16+
17+
To run the app remotely, we have terraform for aws & gcp. To use them simply cd to your preferred platform, create a .tfvars file using `mv .tfvars.example .tfvars`, fill in the appropriate settings and then run the following:
18+
19+
```bash
20+
terraform init
21+
terraform plan -var-file=.tfvars
22+
terraform apply -var-file=.tfvars --auto-approve
23+
```
24+
25+
It will take some time to build (after the resource are created) but it will be deployed to `bookstore.your.subdomain.tld`
26+
1527
### Locally
1628

1729
To run this project you must first install the required jars locally:

samples/bookstore-demo/settings.xml

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ssh_key_file = ""
2+
aws_dns_zone = ""
3+
aws_region = ""
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
provider "aws" {
2+
region = "${var.aws_region}"
3+
}
4+
5+
resource "aws_key_pair" "sshKey" {
6+
key_name = "sessions-test-ssh-key"
7+
public_key = file("${var.ssh_key_file}")
8+
}
9+
10+
resource "aws_instance" "fe-sessions-test-vm" {
11+
ami = "ami-02b71e4c18caedcb5"
12+
instance_type = "t2.medium"
13+
key_name = aws_key_pair.sshKey.key_name
14+
15+
tags = {
16+
name = "fe-sessions-test-vm"
17+
}
18+
19+
user_data = <<-EOF
20+
#!/bin/bash
21+
sudo apt-get update
22+
sudo apt-get install -y openjdk-17-jdk git docker.io docker-compose
23+
24+
sudo mkdir -p /usr/local/lib/docker/cli-plugins
25+
sudo curl -SL https://github.com/docker/compose/releases/download/v2.22.0/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
26+
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
27+
28+
#start Docker service
29+
30+
# Start Docker service
31+
sudo systemctl start docker
32+
sudo systemctl enable docker
33+
34+
git clone https://@github.com/redis-field-engineering/redis-sessions-java-dist
35+
cd redis-sessions-java-dist/samples/bookstore-demo
36+
./mvnw clean package
37+
docker compose up -d
38+
EOF
39+
}
40+
41+
data "aws_route53_zone" "redisdemo_zone"{
42+
name = "${var.aws_dns_zone}"
43+
}
44+
45+
resource "aws_route53_record" "fe-sessions-test-vm-a-record" {
46+
zone_id = data.aws_route53_zone.redisdemo_zone.zone_id
47+
name = "bookstore"
48+
type = "A"
49+
ttl = "300"
50+
records = [aws_instance.fe-sessions-test-vm.public_ip]
51+
depends_on = [aws_instance.fe-sessions-test-vm]
52+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
variable "aws_dns_zone" {
2+
type = string
3+
sensitive = true
4+
description = "The DNS zone you're going to use for the app"
5+
}
6+
7+
variable "aws_region" {
8+
type = string
9+
sensitive = true
10+
description = "The AWS region to deploy the app to"
11+
12+
}
13+
14+
variable "ssh_key_file"{
15+
type = string
16+
description = "Path to the SSH public key file"
17+
}

samples/bookstore-demo/terraform/gcp/.tfvars.example

Whitespace-only changes.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
provider "google" {
2+
project = "${var.gcp-project}"
3+
region = "${var.gcp-region}"
4+
}
5+
6+
resource "google_compute_instance" "redis-sessions-java-bookstore-demo-vm"{
7+
machine_type = "n2-standard-8"
8+
name = "redis-sessions-java-bookstore-demo-vm"
9+
zone = "${var.gcp-zone}"
10+
11+
boot_disk {
12+
initialize_params {
13+
image = "ubuntu-2004-focal-v20240731"
14+
size = 50
15+
}
16+
17+
auto_delete = true
18+
}
19+
20+
network_interface {
21+
network = "default"
22+
access_config {
23+
}
24+
}
25+
26+
metadata_startup_script = <<-EOT
27+
#!/bin/bash
28+
apt-get update
29+
apt-get install -y openjdk-17-jdk git docker.io docker-compose
30+
31+
mkdir -p /usr/local/lib/docker/cli-plugins
32+
curl -SL https://github.com/docker/compose/releases/download/v2.22.0/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
33+
chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
34+
35+
# Start Docker service
36+
systemctl start docker
37+
systemctl enable docker
38+
39+
# Git repository clone with error handling
40+
git clone https://github.com/redis-field-engineering/redis-sessions-java-dist
41+
cd redis-sessions-java-dist/samples/bookstore-demo
42+
./mvnw -s ./settings.xml clean package
43+
docker compose up -d
44+
EOT
45+
46+
}
47+
48+
resource "google_dns_record_set" "app_dns" {
49+
managed_zone = "${var.dns-zone-name}"
50+
name = "bookstore.${var.subdomain}."
51+
rrdatas = [google_compute_instance.redis-sessions-java-bookstore-demo-vm.network_interface[0].access_config[0].nat_ip]
52+
type = "A"
53+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
variable "gcp-project" {
2+
type = string
3+
sensitive = true
4+
description = "The GCP Project to deploy the app to"
5+
}
6+
7+
variable "gcp-region" {
8+
type = string
9+
sensitive = true
10+
description = "The GCP Region to deploy the app to"
11+
12+
}
13+
14+
variable "gcp-zone" {
15+
type = string
16+
sensitive = true
17+
description = "The GCP Zone to deploy the app to"
18+
19+
}
20+
21+
variable "dns-zone-name" {
22+
type = string
23+
sensitive = true
24+
description = "The DNS Zone to deploy the app to"
25+
}
26+
27+
variable "subdomain" {
28+
type = string
29+
sensitive = true
30+
description = "The subdomain to deploy the app to"
31+
32+
}

0 commit comments

Comments
 (0)