Skip to content

Commit a8852a7

Browse files
committed
feat(pw): cicd시 env 파일 생성 및 password 생성 스크립트에서 기본 DOCKER_CMD="echo $PW | sudo -S docker" 사용
1 parent 6e99189 commit a8852a7

2 files changed

Lines changed: 36 additions & 21 deletions

File tree

.github/workflows/SEJONG-MALSAMI-SCRIPT-CICD.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
deploy:
1010
runs-on: ubuntu-20.04
1111
steps:
12-
# 리포 코드 체크아웃
12+
# 소스 코드 체크아웃
1313
- name: 소스 코드 가져오기
1414
uses: actions/checkout@v3
1515
with:
@@ -18,6 +18,12 @@ jobs:
1818
- name: 소스 코드 체크아웃 확인
1919
run: echo "소스 코드를 성공적으로 가져왔습니다."
2020

21+
# .env 파일 생성
22+
- name: Create .env file
23+
run: |
24+
echo "PW=${{ secrets.SERVER_PASSWORD }}" > bin/.env
25+
echo ".env 파일이 성공적으로 생성되었습니다."
26+
2127
# 서버 bin 폴더 업로드
2228
- name: bin 폴더 업로드
2329
uses: appleboy/[email protected]
@@ -32,7 +38,7 @@ jobs:
3238
- name: bin 폴더 업로드 확인
3339
run: echo "bin 폴더가 서버에 성공적으로 업로드되었습니다."
3440

35-
# SSH 접속 -> 권한 설정
41+
# SSH 접속 -> 스크립트 권한 설정
3642
- name: 스크립트 실행 권한 설정
3743
uses: appleboy/[email protected]
3844
with:
@@ -45,9 +51,8 @@ jobs:
4551
4652
echo "=== 환경 변수 설정 중 ==="
4753
export PATH=$PATH:/usr/local/bin
48-
export PW=${{ secrets.SERVER_PASSWORD }}
4954
SEJONG_MALSAMI_BIN="${{ secrets.SEJONG_MALSAMI_DIR }}/bin"
5055
5156
echo "=== 스크립트 실행 권한 설정 시작 ==="
52-
echo $PW | sudo -S chmod +x ${SEJONG_MALSAMI_BIN}/*.sh
53-
echo "=== 스크립트 실행 권한 설정 완료 ==="
57+
sudo chmod +x ${SEJONG_MALSAMI_BIN}/*.sh
58+
echo "=== 스크립트 실행 권한 설정 완료 ==="

bin/docker_info.sh

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@
22
#
33
# docker_info.sh - 시놀로지 환경에서 sudo docker를 사용하여
44
# 컨테이너/이미지 정보를 JSON 형태로 ONLY 출력하는 스크립트
5-
#
6-
# chkconfig: - 60 30
7-
# description: Docker info as JSON
8-
#
5+
# HISTORY
6+
# 2025.01.17 : SUHSAECHAN : PW 스크립트 추가
97

108
set -euo pipefail
119
IFS=$'\n\t'
1210

13-
DOCKER_CMD="sudo docker"
11+
# .env 파일 유효성 확인
12+
if [[ ! -f ".env" ]]; then
13+
echo '{"error": ".env file not found. Please create an .env file with the required variables."}'
14+
exit 1
15+
fi
16+
17+
# .env 파일 읽기
18+
source .env
19+
20+
# PW 변수 확인
21+
if [[ -z "${PW:-}" ]]; then
22+
echo '{"error": "PW is not set in the .env file. Please set PW to use this script."}'
23+
exit 1
24+
fi
25+
26+
DOCKER_CMD="echo $PW | sudo -S docker"
1427

1528
# jq가 설치되어 있는지 확인
1629
if ! command -v jq &> /dev/null; then
@@ -30,15 +43,15 @@ error_exit() {
3043
# 컨테이너 존재 여부 확인
3144
validate_container() {
3245
local container_name="$1"
33-
if ! ${DOCKER_CMD} ps -a --format '{{.Names}}' | grep -wq "${container_name}"; then
46+
if ! $DOCKER_CMD ps -a --format '{{.Names}}' | grep -wq "${container_name}"; then
3447
error_exit "Container '${container_name}' does not exist."
3548
fi
3649
}
3750

3851
# 이미지 존재 여부 확인
3952
validate_image() {
4053
local image_name="$1"
41-
if ! ${DOCKER_CMD} images --format '{{.Repository}}:{{.Tag}}' | grep -wq "${image_name}"; then
54+
if ! $DOCKER_CMD images --format '{{.Repository}}:{{.Tag}}' | grep -wq "${image_name}"; then
4255
error_exit "Image '${image_name}' does not exist."
4356
fi
4457
}
@@ -55,7 +68,7 @@ show_container_info() {
5568

5669
validate_container "${container_name}"
5770

58-
${DOCKER_CMD} inspect "${inspect_options[@]}" "${container_name}" | jq '.[0]'
71+
$DOCKER_CMD inspect "${inspect_options[@]}" "${container_name}" | jq '.[0]'
5972
}
6073

6174
# 이미지 정보 (docker inspect <image_name> [OPTIONS])
@@ -70,19 +83,19 @@ show_image_info() {
7083

7184
validate_image "${image_name}"
7285

73-
${DOCKER_CMD} inspect "${inspect_options[@]}" "${image_name}" | jq '.[0]'
86+
$DOCKER_CMD inspect "${inspect_options[@]}" "${image_name}" | jq '.[0]'
7487
}
7588

7689
# 모든 컨테이너 목록 (docker ps [OPTIONS])
7790
list_containers() {
7891
local ps_options=("$@")
79-
${DOCKER_CMD} ps "${ps_options[@]}" --format '{{json .}}' | jq -s .
92+
$DOCKER_CMD ps "${ps_options[@]}" --format '{{json .}}' | jq -s .
8093
}
8194

8295
# 모든 이미지 목록 (docker images [OPTIONS])
8396
list_images() {
8497
local images_options=("$@")
85-
${DOCKER_CMD} images "${images_options[@]}" --format '{{json .}}' | jq -s .
98+
$DOCKER_CMD images "${images_options[@]}" --format '{{json .}}' | jq -s .
8699
}
87100

88101
# 컨테이너 로그 (docker logs <container_name> [OPTIONS])
@@ -98,7 +111,7 @@ show_container_logs() {
98111
validate_container "${container_name}"
99112

100113
# 로그 명령어 실행
101-
logs=$(${DOCKER_CMD} logs "${log_options[@]}" "${container_name}" 2>&1 || true)
114+
logs=$($DOCKER_CMD logs "${log_options[@]}" "${container_name}" 2>&1 || true)
102115

103116
# 로그를 JSON 배열로 변환
104117
echo "$logs" | jq -R -s -c 'split("\n") | map(select(length > 0))'
@@ -107,7 +120,7 @@ show_container_logs() {
107120
# 시스템 정보 (docker info [OPTIONS])
108121
show_system_info() {
109122
local info_options=("$@")
110-
${DOCKER_CMD} info "${info_options[@]}" --format '{{json .}}' | jq '.'
123+
$DOCKER_CMD info "${info_options[@]}" --format '{{json .}}' | jq '.'
111124
}
112125

113126
# 메인 로직
@@ -134,12 +147,10 @@ main() {
134147
show_image_info "${image_name}" "$@"
135148
;;
136149
ps)
137-
# 'ps'는 추가 옵션 없이도 사용 가능
138150
shift 1
139151
list_containers "$@"
140152
;;
141153
images)
142-
# 'images'는 추가 옵션 없이도 사용 가능
143154
shift 1
144155
list_images "$@"
145156
;;
@@ -152,7 +163,6 @@ main() {
152163
show_container_logs "${container_name}" "$@"
153164
;;
154165
system)
155-
# 'system'은 추가 옵션 없이도 사용 가능
156166
shift 1
157167
show_system_info "$@"
158168
;;

0 commit comments

Comments
 (0)