Skip to content

Merge pull request #2 from themerous/minseok #17

Merge pull request #2 from themerous/minseok

Merge pull request #2 from themerous/minseok #17

Workflow file for this run

name: Docker React App
on:
push:
branches: [ "main" ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install pnpm
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install
- name: Build Next.js app
run: pnpm build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/react-app:latest .
docker push ${{ secrets.DOCKER_USERNAME }}/react-app:latest
- name: SSH and deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/react-app:latest
docker stop react-app-container || true
docker rm react-app-container || true
docker run -d -p 80:3000 --name react-app-container ${{ secrets.DOCKER_USERNAME }}/react-app:latest