Skip to content

Commit 57dbacc

Browse files
authored
Create postgres.yml
1 parent 0adfa41 commit 57dbacc

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

.github/workflows/postgres.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: ONDC Automation Mock Service Deployment
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
7+
jobs:
8+
ssh-ec2:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
15+
- name: SSH Setup and Cloning Repository
16+
run: |
17+
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ./key.pem
18+
chmod 600 ./key.pem
19+
mkdir -p ~/.ssh
20+
ssh-keyscan -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts
21+
22+
ssh -i ./key.pem ${{ secrets.USER }}@${{ secrets.HOST }} -T <<EOF
23+
REPO_DIR=~/ONDC-automation-framework/automation-iac
24+
echo "Removing existing repository directory if exists"
25+
rm -rf \$REPO_DIR
26+
echo "Cloning repository from main branch"
27+
git clone --single-branch --branch main https://github.com/ONDC-Official/automation-iac.git \$REPO_DIR
28+
EOF
29+
30+
- name: Install Docker Compose (if not installed)
31+
run: |
32+
ssh -i ./key.pem ${{ secrets.USER }}@${{ secrets.HOST }} <<EOF
33+
# Check if Docker Compose is installed
34+
if ! command -v docker-compose &> /dev/null
35+
then
36+
echo "Docker Compose not found. Installing..."
37+
sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | jq -r .tag_name)/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
38+
sudo chmod +x /usr/local/bin/docker-compose
39+
else
40+
echo "Docker Compose is already installed."
41+
fi
42+
EOF
43+
44+
- name: Write secrets to .env on EC2
45+
run: |
46+
echo "Writing secrets to .env file"
47+
ssh -i ./key.pem ${{ secrets.USER }}@${{ secrets.HOST }} <<EOF
48+
REPO_DIR=~/ONDC-automation-framework/automation-iac
49+
echo "Writing environment variables to .env file"
50+
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> \$REPO_DIR/.env
51+
echo "POSTGRES_USER=${{ vars.POSTGRES_USER }}" >> \$REPO_DIR/.env
52+
echo "POSTGRES_DATABASE=${{ vars.POSTGRES_DATABASE }}" >> \$REPO_DIR/.env
53+
EOF
54+
55+
- name: Verify .env and docker-compose.yml files
56+
run: |
57+
ssh -i ./key.pem ${{ secrets.USER }}@${{ secrets.HOST }} <<EOF
58+
REPO_DIR=~/ONDC-automation-framework/automation-iac
59+
# Check if .env and docker-compose.yml files exist
60+
if [ ! -f \$REPO_DIR/.env ]; then
61+
echo ".env file not found in \$REPO_DIR!"
62+
exit 1
63+
fi
64+
if [ ! -f \$REPO_DIR/docker-compose.yml ]; then
65+
echo "docker-compose.yml file not found in \$REPO_DIR!"
66+
exit 1
67+
fi
68+
echo ".env and docker-compose.yml files found."
69+
EOF
70+
71+
- name: Automation Mock Server Deployment
72+
run: |
73+
echo "Deploying with Docker Compose"
74+
ssh -i ./key.pem ${{ secrets.USER }}@${{ secrets.HOST }} <<EOF
75+
REPO_DIR=~/ONDC-automation-framework/automation-iac
76+
cd \$REPO_DIR
77+
78+
# Ensure the .env and docker-compose.yml files exist
79+
if [ ! -f .env ]; then
80+
echo ".env file not found!"
81+
exit 1
82+
fi
83+
84+
if [ ! -f docker-compose.yml ]; then
85+
echo "docker-compose.yml file not found!"
86+
exit 1
87+
fi
88+
89+
# Start the containers using Docker Compose
90+
echo "Running docker-compose up -d --build"
91+
sudo docker compose up -d --build
92+
EOF

0 commit comments

Comments
 (0)