Skip to content

프론트 배포시 수정사항 변경 안되는 문제 수정 (issue #41) #95

프론트 배포시 수정사항 변경 안되는 문제 수정 (issue #41)

프론트 배포시 수정사항 변경 안되는 문제 수정 (issue #41) #95

Workflow file for this run

name: frontend CI/CD
on:
pull_request:
branches: [main]
paths:
- "front/src/**"
- "backend/src/**"
jobs:
path_changes:
runs-on: ubuntu-latest
outputs:
front: ${{ steps.filter.outputs.front }}
backend: ${{ steps.filter.outputs.backend }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
front:
- 'front/src/**'
backend:
- 'backend/src/**'
frontend-tests:
needs: path_changes
if: needs.path_changes.outputs.front == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
# - name: Cache Node.js modules
# uses: actions/cache@v4
# with:
# path: front/node_modules
# key: ${{ runner.os }}-node-${{ hashFiles('**/front/package-lock.json') }}
# restore-keys: |
# ${{ runner.os }}-node-
- name: Install frontend dependencies
working-directory: front
run: npm i --force
- name: Install missing dependencies
working-directory: front
run: npm install -D @vanilla-extract/next-plugin
- name: Run frontend tests
working-directory: front
run: npm test
build_and_push_frontend:
needs: [path_changes, frontend-tests]
if: needs.path_changes.outputs.front == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN_FRONTEND }}
- name: Set up Docker Meta for Frontend
id: docker_meta_frontend
uses: docker/metadata-action@v5
with:
images: ${{ secrets.FRONT_DOCKER_IMAGE }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=ref,event=branch
type=ref,event=pr
type=sha
flavor: |
latest=true
- name: Build and Push Frontend Docker Image
uses: docker/build-push-action@v5
with:
context: ./front
file: ./front/Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.docker_meta_frontend.outputs.tags }}
labels: ${{ steps.docker_meta_frontend.outputs.labels }}
no-cache: true
build-args: |
NEXT_PUBLIC_DEV_API_URL=${{ secrets.NEXT_PUBLIC_DEV_API_URL }}
NEXT_PUBLIC_PRODUCTION_API_URL=${{ secrets.NEXT_PUBLIC_PRODUCTION_API_URL }}
NEXT_PUBLIC_FRONT_ENV_MODE=${{ secrets.NEXT_PUBLIC_FRONT_ENV_MODE }}
NEXT_PUBLIC_CDN_URL=${{ secrets.NEXT_PUBLIC_CDN_URL }}
- name: EC2 Front Docker Run
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.FRONT_EC2_HOST }}
username: ec2-user
key: ${{ secrets.FRONT_EC2_PEM_KEY }}
script: |
docker stop ${{ secrets.FRONT_DOCKER_CONTAINER }} || true
docker rm ${{ secrets.FRONT_DOCKER_CONTAINER }} || true
docker pull ${{ secrets.FRONT_DOCKER_IMAGE }}:latest
docker run --name ${{ secrets.FRONT_DOCKER_CONTAINER }} --rm -d -p 3000:3000 ${{ secrets.FRONT_DOCKER_IMAGE }}:latest