Github Workflow File To Deploy Your Angular App on AWS EC2
2 min readSep 24, 2023
I went through multiple blogs, ChatGPT & Google Bard to finally come up with a minimal .yml
file that works! You will find multiple good blogs that explain setting up an EC2 instance, installing NGINX web server on it etc. This article will not cover those.
name: Deploy to EC2
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: NPM Install
run: npm install
- name: NPM Install Angular
run: npm install -g @angular/cli > /dev/null
- name: NPM build Angular
run: npm run build
- name: Deploy to EC2 instance
uses: easingthemes/ssh-deploy@v2.1.5
with:
REMOTE_HOST: bla.bla.bla.bla
REMOTE_USER: ubuntu
SSH_PRIVATE_KEY: ${{ secrets.SSH_KEY }}
SOURCE: dist/task-master
TARGET: /var/www/html/
A few things to remind
- Please use your desired node version
REMOTE_HOST
should contain the IP address of your running instanceREMOTE_USER
should contain the remote user. I am using an ubuntu AMI (Amazon Machine Image)- Rename the Repository Secret accordingly (
secrets.SSH_KEY
) - I have set up my folder in such a way that, there’s a
task-master
folder insidevar/www/html
. Please modifySOURCE
&TARGET
accordingly