コンテナイメージ公開CIを追加
Validate and publish container image / build (pull_request) Failing after 1m31s

This commit is contained in:
2026-07-18 08:42:04 +09:00
parent 8fe18971f0
commit c14716c46b
9 changed files with 202 additions and 28 deletions
+14 -5
View File
@@ -1,4 +1,4 @@
FROM python:3.11-slim
FROM python:3.11-slim AS base
# 作業ディレクトリを設定
WORKDIR /app
@@ -15,14 +15,23 @@ RUN pip install --no-cache-dir -r requirements.txt
# アプリケーションファイルをコピー
COPY app.py .
# テスト用ステージ(CIではこのステージまでビルドして単体テストを実行)
FROM base AS test
COPY docker-compose.yml docker-compose.local.yml ./
COPY tests ./tests
RUN python -m unittest discover -s tests -v
# 実行用ステージ
FROM base AS runtime
# 非rootユーザーを作成
RUN useradd --create-home --shell /bin/bash appuser
RUN chown -R appuser:appuser /app
RUN useradd --create-home --shell /bin/bash appuser \
&& chown -R appuser:appuser /app
USER appuser
# ヘルスチェックを追加
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import sys; sys.exit(0)"
CMD python -c "from pathlib import Path; import sys; sys.exit(0 if b'app.py' in Path('/proc/1/cmdline').read_bytes() else 1)"
# アプリケーションを実行
CMD ["python", "app.py"]
CMD ["python", "app.py"]