diff --git a/.github/workflows/dokcer-image.yml b/.github/workflows/dokcer-image.yml new file mode 100644 index 0000000..3395787 --- /dev/null +++ b/.github/workflows/dokcer-image.yml @@ -0,0 +1,55 @@ +name: Docker Image CI/CD + +on: + push: + branches: + - main + +permissions: + contents: write + +jobs: + build-and-push: + runs-on: ubuntu-latest + environment: production + + steps: + - name: Checkout 'study' repository + uses: actions/checkout@v3 + + - name: Login to Docker Registry + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract short SHA + id: vars + run: echo "SHORT_SHA=${GITHUB_SHA::6}" >> $GITHUB_ENV + + - name: Build and push Docker image + run: | + docker build -t "${{ secrets.DOCKER_USERNAME }}/my-gitbook:${{ env.SHORT_SHA }}" . + docker push "${{ secrets.DOCKER_USERNAME }}/my-gitbook:${{ env.SHORT_SHA }}" + + - name: Checkout 'study-manifests' repository + uses: actions/checkout@v3 + with: + repository: idoyo7/study-manifests + token: ${{ secrets.PERSONAL_GITHUB_TOKEN }} + path: study-manifests + + - name: Update manifest files + run: | + cd study-manifests + # 필요한 수정 작업 수행 (예: 이미지 태그 업데이트) + sed -i 's|image:.*|image: '"${{ secrets.DOCKER_USERNAME }}/my-gitbook:${{ env.SHORT_SHA }}"'|' deployment.yaml + + - name: Commit and push changes to 'study-manifests' + run: | + cd study-manifests + git config user.name "${{ github.actor }}" + git config user.email "${{ github.actor }}@users.noreply.github.com" + git add . + git commit -m "Update image tag to ${{ env.SHORT_SHA }}" + git push