Skip to content

Commit a5af99d

Browse files
committed
Add workflow for deploying to EC2
1 parent 7c62f1b commit a5af99d

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

.github/workflows/deploy.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Deploy to EC2
2+
3+
on:
4+
push:
5+
branches: [release]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Deploy to EC2
14+
env:
15+
PRIVATE_KEY: ${{ secrets.EC2_PRIVATE_KEY }}
16+
HOST: ${{ secrets.EC2_HOST }}
17+
USER: ${{ secrets.EC2_USER }}
18+
run: |
19+
echo "$PRIVATE_KEY" > github-ec2.pem && chmod 600 github-ec2.pem
20+
ssh -o StrictHostKeyChecking=no -i github-ec2.pem ${USER}@${HOST} '
21+
echo "Current directory: $(pwd)"
22+
echo "Listing home directory:"
23+
ls -la ~
24+
25+
echo "Installing Node.js..."
26+
if ! command -v nvm &> /dev/null; then
27+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
28+
export NVM_DIR="$HOME/.nvm"
29+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
30+
fi
31+
nvm install node
32+
33+
echo "Installing PM2..."
34+
if ! command -v pm2 &> /dev/null; then
35+
npm install -g pm2
36+
fi
37+
38+
REPO_URL="https://github.com/mahutt/cue.git"
39+
BRANCH="release"
40+
REPO_DIR="$HOME/github-aws-ec2"
41+
42+
if [ -d "$REPO_DIR/.git" ]; then
43+
cd "$REPO_DIR"
44+
git pull origin "$BRANCH"
45+
else
46+
git clone "$REPO_URL" "$REPO_DIR"
47+
cd "$REPO_DIR"
48+
fi
49+
50+
cd "$REPO_DIR/simple-web-server"
51+
npm install
52+
53+
echo "Starting/restarting application..."
54+
npm run start
55+
'

.prettierrc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,13 @@
22
"semi": true,
33
"singleQuote": true,
44
"tabWidth": 4,
5-
"printWidth": 120
5+
"printWidth": 120,
6+
"overrides": [
7+
{
8+
"files": "*.{yml,yaml}",
9+
"options": {
10+
"tabWidth": 2
11+
}
12+
}
13+
]
614
}

0 commit comments

Comments
 (0)