Skip to content

Instantly share code, notes, and snippets.

@Farhandroid
Last active October 13, 2022 10:35
Show Gist options
  • Save Farhandroid/cf1988ea552d4ccb55bcec017fabdc62 to your computer and use it in GitHub Desktop.
Save Farhandroid/cf1988ea552d4ccb55bcec017fabdc62 to your computer and use it in GitHub Desktop.
name: CI/CD counter app
on:
push:
branches: [ master ]
jobs:
#First we will see the application build or not , then we will deploy in EC2
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the docker_compose
run: docker-compose up -d --build
- name: Buid the application
run: docker-compose exec -T counter_app npm run build
Deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Deploy in EC2
env:
PRIVATE_KEY: ${{ secrets.AWS_PRIVATE_KEY }}
HOSTNAME : ${{ secrets.HOSTNAME }}
USER_NAME : ${{ secrets.USER_NAME }}
run: |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} '
#Now we have got the access of EC2 and we will start the deploy .
cd /home/ubuntu/CounterApp &&
git checkout master &&
git fetch --all &&
git reset --hard origin/master &&
git pull origin master &&
docker-compose -f docker-compose.prod.yml up -d --build
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment