fix: env 파일 복사 스크립트 제거 #196
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 Image CD | |
on: | |
push: | |
branches: ['dev'] | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
# 소스 코드 체크아웃 | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Docker Hub 로그인 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
# SSH 접속을 위한 SSH 키 설정 | |
- name: Set up SSH | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
# 원격 서버의 SSH 호스트 키를 저장하여 SSH 연결 시 신뢰성을 확인하는 과정 | |
- name: Add known hosts | |
run: ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts | |
# 서버 이미지 빌드 및 태그 지정 | |
- name: Build and tag Docker image | |
run: | | |
docker build -f server/Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/inear-server:${{ github.sha }} ./ | |
docker tag ${{ secrets.DOCKER_USERNAME }}/inear-server:${{ github.sha }} ${{ secrets.DOCKER_USERNAME }}/inear-server:latest | |
# 클라이언트 및 nginx 이미지 빌드 및 태그 지정 | |
- name: Build and tag client image | |
run: | | |
yarn --cwd ./client install | |
echo ${{ secrets.CLIENT_ENV_PRODUCTION }} > ./client/.env.production | |
echo ${{ secrets.CLIENT_ENV_DEVELOPMENT }} > ./client/.env.development | |
yarn --cwd ./client build | |
scp -r ./client/dist/ ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }}:/${{ secrets.SSH_USER }}/web18-inear-test/nginx/html/ | |
# Docker Compose로 전체 애플리케이션 빌드 및 실행 (테스트용) | |
- name: Run Docker Compose for testing (optional) | |
run: | | |
docker compose up --build -d | |
continue-on-error: false | |
# 서버 이미지 푸시 (Docker Hub 또는 다른 레지스트리) | |
- name: Push server image to Docker Hub (optional) | |
run: | | |
docker push ${{ secrets.DOCKER_USERNAME }}/inear-server:${{ github.sha }} | |
docker push ${{ secrets.DOCKER_USERNAME }}/inear-server:latest | |
# 서버에서 파일을 최신화 하고, 배포 스크립트를 통해 실제 배포 진행 | |
- name: Deploy with Docker Compose on server | |
run: | | |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }} " \ | |
mkdir -p /${{ secrets.SSH_USER }}/web18-inear-test && \ | |
cd /${{ secrets.SSH_USER }}/web18-inear-test && \ | |
docker system prune -af && \ | |
docker pull ${{ secrets.DOCKER_USERNAME }}/inear-server:latest && \ | |
./deploy.sh | |
" |