1 Commits

Author SHA1 Message Date
6848baae5f Merge pull request 'feat: 자산관리 시스템 도커 운영 배포 환경 및 CI/CD 구축' (#21) from feature/docker-deploy into main
All checks were successful
ITAM Docker Build Check / docker-build-check (push) Successful in 18s
ITAM Code Check / build-and-config-check (push) Successful in 20s
Reviewed-on: #21
2026-06-19 10:50:17 +09:00
4 changed files with 19 additions and 33 deletions

View File

@@ -71,11 +71,6 @@ jobs:
PROD_DEPLOY_PATH: ${{ vars.PROD_DEPLOY_PATH }}
PROD_BACKUP_ROOT: ${{ vars.PROD_BACKUP_ROOT }}
PROD_GIT_URL: ${{ vars.PROD_GIT_URL }}
DB_HOST: ${{ vars.PROD_DB_HOST }}
DB_PORT: ${{ vars.PROD_DB_PORT }}
DB_USER: ${{ vars.PROD_DB_USER }}
DB_PASS: ${{ secrets.PROD_DB_PASS }}
DB_NAME: ${{ vars.PROD_DB_NAME }}
TARGET_BRANCH: ${{ github.event.inputs.target_branch }}
run: |
set -euo pipefail
@@ -83,7 +78,7 @@ jobs:
ssh "${PROD_USER}@${PROD_HOST}" "mkdir -p '${PROD_DEPLOY_PATH}'"
EFFECTIVE_BACKUP_ROOT="${PROD_BACKUP_ROOT:-/home/user/dachs_backups}"
EFFECTIVE_BACKUP_ROOT="${PROD_BACKUP_ROOT:-${PROD_DEPLOY_PATH%/}_backups}"
ssh "${PROD_USER}@${PROD_HOST}" "export DEPLOY_PATH='${PROD_DEPLOY_PATH}' BACKUP_ROOT='${EFFECTIVE_BACKUP_ROOT}'; sh -eu -s" <<'REMOTE_BACKUP'
case "$BACKUP_ROOT" in
@@ -95,12 +90,12 @@ jobs:
if [ -d "$DEPLOY_PATH/.git" ]; then
mkdir -p "$BACKUP_ROOT"
echo "Starting pre-deploy backup..."
cd "$DEPLOY_PATH"
if [ -f Makefile ] && [ -f scripts/backup.sh ]; then
make predeploy-backup ENV_FILE=.env BACKUP_ROOT="$BACKUP_ROOT"
make predeploy-backup BACKUP_ROOT="$BACKUP_ROOT"
else
echo "Skipping pre-deploy backup because current deployed revision does not contain backup tooling."
echo "Skipping pre-deploy backup because current deployed revision does not contain Makefile backup tooling."
fi
else
echo "Skipping pre-deploy backup because no existing deployment was found."
@@ -133,8 +128,9 @@ jobs:
PROD_DEPLOY_PATH: ${{ vars.PROD_DEPLOY_PATH }}
run: |
set -euo pipefail
ssh "${PROD_USER}@${PROD_HOST}" "curl -fsS http://localhost:9090/health"
ssh "${PROD_USER}@${PROD_HOST}" "cd '${PROD_DEPLOY_PATH}' && docker compose -f docker-compose.prod.yaml exec -T backend curl -fsS http://localhost:3000/health"
ssh "${PROD_USER}@${PROD_HOST}" "curl -fsS http://localhost/health"
ssh "${PROD_USER}@${PROD_HOST}" "curl -fsS http://localhost/ > /dev/null"
ssh "${PROD_USER}@${PROD_HOST}" "cd '${PROD_DEPLOY_PATH}' && docker compose -f docker-compose.prod.yaml exec -T backend curl -fsS http://localhost:3000/ready"
- name: Cleanup generated env file
if: ${{ always() }}

View File

@@ -8,7 +8,7 @@ ENV NODE_ENV=production
WORKDIR /app
# Install curl for health checks and dumb-init for proper signal handling
RUN apk add --no-cache curl dumb-init mysql-client
RUN apk add --no-cache curl dumb-init
# Copy package files
COPY package*.json ./

View File

@@ -38,7 +38,7 @@ services:
image: nginx:stable-alpine
container_name: itam-nginx
ports:
- "9090:80"
- "80:80"
volumes:
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
- ./logs/nginx:/var/log/nginx

View File

@@ -21,10 +21,6 @@ require_command() {
command -v "$1" >/dev/null 2>&1 || fail "Required command not found: $1"
}
has_command() {
command -v "$1" >/dev/null 2>&1
}
load_env() {
[ -f "$ENV_FILE" ] || fail "Env file not found: $ENV_FILE"
@@ -41,6 +37,7 @@ load_env() {
}
db_dump() {
require_command mysqldump
require_command gzip
load_env
@@ -48,22 +45,15 @@ db_dump() {
output_path="$BACKUP_ROOT/db/${DB_NAME}_${TIMESTAMP}.sql.gz"
log "Creating DB dump: $output_path"
if has_command mysqldump; then
MYSQL_PWD="$DB_PASS" mysqldump \
--host="$DB_HOST" \
--port="$DB_PORT" \
--user="$DB_USER" \
--single-transaction \
--quick \
--routines \
--triggers \
"$DB_NAME" | gzip > "$output_path"
elif has_command docker; then
docker exec itam-backend sh -lc "MYSQL_PWD=\"$DB_PASS\" exec mysqldump --host=\"$DB_HOST\" --port=\"$DB_PORT\" --user=\"$DB_USER\" --single-transaction --quick --routines --triggers \"$DB_NAME\"" | gzip > "$output_path"
else
fail "Required command not found: mysqldump (and docker fallback unavailable)"
fi
MYSQL_PWD="$DB_PASS" mysqldump \
--host="$DB_HOST" \
--port="$DB_PORT" \
--user="$DB_USER" \
--single-transaction \
--quick \
--routines \
--triggers \
"$DB_NAME" | gzip > "$output_path"
log "DB dump completed: $output_path"
}