-
Notifications
You must be signed in to change notification settings - Fork 0
52 lines (47 loc) · 1.81 KB
/
Copy pathdocker-image.yml
File metadata and controls
52 lines (47 loc) · 1.81 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
name: Build and Push Docker Image
on:
push:
branches: [ "dev" ]
env:
# (도커허브로 변경 가능)
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
# 권한 설정
permissions:
contents: read
packages: write
steps:
# 1. 현재 레포 코드를 가상 서버로 가져옴
- name: Checkout repository
uses: actions/checkout@v4
# 레포 이름을 소문자로 변환해서 이미지명 저장
- name: Convert repository name to lowercase
run: echo "IMAGE_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
# 2. ghcr.io에 로그인 (이미지 push하려면 인증 필요)
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
# 로그인할 레지스트리 주소
registry: ${{ env.REGISTRY }}
# 이 워크플로우를 실행시킨 GitHub 사용자명(자동)
username: ${{ github.actor }}
# GitHub이 워크플로우마다 자동 발급하는 임시 인증 토큰
password: ${{ secrets.GITHUB_TOKEN }}
# 3. Dockerfile로 이미지 빌드하고, 성공하면 ghcr.io로 push
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/Dockerfile
push: true
# 이 이미지에 붙일 태그(버전 이름)
# Render 참조용 고정 주소, 특정 커밋을 가리키는 고유 주소
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
# 4. 이미지 push 완료 후 Render에 배포 트리거
- name: Trigger Render deploy
run: curl -X POST "${{ secrets.RENDER_DEPLOY_HOOK_URL }}"