minor change made for versioning #32
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: Docker React App | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Get the latest tag or default | |
id: git_tag | |
run: | | |
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0") | |
echo "TAG=${TAG}" >> $GITHUB_ENV | |
- 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: Login to Docker registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ${{ secrets.REGISTRY_URL }} | |
username: ${{ secrets.NAVER_ACESSKEY }} | |
password: ${{ secrets.NAVER_SECRETKEY }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
push: true | |
tags: ${{ secrets.REGISTRY_URL }}/react-app:${{ env.TAG }} | |
- name: SSH and deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
password: ${{ secrets.SERVER_PASSWORD }} | |
script: | | |
docker login -u ${{ secrets.NAVER_ACESSKEY }} -p ${{ secrets.NAVER_SECRETKEY }} ${{ secrets.REGISTRY_URL }} | |
docker pull ${{ secrets.REGISTRY_URL }}/react-app:${{ env.TAG }} | |
docker stop react-app-container || true | |
docker rm react-app-container || true | |
docker run -d -p 80:3000 --name react-app-container ${{ secrets.REGISTRY_URL }}/react-app:${{ env.TAG }} |