Testing workflow #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploying-Docker-image-to-AWS-EC2 | |
on: | |
push: | |
branches: | |
- Feature-deploy-in-AWS | |
paths: | |
- "server/**" | |
defaults: | |
run: | |
working-directory: "server" | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 18 | |
- name: Docker Setup Buildx | |
uses: docker/[email protected] | |
- name: Install Dependencies | |
run: | | |
npm ci | |
- name: Verify Docker Setup | |
run: docker version | |
- name: Build and Push Docker Image | |
run: | | |
docker buildx create --use | |
docker build -t afsha9/video-storage-app:latest . | |
docker login -u afsha9 -p ${{ secrets.DOCKER_ACCESS_TOKEN }} | |
docker push afsha9/video-storage-app:latest | |
- name: EC2 SSH > Start PM2 process | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
script: | | |
docker login -u afsha9 -p ${{ secrets.DOCKER_ACCESS_TOKEN }} | |
docker pull afsha9/video-storage-app:latest | |
docker stop $(docker ps -a -q) | |
docker run --rm -d -p 3000:3000 afsha9/video-storage-app:latest |