@@ -3,7 +3,7 @@ name: Deploy on EC2 CI
33on :
44 push :
55 branches :
6- - deploy-fxmodel-docker
6+ - dev2
77
88jobs :
99 deploy :
@@ -18,19 +18,37 @@ jobs:
1818 ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
1919
2020 - name : Deploy on EC2
21- # checks if no folder than clones , if exists than pulls latest
22- # shell scripting, fi is used to mark the end of an if statement
23- # In shell scripting, EOF (End of File) is commonly used to denote the end of a block of text that is being redirected as input to a command
2421 run : |
2522 ssh ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
23+
24+ # === INSTALL DOCKER IF NOT INSTALLED ===
25+ if ! command -v docker &> /dev/null; then
26+ echo "Installing Docker..."
27+ sudo apt-get update
28+ sudo apt-get install -y ca-certificates curl gnupg
29+ sudo install -m 0755 -d /etc/apt/keyrings
30+ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
31+ echo \
32+ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
33+ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
34+ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
35+ sudo apt-get update
36+ sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
37+ fi
38+
39+ # === CLONE OR UPDATE PROJECT ===
2640 cd /home/ubuntu
2741 if [ ! -d "fxmodelci" ]; then
2842 git clone https://github.com/Adeesh-bode/FXModel.git fxmodelci
2943 else
3044 cd fxmodelci
3145 git pull origin deploy-fxmodel-docker
3246 fi
47+
3348 cd /home/ubuntu/fxmodelci
34- docker-compose down
35- docker-compose up -d --build
49+
50+ # === RUN DOCKER COMPOSE ===
51+ docker compose down
52+ docker compose up -d --build
53+
3654 EOF
0 commit comments