From 70a06f2f7384e85936c62e36980cc47c407ffaf6 Mon Sep 17 00:00:00 2001 From: Isaac Hunter Date: Sat, 2 Mar 2024 20:11:52 -0500 Subject: [PATCH] connect frontend to ec2 container --- deploy/ec2.tf | 4 ++-- deploy/sample.tfvars | 8 ++++++++ deploy/templates/ec2/server-setup.sh.tpl | 24 ++++++++++++++++-------- deploy/variables.tf | 4 ++-- proxy/default.conf.tpl | 4 +++- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/deploy/ec2.tf b/deploy/ec2.tf index 458440c..9a97e15 100644 --- a/deploy/ec2.tf +++ b/deploy/ec2.tf @@ -52,8 +52,8 @@ resource "aws_instance" "jukebox_server" { JWT_SECRET_KEY = var.SERVER__JWT_SECRET_KEY TOKEN_HEADER_KEY = var.SERVER__TOKEN_HEADER_KEY MONGO_URI = "mongodb://${var.DB__MONGO_USER}:${var.DB__MONGO_PASSWORD}@mongodb:27017" - SP_ID = var.SERVER__SP_ID - SP_SECRET = var.SERVER__SP_SECRET + SP_ID = var.SERVER__SPOTIFY_CLIENT_ID + SP_SECRET = var.SERVER__SPOTIFY_CLIENT_SECRET MONGO_USER = var.DB__MONGO_USER MONGO_PASSWORD = var.DB__MONGO_PASSWORD } }) diff --git a/deploy/sample.tfvars b/deploy/sample.tfvars index e69de29..164625f 100644 --- a/deploy/sample.tfvars +++ b/deploy/sample.tfvars @@ -0,0 +1,8 @@ +ssh_key_name = "some_key" + +SERVER__JWT_SECRET_KEY = "very_long_secret_key" +SPOTIFY_CLIENT_ID="changeme" +SPOTIFY_CLIENT_SECRET="supersecret" + +DB__MONGO_USER = "root" +DB__MONGO_PASSWORD = "password" \ No newline at end of file diff --git a/deploy/templates/ec2/server-setup.sh.tpl b/deploy/templates/ec2/server-setup.sh.tpl index 51a0e54..db631c5 100644 --- a/deploy/templates/ec2/server-setup.sh.tpl +++ b/deploy/templates/ec2/server-setup.sh.tpl @@ -1,29 +1,37 @@ #!/bin/bash -set -e +set -e # Exit if a command yields a non-zero exit code +# Update yum and install Docker onto the EC2 server sudo yum update -y sudo yum install -y docker +# Start up Docker sudo service docker start sudo chkconfig docker on # auto restart docker -# sudo systemctl enable docker.service -# sudo systemctl start docker.service - +# Install Docker Compose sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose - sudo usermod -aG docker ec2-user # Add user to "docker" group for permissions -# cd ~ - +# Install git sudo yum install -y git -git clone https://github.com/ufosc/Jukebox-Server.git /home/ec2-user/Jukebox-Server +# Jukebox-Server Configuration ======================== +git clone https://github.com/ufosc/Jukebox-Server.git /home/ec2-user/Jukebox-Server +echo "# Environment Variables, created by terraform on $(date)" > /home/ec2-user/Jukebox-Server/.env %{ for env_key, env_value in env } echo "${env_key}=${env_value}" >> /home/ec2-user/Jukebox-Server/.env %{ endfor ~} + sudo docker-compose -f /home/ec2-user/Jukebox-Server/docker-compose.prod.yml up -d --build +# Jukebox-Frontend Configuration ====================== +git clone https://github.com/ufosc/Jukebox-Frontend.git /home/ec2-user/Jukebox-Frontend +sudo docker-compose -f /home/ec2-user/Jukebox-Frontend/docker-compose.network.yml run --rm client sh -c "npm run build" --build + + + + diff --git a/deploy/variables.tf b/deploy/variables.tf index 7728de5..e7afa02 100644 --- a/deploy/variables.tf +++ b/deploy/variables.tf @@ -48,10 +48,10 @@ variable "SERVER__TOKEN_HEADER_KEY" { default = "Authorization" } # -variable "SERVER__SP_ID" { +variable "SERVER__SPOTIFY_CLIENT_ID" { description = "Spotify App ID" } -variable "SERVER__SP_SECRET" { +variable "SERVER__SPOTIFY_CLIENT_SECRET" { description = "Spotify App Secret" } diff --git a/proxy/default.conf.tpl b/proxy/default.conf.tpl index 375a94a..0437149 100644 --- a/proxy/default.conf.tpl +++ b/proxy/default.conf.tpl @@ -12,7 +12,9 @@ server { location / { root /vol/client; index index.html index.htm; + + # try_files $uri $uri/ index.html; + error_page 404 =200 /index.html; } - error_page 404 =200 index.html; } \ No newline at end of file