Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

KJH

github action (CD) 본문

DevOps

github action (CD)

모이스쳐라이징 2021. 11. 6. 01:45

1. CD 과정에서 사용될 Dockerfile

  • 테스트 용도로 사용할 crawling app이고 cronjob으로 돌릴 용도
FROM python:3.9
LABEL maintainer="mskjh6@naver.com"
RUN mkdir -p /app/server
COPY . /app/server

WORKDIR /app/server
RUN pip install --upgrade pip
RUN pip3 install -r requirements.txt

ENTRYPOINT ["python", "naver.py"]

 

2. Github registry

  • docker registry처럼 관리되는 기능이 있음
  • 정식 서비스는 아니라서 기능을 Enable 해줘야함

 

 

3. cd.yml 등록

.github/workflows/cd.yml
name: CD

on:
  push:
    branches: [ master ]

env:

  IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/scrap-app

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Check out code
        uses: actions/checkout@v2
     
      - name: Get verion
        id: image
        run: |
          VERSION=$(echo ${{ github.sha }} | cut -c1-8)
          echo VERSION=$VERSION
          echo "::set-output name=version::$VERSION"
      - name: Login to GitHub Packages Container Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.ACTION_TOKEN }}
      - name: Push to GitHub Packages
        uses: docker/build-push-action@v2
        with:
          push: true
          tags: |
            ${{ env.IMAGE_NAME }}:${{ steps.image.outputs.version }}
      - name: Setup Kustomize
        uses: imranismail/setup-kustomize@v1

      - name: Checkout kustomize repository
        uses: actions/checkout@v2
        with:
          repository: kimjanghyun1010/argo-kustomize
          ref: master
          token: ${{ secrets.ACTION_TOKEN }}
          path: argo-kustomize

      - name: Update Kubernetes resources
        run: |
          cd argo-kustomize/overlays/dev/
          kustomize edit set image ${{ env.IMAGE_NAME }}:${{ steps.image.outputs.version }}
          cat kustomization.yaml
      - name: Commit files
        run: |
          cd argo-kustomize
          git config --global user.email "mskjh6@naver.com"
          git config --global user.name "kimjanghyun1010"
          git add .
          git commit -am "Update image tag"
          git push -u origin master

 

4. token 생성

  • CD과정에서 푸쉬할때 사용할 token을 생성함

 

  • 위에 만든 cd.yml에서 token을 사용하려면 해당 repo에 secret을 등록해야 변수로 사용가능함

 

5. CD 실행

  • master에 푸쉬하게 되면 CD가 돌고 이미지를 생성함
  • 패키지쪽에서 확인 할 수 있음

'DevOps' 카테고리의 다른 글

github action (argoCD)  (0) 2021.11.06
github action (kustomize)  (0) 2021.11.06
github action (CI)  (0) 2021.11.06
Terraform Variable  (0) 2021.11.03
Terraform 시작하기 (GCP)  (0) 2021.10.31