feat: add Forgejo workflow to automate LEMP stack installation on EC2
This commit is contained in:
parent
ee53672229
commit
13151237b4
1 changed files with 56 additions and 0 deletions
56
.forgejo/workflows/setup-ec2.yml
Normal file
56
.forgejo/workflows/setup-ec2.yml
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
name: Setup EC2 Tools
|
||||
|
||||
on:
|
||||
workflow_dispatch: # Allows you to trigger this manually from the Forgejo Actions UI
|
||||
|
||||
jobs:
|
||||
setup-server:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Install LEMP Stack and Tools on EC2
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.BETA_EC2_HOST }}
|
||||
username: ${{ secrets.BETA_EC2_USERNAME }}
|
||||
key: ${{ secrets.BETA_EC2_SSH_KEY }}
|
||||
script: |
|
||||
echo "Starting EC2 Server Setup..."
|
||||
|
||||
# 1. Update package list
|
||||
sudo apt-get update -y
|
||||
sudo apt-get upgrade -y
|
||||
sudo apt-get install -y software-properties-common curl git unzip nginx supervisor redis-server
|
||||
|
||||
# 2. Add PHP repository and install PHP 8.2 with required extensions
|
||||
sudo add-apt-repository -y ppa:ondrej/php
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y php8.2-fpm php8.2-cli php8.2-pgsql php8.2-mbstring php8.2-xml php8.2-curl php8.2-zip php8.2-bcmath php8.2-intl php8.2-redis
|
||||
|
||||
# 3. Install Composer (PHP Package Manager)
|
||||
if ! command -v composer &> /dev/null; then
|
||||
echo "Installing Composer..."
|
||||
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
|
||||
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
||||
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
|
||||
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then
|
||||
>&2 echo 'ERROR: Invalid installer checksum'
|
||||
rm composer-setup.php
|
||||
exit 1
|
||||
fi
|
||||
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
|
||||
rm composer-setup.php
|
||||
fi
|
||||
|
||||
# 4. Install Node.js (v20) and NPM for building frontend assets
|
||||
if ! command -v node &> /dev/null; then
|
||||
echo "Installing Node.js..."
|
||||
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
||||
sudo apt-get install -y nodejs
|
||||
fi
|
||||
|
||||
# 5. Create web directory and set basic permissions
|
||||
sudo mkdir -p /var/www/trypost
|
||||
sudo chown -R $USER:$USER /var/www/trypost
|
||||
|
||||
echo "Setup Complete! Tools installed: Nginx, PHP 8.2, Composer, Node.js, Supervisor, Redis"
|
||||
Loading…
Reference in a new issue