From d2f027f37d72c77c75762938de63592c71a08f36 Mon Sep 17 00:00:00 2001 From: JANG SEONG JU Date: Thu, 5 Nov 2026 19:20:09 +0900 Subject: [PATCH] =?UTF-8?q?add=20::=20Docker=20Hub=20=EA=B8=B0=EB=B0=98=20?= =?UTF-8?q?stag/prod=20=EB=B0=B0=ED=8F=AC=20=EC=9B=8C=ED=81=AC=ED=94=8C?= =?UTF-8?q?=EB=A1=9C=EC=9A=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-prod.yml | 103 ++++++++++++++++++++++++++++++ .github/workflows/deploy-stag.yml | 103 ++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 .github/workflows/deploy-prod.yml create mode 100644 .github/workflows/deploy-stag.yml diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml new file mode 100644 index 00000000..755e359a --- /dev/null +++ b/.github/workflows/deploy-prod.yml @@ -0,0 +1,103 @@ +name: Deploy Prod + +on: + push: + branches: + - main + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: deploy-prod + cancel-in-progress: false + +env: + REGISTRY: docker.io + IMAGE_REPOSITORY: sungjujjang/pick-core-prod + GITOPS_REPO: DSM-PICK/PICK-INFRA-APPLICATION + GITOPS_VALUES_FILE: apps/prod/values.yaml + DEPLOYMENT_NAME: pick-core-prod + +jobs: + build-and-deploy: + name: Build and Deploy + runs-on: ubuntu-latest + timeout-minutes: 30 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: sungjujjang + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64 + push: true + tags: | + ${{ env.IMAGE_REPOSITORY }}:${{ github.sha }} + ${{ env.IMAGE_REPOSITORY }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Checkout GitOps repository + uses: actions/checkout@v4 + with: + repository: ${{ env.GITOPS_REPO }} + ref: main + token: ${{ secrets.GITOPS_PAT }} + path: gitops + fetch-depth: 0 + + - name: Install yq + run: | + sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.54.1/yq_linux_amd64 + sudo chmod +x /usr/local/bin/yq + + - name: Update image in GitOps manifest + env: + IMAGE_TAG: ${{ github.sha }} + run: | + if [ ! -f "gitops/${GITOPS_VALUES_FILE}" ]; then + echo "::error::GitOps manifest not found: ${GITOPS_VALUES_FILE}" + exit 1 + fi + + if ! yq -e ".deployments[] | select(.name == \"${DEPLOYMENT_NAME}\")" "gitops/${GITOPS_VALUES_FILE}" > /dev/null; then + echo "::error::Deployment '${DEPLOYMENT_NAME}' not found in ${GITOPS_VALUES_FILE}" + exit 1 + fi + + yq -i "(.deployments[] | select(.name == \"${DEPLOYMENT_NAME}\") | .image.repository) = strenv(IMAGE_REPOSITORY)" "gitops/${GITOPS_VALUES_FILE}" + yq -i "(.deployments[] | select(.name == \"${DEPLOYMENT_NAME}\") | .image.tag) = strenv(IMAGE_TAG)" "gitops/${GITOPS_VALUES_FILE}" + + - name: Commit and push GitOps manifest + env: + IMAGE_TAG: ${{ github.sha }} + run: | + git -C gitops config user.name "github-actions[bot]" + git -C gitops config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + if git -C gitops diff --quiet -- "${GITOPS_VALUES_FILE}"; then + echo "No changes to commit." + exit 0 + fi + + git -C gitops add "${GITOPS_VALUES_FILE}" + git -C gitops commit -m "chore(prod): update ${DEPLOYMENT_NAME} image to ${IMAGE_TAG}" + git -C gitops fetch origin main + git -C gitops rebase origin/main + git -C gitops push origin HEAD:main diff --git a/.github/workflows/deploy-stag.yml b/.github/workflows/deploy-stag.yml new file mode 100644 index 00000000..1e453095 --- /dev/null +++ b/.github/workflows/deploy-stag.yml @@ -0,0 +1,103 @@ +name: Deploy Stag + +on: + push: + branches: + - develop + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: deploy-stag + cancel-in-progress: false + +env: + REGISTRY: docker.io + IMAGE_REPOSITORY: sungjujjang/pick-core-stag + GITOPS_REPO: DSM-PICK/PICK-INFRA-APPLICATION + GITOPS_VALUES_FILE: apps/stag/values.yaml + DEPLOYMENT_NAME: pick-core-stag + +jobs: + build-and-deploy: + name: Build and Deploy + runs-on: ubuntu-latest + timeout-minutes: 30 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: sungjujjang + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64 + push: true + tags: | + ${{ env.IMAGE_REPOSITORY }}:${{ github.sha }} + ${{ env.IMAGE_REPOSITORY }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Checkout GitOps repository + uses: actions/checkout@v4 + with: + repository: ${{ env.GITOPS_REPO }} + ref: main + token: ${{ secrets.GITOPS_PAT }} + path: gitops + fetch-depth: 0 + + - name: Install yq + run: | + sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.54.1/yq_linux_amd64 + sudo chmod +x /usr/local/bin/yq + + - name: Update image in GitOps manifest + env: + IMAGE_TAG: ${{ github.sha }} + run: | + if [ ! -f "gitops/${GITOPS_VALUES_FILE}" ]; then + echo "::error::GitOps manifest not found: ${GITOPS_VALUES_FILE}" + exit 1 + fi + + if ! yq -e ".deployments[] | select(.name == \"${DEPLOYMENT_NAME}\")" "gitops/${GITOPS_VALUES_FILE}" > /dev/null; then + echo "::error::Deployment '${DEPLOYMENT_NAME}' not found in ${GITOPS_VALUES_FILE}" + exit 1 + fi + + yq -i "(.deployments[] | select(.name == \"${DEPLOYMENT_NAME}\") | .image.repository) = strenv(IMAGE_REPOSITORY)" "gitops/${GITOPS_VALUES_FILE}" + yq -i "(.deployments[] | select(.name == \"${DEPLOYMENT_NAME}\") | .image.tag) = strenv(IMAGE_TAG)" "gitops/${GITOPS_VALUES_FILE}" + + - name: Commit and push GitOps manifest + env: + IMAGE_TAG: ${{ github.sha }} + run: | + git -C gitops config user.name "github-actions[bot]" + git -C gitops config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + if git -C gitops diff --quiet -- "${GITOPS_VALUES_FILE}"; then + echo "No changes to commit." + exit 0 + fi + + git -C gitops add "${GITOPS_VALUES_FILE}" + git -C gitops commit -m "chore(stag): update ${DEPLOYMENT_NAME} image to ${IMAGE_TAG}" + git -C gitops fetch origin main + git -C gitops rebase origin/main + git -C gitops push origin HEAD:main