Update main.yml #74
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: CI/CD | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [main] | |
| env: | |
| DOCKER_IMAGE: wlsdud5654/speed-coder | |
| NAME: coder | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source code. | |
| uses: actions/checkout@v3 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "18" # 원하는 노드 버전 지정 | |
| - name: React Build. | |
| run: | | |
| cd client | |
| yarn build | |
| cd .. | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v1 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v1 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v2 # build-push-action 사용 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ env.DOCKER_IMAGE }}:latest | |
| cache-from: type=gha # 여기서 gha 는 Guthub Actions 용 캐시를 의미합니다. | |
| cache-to: type=gha,mode=max | |
| deploy: | |
| needs: build # build 후에 실행되도록 정의 | |
| name: Deploy | |
| runs-on: [self-hosted, label-go] | |
| steps: | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v1 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Docker run | |
| run: | | |
| docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q) && docker rmi $(docker images -q) | |
| docker run -e ATLAS_URL="${{ secrets.ATLAS_URL }}" -d -p 80:80 --name ${{ env.NAME }} ${{ env.DOCKER_IMAGE }}:latest |