Skip to content

Commit

Permalink
fix install issue
Browse files Browse the repository at this point in the history
  • Loading branch information
proquickly committed Dec 9, 2024
1 parent aed889f commit ef5ac2e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 46 deletions.
48 changes: 2 additions & 46 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,51 +99,8 @@ resource "aws_instance" "py_server" {
ami = "ami-06946f6c9b153d494"
instance_type = "t2.micro"
key_name = aws_key_pair.deployer.key_name
user_data = <<-EOF
#!/bin/bash
PROJ="tfgha"
POETRY="/home/ubuntu/.local/bin"
WORKDIR="/home/ubuntu"
# Update package lists
if ! sudo apt-get update; then
echo "Failed to update package lists"
exit 1
fi
# Install necessary packages
if ! sudo apt-get install -y python3 python3-pip git curl; then
echo "Failed to install packages"
exit 1
fi
# Change to the working directory
cd "$WORKDIR" || { echo "Failed to change directory to $WORKDIR"; exit 1; }
# Clone the project
if ! git clone "https://github.com/proquickly/$PROJ.git"; then
echo "Failed to clone the repository"
exit 1
fi
# Change ownership
if ! sudo chown -R ubuntu:ubuntu "$WORKDIR"; then
echo "Failed to change ownership"
exit 1
fi
# Run as the ubuntu user
sudo -u ubuntu bash <<EOF
set -e
python3 -m pip install -U poetry
cd "$WORKDIR/$PROJ"
export PATH="$WORKDIR/.local/bin:\$PATH"
[ -f poetry.lock ] && rm poetry.lock
$POETRY/poetry install
cd "$WORKDIR/$PROJ/src/$PROJ"
nohup $POETRY/poetry run python app.py &
EOF

user_data = file("setup.sh")

tags = {
Name = "FlaskAppInstance"
Expand All @@ -153,4 +110,3 @@ resource "aws_instance" "py_server" {
aws_security_group.allow_http.id, aws_security_group.allow_ssh.id
]
}
# c
43 changes: 43 additions & 0 deletions terraform/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

PROJ="tfgha"
POETRY="/home/ubuntu/.local/bin"
WORKDIR="/home/ubuntu"

# Update package lists
if ! sudo apt-get update; then
echo "Failed to update package lists"
exit 1
fi

# Install necessary packages
if ! sudo apt-get install -y python3 python3-pip git curl; then
echo "Failed to install packages"
exit 1
fi

# Change to the working directory
cd "$WORKDIR" || { echo "Failed to change directory to $WORKDIR"; exit 1; }

# Clone the project
if ! git clone "https://github.com/proquickly/$PROJ.git"; then
echo "Failed to clone the repository"
exit 1
fi

# Change ownership
if ! sudo chown -R ubuntu:ubuntu "$WORKDIR"; then
echo "Failed to change ownership"
exit 1
fi

# Run as the ubuntu user
sudo -u ubuntu bash <<EOF
set -e
python3 -m pip install -U poetry
cd "$WORKDIR/$PROJ"
export PATH="$WORKDIR/.local/bin:\$PATH"
[ -f poetry.lock ] && rm poetry.lock
$POETRY/poetry install
cd "$WORKDIR/$PROJ/src/$PROJ"
nohup $POETRY/poetry run python app.py &

0 comments on commit ef5ac2e

Please sign in to comment.