Skip to content

fix: 도커 수정

fix: 도커 수정 #57

Workflow file for this run

name: Deploy and Update GitOps Repo
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
pull-requests: write
steps:
- name: Start Timer
run: echo "START_TIME=$(date +%s)" >> $GITHUB_ENV
- name: Checkout source repo
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build and push Docker image
shell: bash
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
run: |
set -euo pipefail
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/blog
IMAGE_TAG=$(date +%Y%m%d%H%M%S)
echo "IMAGE_TAG=$IMAGE_TAG" >> "$GITHUB_ENV"
# ✅ env로 받은 값을 파일로 저장 (YAML 문제 없음)
printf '%s' "$SECRET_KEY" > secret_key.txt
docker buildx build \
--secret id=SECRET_KEY,src=secret_key.txt \
-t "$IMAGE_NAME:$IMAGE_TAG" \
--push .
rm -f secret_key.txt
- name: Checkout GitOps repo
uses: actions/checkout@v4
with:
repository: cobocho/gitops
token: ${{ secrets.GITOPS_REPO_ACCESS }}
path: gitops
- name: Update image tag in GitOps repo
run: |
cd gitops
FILE=./blog/blog-deploy.yaml
IMAGE_NAME=ghcr.io/cobocho/blog
sed -i "s|$IMAGE_NAME:.*|$IMAGE_NAME:${{ env.IMAGE_TAG }}|g" $FILE
- name: Create Pull Request to GitOps repo
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITOPS_REPO_ACCESS }}
path: gitops
commit-message: "chore: update blog image tag to ${{ env.IMAGE_TAG }}"
branch: update/image-${{ env.IMAGE_TAG }}
title: "Update blog image tag to ${{ env.IMAGE_TAG }}"
body: |
This PR updates the image tag in \`blog-deploy.yaml\` to \`${{ env.IMAGE_TAG }}\`.
- name: Calculate Elapsed Time
run: echo "ELAPSED_TIME=$(($(date +%s) - $START_TIME))" >> $GITHUB_ENV
if: always()
- name: Send Discord Notification (Success)
if: success()
uses: Ilshidur/action-discord@master
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }}
with:
args: |
✅ **undefined.dev 컨테이너 업로드 완료!**
- ⏱ 소요 시간: `${{ env.ELAPSED_TIME }}`초
- 🔗 [Workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
- 🔗 [Pull Request](${{ steps.cpr.outputs.pull-request-url }})
- name: Send Discord Notification (Failed)
if: failure()
uses: Ilshidur/action-discord@master
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }}
with:
args: |
❌ **undefined.dev 컨테이너 업로드 실패!**
- 브랜치: `main`
- ⏱ 소요 시간: `${{ env.ELAPSED_TIME }}`초
- 🔗 [Workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})