Skip to content

Commit

Permalink
Fix static assets on staging (#484)
Browse files Browse the repository at this point in the history
* Add static asset build to cibuild

* Adjust context dir for django container

* Clean up unnecessary code

* Adjust how/when to build static assets

Local setup was previously dependent on there not being a /taui/assets/ dir, that way docker would ignore the command to copy on initial build in scripts/update when the assets had not been bundled yet. However, this isn't a very reliable setup since scripts/update could be called from a local environment and /taui/assets/ has potential to exist but be empty, which would throw an error on build. Instead, this waits to build the django container until after taui is built and bundled, so regardless of dev environment the build can succeed.

* Move yarn build outside of Dockerfile
  • Loading branch information
rachelekm authored May 12, 2022
1 parent 3ba2a3d commit 0b190a0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ services:
- DJANGO_SECRET_KEY=secret
- DJANGO_LOG_LEVEL=INFO
build:
context: ./src/backend
dockerfile: Dockerfile
context: ./
dockerfile: ./src/backend/Dockerfile
volumes:
- ./src/backend:/usr/local/src/backend
- $HOME/.aws:/root/.aws:ro
- type: bind
source: ./taui/index.html
target: /usr/local/src/backend/static/index.html
- ./taui/assets:/usr/local/src/backend/static/assets
- ./taui/index.html:/usr/local/src/backend/static/index.html
working_dir: /usr/local/src/backend
depends_on:
database:
Expand Down
10 changes: 9 additions & 1 deletion scripts/update
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
usage
else
# Ensure container images are current
docker-compose build
docker-compose build taui

# Separated to build taui static assets before copied to django container
docker-compose \
-f docker-compose.yml \
run --rm --no-deps --entrypoint "bash -c" taui \
"yarn install && yarn build"

docker-compose build database django

# Bring up PostgreSQL and Django in a way that respects
# configured service health checks.
Expand Down
7 changes: 5 additions & 2 deletions src/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ FROM quay.io/azavea/django:3.2-python3.10-slim
RUN mkdir -p /usr/local/src/backend
WORKDIR /usr/local/src/backend

COPY requirements.txt /usr/local/src/backend/
COPY ./src/backend/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . /usr/local/src/backend
COPY ./src/backend /usr/local/src/backend

COPY ./taui/assets/ /usr/local/src/backend/static/assets
COPY ./taui/index.html /usr/local/src/backend/static/index.html

CMD ["-b :8085", \
"--workers=2", \
Expand Down

0 comments on commit 0b190a0

Please sign in to comment.