Skip to content
Snippets Groups Projects
Commit a8cd0b41 authored by Byron Biggs's avatar Byron Biggs
Browse files

First attempt for NGINX

parent 0cd3080c
No related branches found
No related tags found
No related merge requests found
terraform {
required_version = ">= 0.14.0"
required_version = ">= 0.14.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
......@@ -8,44 +8,65 @@ required_version = ">= 0.14.0"
}
}
resource "openstack_networking_floatingip_v2" "floating_ip_1" {
pool = var.pool
}
resource "openstack_networking_floatingip_v2" "floating_ip_1" {
pool = var.pool
}
resource "openstack_compute_secgroup_v2" "security_group" {
name = var.security_name
description = var.security_description
rule {
from_port = 22
to_port = 22
ip_protocol = "tcp"
cidr = "0.0.0.0/0"
}
rule {
from_port = 8080
to_port = 8080
ip_protocol = "tcp"
cidr = "0.0.0.0/0"
}
rule {
from_port = 8081
to_port = 8081
ip_protocol = "tcp"
cidr = "0.0.0.0/0"
}
resource "openstack_compute_secgroup_v2" "security_group" {
name = var.security_name
description = var.security_description
rule {
from_port = 22
to_port = 22
ip_protocol = "tcp"
cidr = "0.0.0.0/0"
}
resource "openstack_compute_instance_v2" "instance_1" {
name = var.name1
image_name = var.image
flavor_name = var.flavor
security_groups = [openstack_compute_secgroup_v2.security_group.name]
key_pair = var.keypair
user_data = file(var.server1_script)
network {
name = var.network
}
rule {
from_port = 8080
to_port = 8080
ip_protocol = "tcp"
cidr = "0.0.0.0/0"
}
rule {
from_port = 8081
to_port = 8081
ip_protocol = "tcp"
cidr = "0.0.0.0/0"
}
# Adding rule for HTTP traffic (port 80)
rule {
from_port = 80
to_port = 80
ip_protocol = "tcp"
cidr = "0.0.0.0/0"
}
resource "openstack_compute_floatingip_associate_v2" "floating_ip_1" {
floating_ip = openstack_networking_floatingip_v2.floating_ip_1.address
instance_id = openstack_compute_instance_v2.instance_1.id
# Adding rule for HTTPS traffic (port 443) if needed
rule {
from_port = 443
to_port = 443
ip_protocol = "tcp"
cidr = "0.0.0.0/0"
}
}
resource "openstack_compute_instance_v2" "instance_1" {
name = var.name1
image_name = var.image
flavor_name = var.flavor
security_groups = [openstack_compute_secgroup_v2.security_group.name]
key_pair = var.keypair
user_data = file(var.server1_script)
network {
name = var.network
}
}
resource "openstack_compute_floatingip_associate_v2" "floating_ip_1" {
floating_ip = openstack_networking_floatingip_v2.floating_ip_1.address
instance_id = openstack_compute_instance_v2.instance_1.id
}
# Output the floating IP for use in Jenkins
output "floating_ip_1" {
value = openstack_networking_floatingip_v2.floating_ip_1.address
}
\ No newline at end of file
......@@ -130,11 +130,63 @@ sudo unzip -d /opt/gradle gradle-7.6-bin.zip
echo "export PATH=\$PATH:/opt/gradle/gradle-7.6/bin" >> ~/.bashrc
source ~/.bashrc
# Install NGINX
echo "=== Installing and configuring NGINX ==="
sudo dnf install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
# Configure NGINX as reverse proxy for Spring Boot
echo "=== Configuring NGINX as reverse proxy ==="
cat << EOF > /etc/nginx/conf.d/springboot.conf
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
}
EOF
# Remove default nginx configuration
sudo rm -f /etc/nginx/conf.d/default.conf
# Restart NGINX to apply changes
sudo systemctl restart nginx
# Build and run the Polish community group application
echo "=== Building and running Polish community application ==="
echo "=== Building Polish community application ==="
cd ~/fork-team-10-polish-community-group
export PATH=$PATH:/opt/gradle/gradle-7.6/bin
gradle build
nohup gradle bootrun &
# Create a systemd service for Spring Boot application
echo "=== Creating systemd service for Spring Boot ==="
cat << EOF > /etc/systemd/system/springboot.service
[Unit]
Description=Spring Boot Application
After=syslog.target network.target
[Service]
User=root
WorkingDirectory=/root/fork-team-10-polish-community-group
ExecStart=/opt/gradle/gradle-7.6/bin/gradle bootRun
SuccessExitStatus=143
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
# Enable and start the Spring Boot service
sudo systemctl daemon-reload
sudo systemctl enable springboot
sudo systemctl start springboot
echo "=== Provisioning complete ==="
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment