This commit is contained in:
leehk 2025-04-17 10:05:10 +08:00
parent 0a79654728
commit 3bd2ecbafc
2 changed files with 28 additions and 9 deletions

View File

@ -156,9 +156,10 @@ jobs:
ENV_ARGS=""
if [[ "$TEST_ENVS_JSON" != "[]" ]]; then
# Convert JSON array string to individual env vars
while IFS= read -r line; do
ENV_ARGS+=" -e \"$line\""
done <<< $(echo "$TEST_ENVS_JSON" | jq -r '.[]')
IFS=',' read -r -a env_array <<< $(echo "$TEST_ENVS_JSON" | jq -r '.[][]')
for env in "${env_array[@]}"; do
ENV_ARGS+=" -e \"$env\""
done
else
# Add a dummy env var if none are provided, as required by original script logic
ENV_ARGS+=" -e DUMMY_ENV_TEST_RUN_ID=${{ github.run_id }}"

View File

@ -1,5 +1,5 @@
# pull official base image
FROM python:3.11-slim-bullseye
FROM python:3.11-slim-bullseye AS base
# create directory for the app user
RUN mkdir -p /home/app
@ -16,16 +16,13 @@ WORKDIR $APP_HOME
# set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV ENVIRONMENT=prod
ENV TESTING=0
# 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 --dev
RUN pipenv install --deploy
# chown all the files to the app user
RUN chown -R app:app $APP_HOME
@ -33,8 +30,29 @@ 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
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
# run uvicorn
CMD ["pipenv", "run", "uvicorn", "main:app", "--reload", "--workers", "1", "--host", "0.0.0.0", "--port", "80"]
CMD ["pipenv", "run", "uvicorn", "main:app", "--reload", "--workers", "1", "--host", "0.0.0.0", "--port", "80"]