Update README.md #70
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 ] | |
| # 무슨 브랜치가 업데이트 될 때 Actions 를 작동시킬지 적는다. | |
| # develop 브랜치로 개발하며 완료되면 main 에 머지해 Actions 를 작동시키면 조금 더 안전하겠지. | |
| # 여러개 적어도 된다. | |
| env: | |
| DOCKER_IMAGE: ghcr.io/${{ github.actor }}/sorivision | |
| VERSION: ${{ github.sha }} | |
| NAME: sorivision | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v2 | |
| - name: Setup docker buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@v1 | |
| - name: Cache docker layers | |
| uses: actions/cache@v4 | |
| 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 | |
| build-args: | | |
| ENV_VARS=${{ secrets.ENV }} | |
| deploy: | |
| needs: build | |
| name: Deploy | |
| runs-on: [ self-hosted, Linux, x64 ] | |
| # label-newproject 라는 이름으로 AWS EC2 가 Runner 를 작동시킬 때 사용했던 그 label | |
| steps: | |
| - name: Login to ghcr | |
| uses: docker/login-action@v1 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GHCR_TOKEN }} | |
| - name: Docker run | |
| run: | | |
| docker stop ${{ env.NAME }} && docker rm ${{ env.NAME }} && docker rmi ${{ env.DOCKER_IMAGE }}:latest | |
| docker run -d -p 8000:8000 -v ~/shared:/shared --env-file ~/.env --name sorivision ${{ env.DOCKER_IMAGE }}:latest | |