
기존 - 약 5분
→ build 1분 30초
→ push 1분
→ pull + compose up 1분 30초
→ +@ 20~30초
build docker image → push image to AWS ECR → docker pull → docker-compose up
dev_cicd.yml
jobs:
Build_and_Push:
steps:
...
- name: Build api image
run: |
docker build -f Dockerfile.dev --platform linux/amd64 \\
-t ...amazonaws.com/${{ secrets.ECR_REPO_NAME }}:dev
- name: Build socket image
run: |
docker build -f Dockerfile.socket.dev --platform linux/amd64 \\
-t ...amazonaws.com/${{ secrets.ECR_REPO_NAME }}:socket.dev
- name: Push image to ECR
run: |
docker push ...amazonaws.com/${{ secrets.ECR_REPO_NAME }}:dev
docker push ...amazonaws.com/${{ secrets.ECR_REPO_NAME }}:socket.dev
...
Deploy:
steps:
...
- name: Deploy using shell scripts
run: |
sudo ... stop_container.sh
sudo ... deploy_container.sh
build & push를 병렬 실행 두 가지 방법
shell background
# build_and_push.sh
..
build_and_push_image() {
local dockerfile="$1"
local base_tag="$2"
..
docker buildx build \\
--file "$dockerfile" \\
--platform linux/amd64 \\
--push \\
..
.
log_success "이미지 빌드 및 푸시 완료: $base_tag"
}
..
build_and_push_image "./Dockerfile.dev" "dev" &
build_and_push_image "./Dockerfile.socket.dev" "socket.dev" &
buildkit bake 기반 병렬 실행
# docker-bake.hcl
group "default" {
targets = ["base", "dev", "socket"]
}
target "base" {...}
target "dev" {
dockerfile = "Dockerfile.dev"
context = "."
contexts = {
base = "target:base"
}
tags = [
"${ECR_REGISTRY}/${ECR_REPO_NAME}:dev",
"${ECR_REGISTRY}/${ECR_REPO_NAME}:dev.${VERSION_TAG}",
]
platforms = ["linux/amd64"]
# BuildKit 캐시 설정
cache-from = [
"type=registry,ref=${ECR_REGISTRY}/${ECR_REPO_NAME}:dev",
]
# inline 캐시
cache-to = [
"type=inline",
]
# Secret 마운트
secret = [
"id=dev_env,src=.envs/dev.env",
]
# Build args
args = {
BUILDKIT_INLINE_CACHE = "1"
BUILD_DATE = "${BUILD_DATE}"
VERSION = "${VERSION_TAG}"
}
# Registry 출력
output = ["type=registry"]
# Provenance 비활성화
attest = []
}
target "socket" {
...
}
# build&push shell script
# 병렬 실행
docker buildx bake \\
--file docker-bake.hcl \\
--progress=plain
# 단일 실행
docker buildx bake \\
--file docker-bake.hcl \\
--progress=plain \\
dev
# Dockerfile
# syntax=docker/dockerfile:1.4
...
RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \\
--mount=type=cache,target=/root/.cache/uv,sharing=locked \\
python -m pip install --upgrade pip && \\
python -m pip install uv && \\ # runner의 buildkit 캐시 스토리지에 캐시가 있을 경우 hit
python -m uv sync --no-dev