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

[LIB-227] CI/CD 파이프라인 #238

Merged
merged 24 commits into from
Sep 26, 2023
Merged

[LIB-227] CI/CD 파이프라인 #238

merged 24 commits into from
Sep 26, 2023

Conversation

ImKunYoung
Copy link
Collaborator

@ImKunYoung ImKunYoung commented Sep 26, 2023

스프린트 넘버 : Sprint1

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


작업

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

CODE

# docker-ci-dev.yml
name: Build and Push Docker Image for DEV

on:
  push:
    branches:
      - dev

jobs:
  build-and-push:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Create src/main/resources/bootstrap.yml
        run: |
          mkdir -p src/main/resources
          echo "encrypt:" > src/main/resources/bootstrap.yml
          echo "  key: '${{ secrets.ENCRYPTKEY }}'" >> src/main/resources/bootstrap.yml

      - name: Login to GitHub Container Registry
        run: echo ${{ secrets.GTOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin

      - name: Create Release Name
        id: release_name
        run: |
          echo "::set-output name=release_name::v-$(date +'%Y.%m.%d-%H%M%S')"

      - name: Build and Push Docker Dev Image
        run: |
          RELEASE_NAME="${{ steps.release_name.outputs.release_name }}"
          docker build --build-arg SPRING_PROFILES_ACTIVE=dev -t my-product-server:latest -f multistage.Dockerfile .
          docker tag my-product-server:latest ghcr.io/liberty52/liberty52-product-server:dev-$RELEASE_NAME
          docker push ghcr.io/liberty52/liberty52-product-server:dev-$RELEASE_NAME

      - name: Create GitHub Release
        uses: actions/create-release@v1
        with:
          tag_name: ${{ steps.release_name.outputs.release_name }}
          release_name: Release ${{ steps.release_name.outputs.release_name }}
          generateReleaseNotes: true
          draft: false
          prerelease: false
        env:
          GITHUB_TOKEN: ${{ secrets.GTOKEN }}

      - name: Clean up
        run: docker logout ghcr.io
# 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-product-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 }}

테스트 결과


푸시된 도커 이미지입니다
image

Action에 의해 새로 배포된 도커 컨테이너입니다.

CONTAINER ID   IMAGE                                                                COMMAND                  CREATED          STATUS          PORTS                                       NAMES
6eacbac8929b   ghcr.io/liberty52/liberty52-product-server:dev-v-2023.09.25-234927   "java -jar app.jar -…"   11 minutes ago   Up 11 minutes   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   nifty_moser

이슈 [#227]

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

Co-authored-by: hseungho [email protected]

@ImKunYoung ImKunYoung linked an issue Sep 26, 2023 that may be closed by this pull request
@ImKunYoung ImKunYoung added the ci label Sep 26, 2023
@ImKunYoung ImKunYoung changed the title Lib 227 CI/CD 파이프라인 Sep 26, 2023
@ImKunYoung ImKunYoung changed the title CI/CD 파이프라인 [LIB-227] CI/CD 파이프라인 Sep 26, 2023
@ImKunYoung ImKunYoung added 🌏 Deploy 배포 관련 and removed ci labels Sep 26, 2023
Copy link
Member

@DryRains DryRains 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 a697bda into dev Sep 26, 2023
1 check passed
@ImKunYoung ImKunYoung deleted the LIB-227 branch October 25, 2023 06:37
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