docs: ssh 디버거 제거 #11
This file contains hidden or 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: Deploy with Docker | |
| on: | |
| push: | |
| branches: [ main ] | |
| env: | |
| DOCKER_IMAGE: ghcr.io/ummiih/nextjs-app | |
| VERSION: ${{ github.sha }} | |
| CONTAINER_NAME: nextjs-app | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v2 # git 레파지토리를 클론하는것과 같음 | |
| - name: Setup docker buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@v1 | |
| - name: Cache docker layers | |
| uses: actions/cache@v2 | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ runner.os }}-buildx-${{ env.VERSION }} | |
| restore-keys: | | |
| ${{ runner.os }}-buildx- | |
| - name: Login to ghcr | |
| uses: docker/login-action@v1 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GHCR_TOKEN }} | |
| # 우리가 방금 복사해서 setting secrets 에 붙여줬던 token 이다. 이름을 기억해 넣어주자. | |
| # 우리의 ghcr.io 에 접근하기 위함이다. | |
| - name: Build and push | |
| id: docker_build | |
| uses: docker/build-push-action@v2 | |
| with: | |
| builder: ${{ steps.buildx.outputs.name }} | |
| push: true | |
| tags: ${{ env.DOCKER_IMAGE }}:latest | |
| context: ${{ github.workspace }}/dorm-front # Dockerfile이 있는 디렉토리를 컨텍스트로 설정 | |
| file: ${{ github.workspace }}/dorm-front/Dockerfile # Dockerfile 경로를 명시 | |
| deploy: | |
| needs: build | |
| name: Deploy | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Docker login | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.REMOTE_IP }} | |
| username: ${{ secrets.REMOTE_SSH_ID }} | |
| key: ${{ secrets.REMOTE_SSH_KEY }} | |
| port: ${{ secrets.REMOTE_SSH_PORT }} | |
| script: | | |
| sudo chmod 666 /var/run/docker.sock | |
| echo ${{ secrets.GHCR_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| - name: Deploy | |
| uses: appleboy/ssh-action@master # 추적을 위해 스텝을 나누어놨지만 한스크립트에서 전부 돌려도댐. | |
| with: | |
| host: ${{ secrets.REMOTE_IP }} | |
| username: ${{ secrets.REMOTE_SSH_ID }} | |
| key: ${{ secrets.REMOTE_SSH_KEY }} | |
| port: ${{ secrets.REMOTE_SSH_PORT }} | |
| script: | | |
| docker pull ${{ env.DOCKER_IMAGE }}:latest | |
| - name: Run | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.REMOTE_IP }} | |
| username: ${{ secrets.REMOTE_SSH_ID }} | |
| key: ${{ secrets.REMOTE_SSH_KEY }} | |
| port: ${{ secrets.REMOTE_SSH_PORT }} | |
| script: | | |
| docker compose stop ${{ env.CONTAINER_NAME }} && docker rm ${{ env.CONTAINER_NAME }} && docker rmi ${{ env.DOCKER_IMAGE }}:latest | |
| docker compose up -d |