diff --git a/.gitea/workflows/deploy-cd-server.yaml b/.gitea/workflows/deploy-cd-server.yaml index 4bc5002..cad7f14 100644 --- a/.gitea/workflows/deploy-cd-server.yaml +++ b/.gitea/workflows/deploy-cd-server.yaml @@ -19,7 +19,7 @@ jobs: - name: Deploy to Lightsail VM uses: appleboy/ssh-action@v1.0.3 with: - host: ${{ secrets.LIGHTSAIL_HOST }} + host: ${{ vars.LIGHTSAIL_DEPLOY_HOST }} username: ${{ secrets.LIGHTSAIL_USERNAME }} key: ${{ secrets.LIGHTSAIL_SSH_KEY }} port: ${{ vars.LIGHTSAIL_PORT }} @@ -47,7 +47,7 @@ jobs: --exclude='__pycache__' \ --exclude='*.pyc' \ --exclude='.env' \ - ./ "$DEPLOY_DIR/" + ./workspace/sprint_1_2/CODEBASE/deps/implementation/CD_server/ "$DEPLOY_DIR/" echo "[deploy] Building CD server Docker image" sudo -u deploy docker compose -f "$DEPLOY_DIR/docker-compose.yml" build --no-cache diff --git a/workspace/sprint_1_2/CODEBASE/deps/implementation/CD_server/Dockerfile b/workspace/sprint_1_2/CODEBASE/deps/implementation/CD_server/Dockerfile index 24ab487..3670659 100644 --- a/workspace/sprint_1_2/CODEBASE/deps/implementation/CD_server/Dockerfile +++ b/workspace/sprint_1_2/CODEBASE/deps/implementation/CD_server/Dockerfile @@ -1,17 +1,33 @@ -FROM python:3.12-slim +# Stage 1: Builder +FROM python:3.12-slim AS builder WORKDIR /app COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt -COPY main.py config.py docker_ops.py schemas.py config.yaml ./ +# Simply downloads the pre-compiled wheels from PyPI without needing a compiler +RUN pip wheel --no-cache-dir --wheel-dir=/app/wheels -r requirements.txt -RUN groupadd -g 998 docker || true -RUN useradd -m -u 998 -g docker appuser + +# Stage 2: Final Runtime +FROM python:3.12-slim + +WORKDIR /app + +# 1. Setup system user first (Cached forever because it doesn't rely on files) +RUN groupadd -g 998 docker || true \ + && useradd -l -m -u 998 -g docker appuser + +# 2. Bring in the wheels +COPY --from=builder /app/wheels /app/wheels + +# 3. Install dependencies (Only runs if requirements.txt changed) +RUN pip install --no-cache-dir --no-index --find-links=/app/wheels /app/wheels/*.whl \ + && rm -rf /app/wheels + +# 4. Copy code files +COPY --chown=appuser:docker main.py config.py docker_ops.py schemas.py config.yaml ./ USER appuser - EXPOSE 3333 - -CMD ["python", "main.py"] +CMD ["python", "main.py"] \ No newline at end of file