Last active
January 14, 2024 20:27
-
-
Save rameerez/b3e64acbe925c831ebea7c41680b4484 to your computer and use it in GitHub Desktop.
Configure an AWS EC2 instance running Amazon Linux 2023 to deploy Rails apps using Kamal (Docker)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This scrips takes a clean AWS Amazon Linux 2023 AMI and installs and configures | |
# everything needed to deploy a Rails app to it using Kamal. | |
# The resulting state is a clean instance ready to accept Kamal (Dockerized) apps. | |
# --- AESTHETICS --- | |
# Define the color code for green for echo messages | |
GREEN='\033[0;32m' | |
# Define the escape sequence for the alien emoji (U+1F47D) | |
ALIEN='\xF0\x9F\x91\xBD' | |
# Define the variable for resetting the color back to the default | |
NC='\033[0m' | |
# --- CONFIG SCRIPT STARTS --- | |
# Update package list and install Docker | |
echo -e "${GREEN}${ALIEN} Installing Docker and starting the Docker service...${NC}" | |
sudo dnf update -y | |
sudo dnf install -y docker --allowerasing | |
sudo systemctl start docker | |
echo -e "${GREEN}${ALIEN} Adding rails to the docker group and configuring the right Docker permissions...${NC}" | |
sudo chown root:docker /var/run/docker.sock | |
# Add current user to the docker group | |
sudo usermod -a -G docker $USER | |
# Update the group membership for the docker group - This will log us into a new shell session with the updated group membership. | |
newgrp docker | |
echo -e "${GREEN}${ALIEN} Restarting the Docker service...${NC}" | |
sudo systemctl restart docker | |
# crontab does not come installed by default in AL2023 (wtf?) | |
# echo -e "${GREEN}${ALIEN} Installing crontab to run scheduled background jobs...${NC}" | |
# sudo dnf install -y cronie | |
# sudo systemctl enable crond.service | |
# sudo systemctl start crond.service | |
# Delete previous command history so we leave the AMI in a clean state | |
history -c | |
echo -e "${GREEN}${ALIEN} Amazon Linux 2023 machine initial setup for Kamal deployments completed successfully.${NC}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment