diff --git a/.github/workflows/build_new.yml b/.github/workflows/build_new.yml index 8186934..701c3db 100644 --- a/.github/workflows/build_new.yml +++ b/.github/workflows/build_new.yml @@ -73,17 +73,17 @@ jobs: testContainerName: tests-aimingmedai # Pass test environment variables as JSON string testEnvs: > - [ + '[ "FRONTEND_URL=http://frontend:80", "BACKEND_URL=http://backend:80", "ENVIRONMENT=dev", "TESTING=1", - ] + ]' # Pass test directories as JSON string tests: > - [ + '[ "tests/integration/backend", - ] + ]' # Pass image definitions for compose setup as JSON string # Sensitive values should be passed via secrets and referenced within the template images: > diff --git a/app/backend/Dockerfile b/app/backend/Dockerfile index 71da6e4..a3c5e17 100644 --- a/app/backend/Dockerfile +++ b/app/backend/Dockerfile @@ -1,5 +1,5 @@ # pull official base image -FROM python:3.11-slim-bullseye AS base +FROM python:3.11-slim-bullseye # create directory for the app user RUN mkdir -p /home/app @@ -16,13 +16,15 @@ WORKDIR $APP_HOME # set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 +ENV ENVIRONMENT=dev +ENV TESTING=1 # add app COPY . $APP_HOME # install python dependencies RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv && rm -rf ~/.cache/pip -RUN pipenv install --deploy +RUN pipenv install --deploy --dev # chown all the files to the app user RUN chown -R app:app $APP_HOME @@ -30,26 +32,10 @@ RUN chown -R app:app $APP_HOME # change to the app user USER app - - -# TEST -FROM base AS test - -ENV ENVIRONMENT=dev -ENV TESTING=1 - -RUN pipenv install --deploy --dev - -# run tests +# pytest RUN pipenv run pytest tests --disable-warnings -# BUILD -FROM base AS builder - -ENV ENVIRONMENT=prod -ENV TESTING=0 - # expose the port the app runs on EXPOSE 80 diff --git a/app/backend/Dockerfile.prod b/app/backend/Dockerfile.prod index 40d5bc0..bb47d1e 100644 --- a/app/backend/Dockerfile.prod +++ b/app/backend/Dockerfile.prod @@ -5,7 +5,6 @@ # pull official base image FROM python:3.11-slim-bookworm AS builder - # set working directory WORKDIR /usr/src/app @@ -13,11 +12,6 @@ WORKDIR /usr/src/app ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 -# install system dependencies -# RUN apt-get update && apt-get -y install build-essential \ -# && apt-get clean \ -# && rm -rf /var/lib/apt/lists/* - # install python dependencies RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv && rm -rf ~/.cache/pip COPY ./Pipfile . @@ -25,6 +19,7 @@ RUN pipenv install --deploy --dev # add app COPY . /usr/src/app +RUN pipenv run pytest tests --disable-warnings # RUN pipenv run pip install black==23.12.1 flake8==7.0.0 isort==5.13.2 # RUN pipenv run flake8 . # RUN pipenv run black --exclude=migrations . --check @@ -58,9 +53,8 @@ ENV TESTING=0 # install python dependencies -COPY --from=builder /usr/src/app/Pipfile . RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pipenv && rm -rf ~/.cache/pip -RUN pipenv install --deploy --dev +RUN pipenv install --deploy RUN pipenv run pip install "uvicorn[standard]==0.26.0" # add app @@ -73,7 +67,7 @@ RUN chown -R app:app $APP_HOME USER app # expose the port the app runs on -EXPOSE 8765 +EXPOSE 80 # run uvicorn -CMD ["pipenv", "run", "uvicorn", "main:app", "--reload", "--workers", "1", "--host", "0.0.0.0", "--port", "80"] \ No newline at end of file +CMD ["pipenv", "run", "uvicorn", "main:app", "--reload", "--workers", "1", "--host", "0.0.0.0", "--port", "80"]