빌드 및 푸시 관련한 부분 추가
This commit is contained in:
150
8.2.7/Dockerfile
150
8.2.7/Dockerfile
@ -1,150 +0,0 @@
|
|||||||
FROM php:8.2.7-apache
|
|
||||||
|
|
||||||
# 지속적으로 필요한 패키지 설치
|
|
||||||
RUN set -eux; \
|
|
||||||
apt-get update; \
|
|
||||||
apt-get install -y --no-install-recommends \
|
|
||||||
# Ghostscript는 PDF 미리보기 렌더링에 필요합니다.
|
|
||||||
ghostscript \
|
|
||||||
; \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# PHP 확장 모듈 설치에 필요한 라이브러리 및 도구 설치
|
|
||||||
RUN set -eux; \
|
|
||||||
savedAptMark="$(apt-mark showmanual)"; \
|
|
||||||
apt-get update; \
|
|
||||||
apt-get install -y --no-install-recommends \
|
|
||||||
unzip \
|
|
||||||
libfreetype6-dev \
|
|
||||||
libicu-dev \
|
|
||||||
libjpeg-dev \
|
|
||||||
libmagickwand-dev \
|
|
||||||
libpng-dev \
|
|
||||||
libwebp-dev \
|
|
||||||
libzip-dev \
|
|
||||||
libxml2-dev \
|
|
||||||
; \
|
|
||||||
apt-get clean; \
|
|
||||||
\
|
|
||||||
# gd 확장 모듈 설정 (freetype, jpeg, webp 지원)
|
|
||||||
docker-php-ext-configure gd \
|
|
||||||
--with-freetype \
|
|
||||||
--with-jpeg \
|
|
||||||
--with-webp \
|
|
||||||
; \
|
|
||||||
# PHP 확장 모듈 설치
|
|
||||||
docker-php-ext-install -j "$(nproc)" \
|
|
||||||
bcmath \
|
|
||||||
exif \
|
|
||||||
gd \
|
|
||||||
intl \
|
|
||||||
mysqli \
|
|
||||||
zip \
|
|
||||||
soap \
|
|
||||||
; \
|
|
||||||
# imagick PECL 확장 설치 및 활성화 (버전 고정)
|
|
||||||
pecl install imagick-3.6.0; \
|
|
||||||
docker-php-ext-enable imagick; \
|
|
||||||
rm -r /tmp/pear; \
|
|
||||||
\
|
|
||||||
# 일부 확장 모듈이 표준출력에 출력하지 않는지 확인
|
|
||||||
out="$(php -r 'exit(0);')"; [ -z "$out" ]; \
|
|
||||||
err="$(php -r 'exit(0);' 3>&1 1>&2 2>&3)"; [ -z "$err" ]; \
|
|
||||||
\
|
|
||||||
extDir="$(php -r 'echo ini_get("extension_dir");')"; [ -d "$extDir" ]; \
|
|
||||||
\
|
|
||||||
# 설치된 확장 모듈 의존성 패키지를 수동 설치로 표시하여 제거되지 않도록 설정
|
|
||||||
apt-mark auto '.*' > /dev/null; \
|
|
||||||
apt-mark manual $savedAptMark; \
|
|
||||||
ldd "$extDir"/*.so \
|
|
||||||
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \
|
|
||||||
| sort -u \
|
|
||||||
| xargs -r dpkg-query --search \
|
|
||||||
| cut -d: -f1 \
|
|
||||||
| sort -u \
|
|
||||||
| xargs -rt apt-mark manual; \
|
|
||||||
\
|
|
||||||
# 빌드에 사용된 불필요한 패키지 자동 제거
|
|
||||||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
|
|
||||||
rm -rf /var/lib/apt/lists/*; \
|
|
||||||
\
|
|
||||||
# 확장 모듈 누락 여부 점검
|
|
||||||
! { ldd "$extDir"/*.so | grep 'not found'; }; \
|
|
||||||
\
|
|
||||||
# PHP 실행 시 오류 메시지 체크 (확장 모듈 로드 실패 등)
|
|
||||||
err="$(php --version 3>&1 1>&2 2>&3)"; [ -z "$err" ]
|
|
||||||
|
|
||||||
# 권장 PHP 설정 (opcache 활성화 및 기본 튜닝)
|
|
||||||
RUN set -eux; \
|
|
||||||
docker-php-ext-enable opcache; \
|
|
||||||
{ \
|
|
||||||
echo 'opcache.memory_consumption=128'; \
|
|
||||||
echo 'opcache.interned_strings_buffer=8'; \
|
|
||||||
echo 'opcache.max_accelerated_files=4000'; \
|
|
||||||
echo 'opcache.revalidate_freq=2'; \
|
|
||||||
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
|
|
||||||
|
|
||||||
# PHP 오류 로깅 설정
|
|
||||||
# 오류는 stderr로 출력하며, 프로덕션 환경에 적합하도록 설정
|
|
||||||
RUN { \
|
|
||||||
echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR'; \
|
|
||||||
echo 'display_errors = Off'; \
|
|
||||||
echo 'display_startup_errors = Off'; \
|
|
||||||
echo 'log_errors = On'; \
|
|
||||||
echo 'error_log = /dev/stderr'; \
|
|
||||||
echo 'log_errors_max_len = 1024'; \
|
|
||||||
echo 'ignore_repeated_errors = On'; \
|
|
||||||
echo 'ignore_repeated_source = Off'; \
|
|
||||||
echo 'html_errors = Off'; \
|
|
||||||
} > /usr/local/etc/php/conf.d/error-logging.ini
|
|
||||||
|
|
||||||
# Apache 모듈 활성화 및 설정
|
|
||||||
RUN set -eux; \
|
|
||||||
# URL 재작성과 캐시 만료 모듈 활성화
|
|
||||||
a2enmod rewrite expires; \
|
|
||||||
\
|
|
||||||
# 클라이언트 실제 IP를 올바르게 수집하기 위한 remoteip 모듈 활성화 및 설정
|
|
||||||
a2enmod remoteip; \
|
|
||||||
{ \
|
|
||||||
echo 'RemoteIPHeader X-Forwarded-For'; \
|
|
||||||
# 사설 네트워크 IP 범위 지정 (Docker 내부 등)
|
|
||||||
echo 'RemoteIPInternalProxy 10.0.0.0/8'; \
|
|
||||||
echo 'RemoteIPInternalProxy 172.16.0.0/12'; \
|
|
||||||
echo 'RemoteIPInternalProxy 192.168.0.0/16'; \
|
|
||||||
echo 'RemoteIPInternalProxy 169.254.0.0/16'; \
|
|
||||||
echo 'RemoteIPInternalProxy 127.0.0.0/8'; \
|
|
||||||
} > /etc/apache2/conf-available/remoteip.conf; \
|
|
||||||
a2enconf remoteip; \
|
|
||||||
\
|
|
||||||
# 로그 포맷에서 %h를 %a(IP주소)로 변경하여 프록시 환경에 맞춤
|
|
||||||
find /etc/apache2 -type f -name '*.conf' -exec sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' '{}' +
|
|
||||||
|
|
||||||
# Composer 설치 (설치 스크립트 해시 검증 적용)
|
|
||||||
RUN set -eux; \
|
|
||||||
EXPECTED_SIGNATURE="$(curl -s https://composer.github.io/installer.sig)"; \
|
|
||||||
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"; \
|
|
||||||
ACTUAL_SIGNATURE="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"; \
|
|
||||||
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]; then \
|
|
||||||
echo 'ERROR: Invalid installer signature'; \
|
|
||||||
rm composer-setup.php; \
|
|
||||||
exit 1; \
|
|
||||||
fi; \
|
|
||||||
php composer-setup.php --install-dir=/usr/local/bin --filename=composer; \
|
|
||||||
rm composer-setup.php
|
|
||||||
|
|
||||||
# Google Cloud API용 PHP 라이브러리 설치
|
|
||||||
RUN composer require google/cloud
|
|
||||||
|
|
||||||
# SimpleXLSX 라이브러리 설치 (엑셀 파싱용)
|
|
||||||
RUN composer require shuchkin/simplexlsx
|
|
||||||
|
|
||||||
# 웹 루트 볼륨 지정
|
|
||||||
VOLUME /var/www/html
|
|
||||||
|
|
||||||
# 엔트리포인트 스크립트 복사 및 실행 권한 부여
|
|
||||||
COPY entrypoint.sh /usr/local/bin
|
|
||||||
RUN chmod 755 /usr/local/bin/entrypoint.sh
|
|
||||||
|
|
||||||
# 엔트리포인트 및 기본 실행 명령어 지정
|
|
||||||
ENTRYPOINT ["entrypoint.sh"]
|
|
||||||
CMD ["apache2-foreground"]
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
services:
|
|
||||||
web:
|
|
||||||
build: .
|
|
||||||
image: reg.firstgarden.co.kr/php-apache:8.2.7
|
|
||||||
container_name: php-apache
|
|
||||||
ports:
|
|
||||||
- "8080:80" # 호스트 8080 포트를 컨테이너 80 포트에 매핑
|
|
||||||
environment:
|
|
||||||
PUID: 1000 # 필요에 따라 UID 지정 (호스트 사용자 ID)
|
|
||||||
PGID: 1000 # 필요에 따라 GID 지정 (호스트 그룹 ID)
|
|
||||||
APACHE_RUN_USER: www-data
|
|
||||||
APACHE_RUN_GROUP: www-data
|
|
||||||
volumes:
|
|
||||||
- ./html:/var/www/html # 소스코드 마운트 (호스트 ./html → 컨테이너 /var/www/html)
|
|
||||||
restart: unless-stopped
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -Eeuo pipefail
|
|
||||||
|
|
||||||
# 환경변수 PUID가 설정되어 있으면 www-data 사용자의 UID를 변경
|
|
||||||
if [[ -n "${PUID}" ]]
|
|
||||||
then
|
|
||||||
usermod -u ${PUID} www-data
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 환경변수 PGID가 설정되어 있으면 www-data 그룹의 GID를 변경
|
|
||||||
if [[ -n "${PGID}" ]]
|
|
||||||
then
|
|
||||||
groupmod -g ${PGID} www-data
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 첫 번째 인자가 apache2* 또는 php-fpm이면
|
|
||||||
if [[ "$1" == apache2* ]] || [ "$1" = 'php-fpm' ]; then
|
|
||||||
uid="$(id -u)"
|
|
||||||
gid="$(id -g)"
|
|
||||||
# 현재 UID가 root이면
|
|
||||||
if [ "$uid" = '0' ]; then
|
|
||||||
case "$1" in
|
|
||||||
apache2*)
|
|
||||||
user="${APACHE_RUN_USER:-www-data}"
|
|
||||||
group="${APACHE_RUN_GROUP:-www-data}"
|
|
||||||
|
|
||||||
# Apache에서 '#1000' 형식 UID/GID에서 '#' 제거
|
|
||||||
pound='#'
|
|
||||||
user="${user#$pound}"
|
|
||||||
group="${group#$pound}"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
# php-fpm인 경우 기본 사용자 www-data
|
|
||||||
user='www-data'
|
|
||||||
group='www-data'
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
else
|
|
||||||
# root이 아니면 현재 uid/gid 그대로 사용
|
|
||||||
user="$uid"
|
|
||||||
group="$gid"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 마지막으로 인자로 받은 명령어 실행 (ex: apache2-foreground)
|
|
||||||
exec "$@"
|
|
||||||
24
README.md
24
README.md
@ -15,11 +15,33 @@ git clone https://git.siane.kr/firstgarden/php-apache
|
|||||||
cd php-apache
|
cd php-apache
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. 환경설정 및 실행
|
### 2. 환경설정
|
||||||
```bash
|
```bash
|
||||||
cp .env.example .env
|
cp .env.example .env
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3-1. 첫 배포 시 (로컬에서 빌드 후 사설 저장소에 푸시)
|
||||||
|
```bash
|
||||||
docker compose up -d --build
|
docker compose up -d --build
|
||||||
```
|
```
|
||||||
|
빌드 완료 후, 빌드된 이미지를 사설 저장소에 푸시:
|
||||||
|
```bash
|
||||||
|
# Linux/Mac
|
||||||
|
./build-and-push.sh
|
||||||
|
|
||||||
|
# Windows PowerShell
|
||||||
|
.\build-and-push.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3-2. 이후 배포 시 (사설 저장소에서 이미지 다운로드)
|
||||||
|
```bash
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
> **주의**: 사설 저장소에서 이미지를 받으려면 Docker 레지스트리 로그인이 필요합니다.
|
||||||
|
> ```bash
|
||||||
|
> docker login reg.firstgarden.co.kr
|
||||||
|
> ```
|
||||||
|
|
||||||
## 접속 정보
|
## 접속 정보
|
||||||
- **PHP 8.2**: http://localhost
|
- **PHP 8.2**: http://localhost
|
||||||
|
|||||||
43
build-and-push.ps1
Normal file
43
build-and-push.ps1
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# 사설 Docker 레지스트리
|
||||||
|
$REGISTRY = "reg.firstgarden.co.kr"
|
||||||
|
$IMAGE_NAME = "php-apache"
|
||||||
|
|
||||||
|
Write-Host "=== PHP 이미지 빌드 및 푸시 시작 ===" -ForegroundColor Yellow
|
||||||
|
|
||||||
|
# PHP 8.2 빌드 및 푸시
|
||||||
|
Write-Host "Building PHP 8.2..." -ForegroundColor Yellow
|
||||||
|
docker build -f 8.2/Dockerfile -t "$($REGISTRY)/$($IMAGE_NAME):8.2" .
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Host "PHP 8.2 빌드 성공" -ForegroundColor Green
|
||||||
|
Write-Host "Pushing PHP 8.2 to registry..." -ForegroundColor Yellow
|
||||||
|
docker push "$($REGISTRY)/$($IMAGE_NAME):8.2"
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Host "PHP 8.2 푸시 성공" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "PHP 8.2 푸시 실패" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "PHP 8.2 빌드 실패" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# PHP 8.4 빌드 및 푸시
|
||||||
|
Write-Host "Building PHP 8.4..." -ForegroundColor Yellow
|
||||||
|
docker build -f 8.4/Dockerfile -t "$($REGISTRY)/$($IMAGE_NAME):8.4" .
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Host "PHP 8.4 빌드 성공" -ForegroundColor Green
|
||||||
|
Write-Host "Pushing PHP 8.4 to registry..." -ForegroundColor Yellow
|
||||||
|
docker push "$($REGISTRY)/$($IMAGE_NAME):8.4"
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Host "PHP 8.4 푸시 성공" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "PHP 8.4 푸시 실패" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "PHP 8.4 빌드 실패" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "=== 모든 이미지 빌드 및 푸시 완료 ===" -ForegroundColor Green
|
||||||
51
build-and-push.sh
Normal file
51
build-and-push.sh
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 사설 Docker 레지스트리
|
||||||
|
REGISTRY="reg.firstgarden.co.kr"
|
||||||
|
IMAGE_NAME="php-apache"
|
||||||
|
|
||||||
|
# 색상 정의
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
echo -e "${YELLOW}=== PHP 이미지 빌드 및 푸시 시작 ===${NC}"
|
||||||
|
|
||||||
|
# PHP 8.2 빌드 및 푸시
|
||||||
|
echo -e "${YELLOW}Building PHP 8.2...${NC}"
|
||||||
|
docker build -f 8.2/Dockerfile -t ${REGISTRY}/${IMAGE_NAME}:8.2 .
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo -e "${GREEN}PHP 8.2 빌드 성공${NC}"
|
||||||
|
echo -e "${YELLOW}Pushing PHP 8.2 to registry...${NC}"
|
||||||
|
docker push ${REGISTRY}/${IMAGE_NAME}:8.2
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo -e "${GREEN}PHP 8.2 푸시 성공${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}PHP 8.2 푸시 실패${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -e "${RED}PHP 8.2 빌드 실패${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# PHP 8.4 빌드 및 푸시
|
||||||
|
echo -e "${YELLOW}Building PHP 8.4...${NC}"
|
||||||
|
docker build -f 8.4/Dockerfile -t ${REGISTRY}/${IMAGE_NAME}:8.4 .
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo -e "${GREEN}PHP 8.4 빌드 성공${NC}"
|
||||||
|
echo -e "${YELLOW}Pushing PHP 8.4 to registry...${NC}"
|
||||||
|
docker push ${REGISTRY}/${IMAGE_NAME}:8.4
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo -e "${GREEN}PHP 8.4 푸시 성공${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}PHP 8.4 푸시 실패${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -e "${RED}PHP 8.4 빌드 실패${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}=== 모든 이미지 빌드 및 푸시 완료 ===${NC}"
|
||||||
@ -3,6 +3,7 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: 8.2/Dockerfile
|
dockerfile: 8.2/Dockerfile
|
||||||
|
image: reg.firstgarden.co.kr/php-apache:8.2
|
||||||
container_name: cafe24-php-8.2
|
container_name: cafe24-php-8.2
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "80:80"
|
||||||
@ -27,6 +28,7 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: 8.4/Dockerfile
|
dockerfile: 8.4/Dockerfile
|
||||||
|
image: reg.firstgarden.co.kr/php-apache:8.4
|
||||||
container_name: cafe24-php-8.4
|
container_name: cafe24-php-8.4
|
||||||
ports:
|
ports:
|
||||||
- "8084:80"
|
- "8084:80"
|
||||||
|
|||||||
Reference in New Issue
Block a user