Skip to content

Workflow file for this run

name: Tarae Nodejs(TypeScript) CI with NPM and CD with Docker & AWS EC2
on:
push:
branches: [ "main" ]
permissions:
contents: read
jobs:
CI-CD:
runs-on: ubuntu-latest
steps:
# 소스코드 다운로드
- name: Checkout code
uses: actions/checkout@v3
- run: npm ci
# ENV SDK 세팅
- name: Setting env file
run: |
touch .env
echo "${{ secrets.ENV }}" >> .env
shell: bash
- name: Build Docker Image For Node.js
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_USERNAME }}/blue:1.0 -f blue.Dockerfile .
docker build -t ${{ secrets.DOCKER_USERNAME }}/green:1.0 -f green.Dockerfile .
docker push ${{ secrets.DOCKER_USERNAME }}/blue:1.0
docker push ${{ secrets.DOCKER_USERNAME }}/green:1.0
# 서버에서 Docker 이미지 실행
- name: EC2 Docker Run
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
sudo touch /etc/nginx/green.flag
sudo rm /etc/nginx/blue.flag
docker stop blue
docker rm blue
docker rmi ${{ secrets.DOCKER_USERNAME }}/blue:1.0
docker pull ${{ secrets.DOCKER_USERNAME }}/blue:1.0
docker run -d -p 3000:3000 --name blue ${{ secrets.DOCKER_USERNAME }}/blue:1.0
sleep 20
sudo touch /etc/nginx/blue.flag
sudo rm /etc/nginx/green.flag
sleep 20
docker stop green
docker rm green
docker rmi ${{ secrets.DOCKER_USERNAME }}/green:1.0
docker pull ${{ secrets.DOCKER_USERNAME }}/green:1.0
docker run -d -p 3001:3000 --name green ${{ secrets.DOCKER_USERNAME }}/green:1.0