Skip to content

Commit

Permalink
Automate postgres & redis setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ravisumit33 committed Sep 30, 2023
1 parent c32ace7 commit 2463565
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
28 changes: 25 additions & 3 deletions .ebextensions/postgres.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
packages:
yum:
postgresql-devel: []
commands:
01_update_yum:
command: "sudo yum update -y"
02_enable_postgresql14:
command: "sudo amazon-linux-extras enable postgresql14"
03_install_postgresql_devel:
command: "sudo yum install postgresql-devel -y"

## Below command is used for single-instance local postgres
04_postgresql_server_setup:
test: "[ ! -f /usr/bin/psql ]"
command: |
sudo yum install postgresql-server -y
sudo postgresql-setup initdb
sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo sed -i "/^host\s*all\s*all\s*.*$/ s/ident/scram-sha-256/" /var/lib/pgsql/data/pg_hba.conf
sudo systemctl restart postgresql
SECRETS_JSON=$(aws secretsmanager get-secret-value --secret-id "mysterio" --region "ap-south-1" --query "SecretString" --output text)
DB_NAME=$(echo "$SECRETS_JSON" | jq -r '.DB_NAME')
DB_PASS=$(echo "$SECRETS_JSON" | jq -r '.DB_PASSWORD')
DB_USER=$(echo "$SECRETS_JSON" | jq -r '.DB_USER')
sudo -u postgres psql -c "CREATE DATABASE ${DB_NAME};"
sudo -u postgres psql -c "CREATE USER ${DB_USER} WITH PASSWORD '${DB_PASS}';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${DB_USER};"
8 changes: 8 additions & 0 deletions .ebextensions/single-instance-redis.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
commands:
01_redis_server_setup:
test: "[ ! -f /usr/bin/redis-server ]"
command: |
sudo yum update -y
sudo amazon-linux-extras install redis6
sudo systemctl start redis
sudo systemctl enable redis

0 comments on commit 2463565

Please sign in to comment.