Skip to content

Commit

Permalink
Fix API image builds (#2410)
Browse files Browse the repository at this point in the history
  • Loading branch information
zackkrida authored Jun 15, 2023
1 parent 41b0cdb commit 69a87d7
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ FROM realies/audiowaveform:latest AS awf
# Identify dependencies of the `audiowaveform` binary and move them to `/deps`,
# while retaining their folder structure
RUN ldd /usr/local/bin/audiowaveform | tr -s '[:blank:]' '\n' | grep '^/' | \
xargs -I % sh -c 'mkdir -p $(dirname deps%); cp % deps%;'
xargs -I % sh -c 'mkdir -p $(dirname deps%); cp % deps%;'

##################
# Python builder #
Expand All @@ -32,10 +32,10 @@ ENV PATH="/venv/bin:$PATH"
# - Create a virtualenv inside `/venv`
# - Install Pipenv to install Python dependencies
RUN apt-get update \
&& apt-get install -y python3-dev \
&& rm -rf /var/lib/apt/lists/* \
&& python -m venv /venv \
&& pip install --upgrade pipenv
&& apt-get install -y python3-dev \
&& rm -rf /var/lib/apt/lists/* \
&& python -m venv /venv \
&& pip install --upgrade pipenv

# Copy the Pipenv files into the container
COPY Pipfile Pipfile.lock ./
Expand Down Expand Up @@ -66,8 +66,15 @@ ADD api/utils/fonts/SourceSansPro-Bold.ttf /usr/share/fonts/truetype/SourceSansP
# Copy virtualenv from the builder image
COPY --from=builder /venv /venv

# Copy `audiowaveform` dependencies
COPY --from=awf /deps /
# Copy `audiowaveform` dependencies. This is unreliable as we use
# The `latest` version of the audiowaveform image which may introduce
# dependency changes which *could* have a different directory structure.
# If this step is failing, try adding the logging in this commit to help
# update the dependency paths:
# https://github.com/WordPress/openverse/commit/6cd8e3944a1d4ba7a3e80705b969a6a50eb75b5a
COPY --from=awf /deps/lib/ /lib/
COPY --from=awf /deps/usr/ /usr/

# Copy `audiowaveform` binary
COPY --from=awf /usr/local/bin/audiowaveform /usr/local/bin

Expand All @@ -76,27 +83,27 @@ COPY --from=awf /usr/local/bin/audiowaveform /usr/local/bin
# - libpq-dev: required by `psycopg2`
# - Create directory for dumping API logs
RUN apt-get update \
&& apt-get install -y curl libpq-dev libexempi8 postgresql-client \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /var/log/openverse_api/openverse_api.log
&& apt-get install -y curl libpq-dev libexempi8 postgresql-client \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /var/log/openverse_api/openverse_api.log

# Create a folder for placing static files
RUN mkdir /static

# Create a non-root user, and make it the owner of the static dir created above
RUN useradd --create-home opener \
&& chown -R opener /static
&& chown -R opener /static
USER opener

# Copy code into the final image
COPY --chown=opener . /api/

# Collect static assets, these are used by the next stage, `nginx`
RUN env \
SETUP_ES="False" \
STATIC_ROOT="/static" \
DJANGO_SECRET_KEY="any string" \
python manage.py collectstatic
SETUP_ES="False" \
STATIC_ROOT="/static" \
DJANGO_SECRET_KEY="any string" \
python manage.py collectstatic

# Add the release version to the docker container
ARG SEMANTIC_VERSION
Expand Down

0 comments on commit 69a87d7

Please sign in to comment.