Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix API image builds #2410

Merged
merged 3 commits into from
Jun 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering why this is needed here 😶

python manage.py collectstatic

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