Skip to content

Commit

Permalink
feat: add linux automation script and extend support for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar5526 committed Dec 28, 2023
1 parent a16aca0 commit 63a0353
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
8 changes: 3 additions & 5 deletions server/.env.sample
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# vars mostly used in local development
BASE_DIR='/Users/tusharsamagra/projects/sarthi/server/deployments'
NGINX_PROXY_CONF_LOCATION='/Users/tusharsamagra/projects/sarthi/server/nginx-confs'
DEPLOYMENTS_MOUNT_DIR='/home/ubuntu/sarthi/server'
NGINX_PROXY_CONF_LOCATION='/home/ubuntu/sarthi/server/nginx-confs'
ENV=local
DEPLOYMENT_HOST='localhost'
# mac hack
DOCKER_MOUNT_DIR='/Users/tusharsamagra/projects/sarthi/server/deployments'


# this should be your wildcard domain name
DOMAIN_NAME=localhost
15 changes: 10 additions & 5 deletions server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ services:
container_name: sarthi_nginx
ports:
- "80:80"
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- ./nginx-confs:/etc/nginx/conf.d

Expand All @@ -17,10 +19,13 @@ services:
# hack to bypass file resource sharing error to make my development easy on mac
# docker mount dir not meant to be used on linux
# not tested and no support for windows server 💩
- ./deployments:${DOCKER_MOUNT_DIR:-/deployments}
- ./nginx-confs:/nginx-confs
- ./deployments:${DEPLOYMENTS_MOUNT_DIR}
- ./nginx-confs:${NGINX_PROXY_CONF_LOCATION}
- /var/run/docker.sock:/var/run/docker.sock
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
BASE_DIR: ${DOCKER_MOUNT_DIR:-/deployments}
NGINX_PROXY_CONF_LOCATION: '/nginx-confs'
ENV: local
DEPLOYMENTS_MOUNT_DIR: ${DEPLOYMENTS_MOUNT_DIR}
NGINX_PROXY_CONF_LOCATION: ${NGINX_PROXY_CONF_LOCATION}
ENV: ${ENV:-local}
DOMAIN_NAME: ${DOMAIN_NAME:-localhost}
4 changes: 2 additions & 2 deletions server/sarthi/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
class Deployer:
def __init__(self, config: DeploymentConfig):
self._config = config
self._BASE_DIR: typing.Final[str] = os.environ.get("BASE_DIR")
self._DEPLOYMENTS_MOUNT_DIR: typing.Final[str] = os.environ.get("DEPLOYMENTS_MOUNT_DIR")
self._project_path: typing.Final[str] = os.path.join(
self._BASE_DIR, config.get_project_hash()
self._DEPLOYMENTS_MOUNT_DIR, config.get_project_hash()
)
self._setup_project()

Expand Down
48 changes: 48 additions & 0 deletions server/setup-sarthi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Emojis
CHECK_MARK='✔️'
CROSS_MARK=''
WARNING='⚠️'
DOCKER='🐳'

# Check if script is run as root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}${CROSS_MARK} Please run as root.${NC}" >&2
exit 1
fi

# Update package index
echo -e "${YELLOW}${WARNING} Updating package index...${NC}"
apt update

# Install prerequisites
echo -e "${YELLOW}${WARNING} Installing prerequisites...${NC}"
apt install -y apt-transport-https ca-certificates curl software-properties-common

# Install Docker
echo -e "${YELLOW}${WARNING} Installing Docker...${NC}"
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
rm get-docker.sh

# Add user to docker group
echo -e "${YELLOW}${WARNING} Adding user to the docker group...${NC}"
usermod -aG docker $USER
newgrp docker


# Install Docker Compose
echo -e "${YELLOW}${WARNING} Installing Docker Compose...${NC}"
curl -sSL https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

# Display success message
echo -e "${GREEN}${CHECK_MARK} Docker and Docker Compose installed successfully.${NC}"
echo -e "${DOCKER} ${YELLOW}You may need to restart your shell or log out and log back in to apply the changes.${NC}"

0 comments on commit 63a0353

Please sign in to comment.