Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE-#72] CI/CD 파이프라인 #77

Merged
merged 4 commits into from
Sep 26, 2023
Merged

[ISSUE-#72] CI/CD 파이프라인 #77

merged 4 commits into from
Sep 26, 2023

Conversation

ImKunYoung
Copy link
Contributor

스프린트 넘버 : Sprint1

백로그 이름 : CI/CD 파이프라인


작업

  • 지속적 배포 파이프라인: EC2 인스턴스를 대상으로 하는 지속적 배포 파이프라인을 추가하였습니다 :)

CODE

# deploy-dev.yml
name: Deploy dev

on:
  workflow_run:
    workflows:
      - Build and Push Docker Image for DEV
    types:
      - completed

jobs:
  deploy:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}

    env:
      DOCKER_REGISTRY: ghcr.io
      DOCKER_REPO: liberty52/liberty52-admin-server

    steps:
      - name: Get latest Release tag
        id: latest-tag
        uses: robinraju/[email protected]
        with:
          latest: true
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Set Docker Image Name
        id: new-docker-image
        run: echo "::set-output name=image_name::$DOCKER_REGISTRY/$DOCKER_REPO:dev-${{ steps.latest-tag.outputs.tag_name }}"

      - name: Deploy AWS EC2 dev
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.REMOTE_IP_DEV }}
          username: ${{ secrets.REMOTE_SSH_ID_DEV }}
          key: ${{ secrets.REMOTE_SSH_KEY_DEV }}
          port: ${{ secrets.REMOTE_SSH_PORT_DEV }}
          script: |
            echo ${{ secrets.GTOKEN }} | sudo docker login ghcr.io -u ${{ github.actor }} --password-stdin
            sudo docker pull ${{ steps.new-docker-image.outputs.image_name }}
            container_name=$(sudo docker ps | grep liberty52 | awk '{print $NF}')
            sudo docker stop $container_name
            sudo docker run -d -p 8080:8080 ${{ steps.new-docker-image.outputs.image_name }}````
# deploy-prod.yml
name: Deploy prod

on:
  workflow_run:
    workflows:
      - "Build and Push Docker Image for PROD"
    types:
      - completed

jobs:
  deploy:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    env:
      DOCKER_IMAGE: ghcr.io/liberty52/liberty52-admin-server:prod-${{ github.sha }}

    steps:
      - name: Deploy AWS EC2 dev
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.REMOTE_IP_PROD }}
          username: ${{ secrets.REMOTE_SSH_ID_PROD }}
          key: ${{ secrets.REMOTE_SSH_KEY_PROD }}
          port: ${{ secrets.REMOTE_SSH_PORT_PROD }}
          script: |
            echo ${{ secrets.GTOKEN }} | sudo docker login ghcr.io -u ${{ github.actor }} --password-stdin
            sudo docker pull $DOCKER_IMAGE
            container_name=$(sudo docker ps | grep liberty52 | awk '{print $NF}')
            sudo docker stop $container_name
            sudo docker run -d -p 8080:8080 $DOCKER_IMAGE```

테스트 결과


워크플로 실행 결과입니다!!
image

**새로 배포된 도커 컨테이너입니다 ~~**

root@ip-172-31-43-47:/home/ubuntu# docker ps
CONTAINER ID   IMAGE                                                              COMMAND                  CREATED        STATUS        PORTS                                       NAMES
7edd857bcbad   ghcr.io/liberty52/liberty52-admin-server:dev-v-2023.09.25-022049   "java -jar app.jar -…"   20 hours ago   Up 19 hours   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   pedantic_taussig
root@ip-172-31-43-47:/home/ubuntu# docker ps
CONTAINER ID   IMAGE                                                              COMMAND                  CREATED         STATUS        PORTS                                       NAMES
fb30cd93b96f   ghcr.io/liberty52/liberty52-admin-server:dev-v-2023.09.25-022049   "java -jar app.jar -…"   3 seconds ago   Up 1 second   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   epic_murdock

이슈 [#72 ]

  • @hseungho 선배님이 작업해주신 부분에서 크게 변경된 사항은 없습니다 :)
  • Tag 컨벤션은 빠른 시일 내로 수정하겠습니다! (죄송합니다 ㅠㅠ)

Co-authored-by: hseungho [email protected]

Closes #72

Copy link
Contributor

@parkcoldroad parkcoldroad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다! 👍

@ImKunYoung ImKunYoung merged commit c4e0cb9 into dev Sep 26, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌏 Deploy 배포 관련
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CI/CD 파이프라인
3 participants