Skip to content

Commit

Permalink
Export env variables to docker container on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
lcarvajal committed Jul 26, 2024
1 parent 6028680 commit 527d1a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@

FROM python:3.11

# Set the working directory
WORKDIR /code

# Copy the requirements file and install dependencies
COPY requirements.txt .

RUN pip install --no-cache-dir --upgrade -r requirements.txt

# Copy the rest of the application code
COPY . .

# Create the startup script
RUN echo '#!/bin/sh' > /code/startup.sh && \
echo 'eval $(printenv | sed -n "s/^\([^=]\+\)=\(.*\)$/export \1='\''\2'\''/p")' >> /code/startup.sh && \
chmod +x /code/startup.sh

# Expose the port the app runs on
EXPOSE 8000

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
# Command to run the application
CMD ["/bin/sh", "-c", "/code/startup.sh && uvicorn app.main:app --host 0.0.0.0 --port 8000"]
3 changes: 3 additions & 0 deletions startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
# Export environment variables for the current session
eval $(printenv | sed -n "s/^\([^=]\+\)=\(.*\)$/export \1='\2'/p")

0 comments on commit 527d1a8

Please sign in to comment.