|
| 1 | +# github repository actions 페이지에 나타날 이름 |
| 2 | +name: CD for front using github actions |
| 3 | + |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + types: [ closed ] |
| 7 | + branches: [ "develop" ] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + front-cd: |
| 14 | + if: github.event.pull_request.merged == true |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + # 저장소 코드를 체크아웃합니다. (PR 올린 코드를 가져오는 행위) |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + |
| 20 | + # Node.js 환경 설정 |
| 21 | + - name: Use Node.js |
| 22 | + uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: 22 # 지정된 Node.js 버전 사용 |
| 25 | + cache: npm # setup-node 의 캐시 기능을 사용함 |
| 26 | + cache-dependency-path: package-lock.json # 캐시 기능을 사용할 때 캐시의 기준이 될 파일을 지정 |
| 27 | + |
| 28 | + - name: Install Dependencies |
| 29 | + run: npm install |
| 30 | + |
| 31 | + - name: Build with npm |
| 32 | + run: npm run build-only |
| 33 | + |
| 34 | + - name: Create nginxfile.conf |
| 35 | + run: touch ./nginxfile.conf |
| 36 | + - run: echo "${{ secrets.NGINX_FILE_CONF }}" > ./nginxfile.conf |
| 37 | + |
| 38 | + - name: Create Develop nginx.conf |
| 39 | + run: touch ./nginx.conf |
| 40 | + - run: echo "${{ secrets.NGINX_CONF }}" > ./nginx.conf |
| 41 | + |
| 42 | + # docker build & push to develop |
| 43 | + - name: Docker build & push develop |
| 44 | + run: | |
| 45 | + docker login clap.kr-central-2.kcr.dev -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} |
| 46 | + docker build -t ${{ secrets.DOCKER_FRONT_REPO }} . |
| 47 | + docker push ${{ secrets.DOCKER_FRONT_REPO }} |
| 48 | +
|
| 49 | + # deploy |
| 50 | + - name: Deploy Develop |
| 51 | + uses: appleboy/ssh-action@master |
| 52 | + id: deployDevelop |
| 53 | + with: |
| 54 | + host: ${{ secrets.FRONT_HOST }} |
| 55 | + username: ${{ secrets.FRONT_HOST_USERNAME }} |
| 56 | + key: ${{ secrets.FRONT_HOST_KEY }} |
| 57 | + port: ${{ secrets.FRONT_HOST_PORT }} |
| 58 | + script: | |
| 59 | + docker rm -f taskflow-front |
| 60 | + docker image rm -f ${{ secrets.DOCKER_FRONT_REPO }} |
| 61 | + docker run --name taskflow-front -d -p 80:80 -p 443:443 -v /etc/letsencrypt/:/etc/letsencrypt/ -v /etc/ssl/:/etc/ssl/ --restart on-failure ${{ secrets.DOCKER_FRONT_REPO }} |
0 commit comments