Skip to content

Commit

Permalink
chore: Automate collectstatic and migrate commands (#427)
Browse files Browse the repository at this point in the history
* chore: Automate management commands on init

* chore: Run collectstatic only on init

* chore: Provide absolute path to manage.py

* docs: Mention what management command to run (collectstatic)

* chore: Include static files in Docker image

* chore: Run migrate command on init
  • Loading branch information
microamp authored Apr 23, 2024
1 parent 9a3f9f6 commit 8db6141
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ EOF
COPY docker/nginx-sandbox.conf /etc/nginx/sites-enabled/default
COPY docker/supervisord-sandbox.conf /app/supervisord.conf

COPY docker/init.sh /app/init.sh
RUN chmod +x /app/init.sh

RUN mkdir -p /app/media

CMD ["/usr/bin/supervisord", "-c", "/app/supervisord.conf"]
# Configure environment variables (each with a placeholder) required
# to bootstrap Django, so that collectstatic can run successfully
RUN APP_SECRET_KEY="abcdef" \
DATABASE_URL="postgresql://userspec@hostspec/dbname?paramspec" \
python /app/manage.py collectstatic --no-input

CMD ["./init.sh"]
7 changes: 7 additions & 0 deletions docker/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

echo "Running migrate..."
python /app/manage.py migrate

echo "Starting supervisor..."
/usr/bin/supervisord -c /app/supervisord.conf

0 comments on commit 8db6141

Please sign in to comment.