Skip to content

Commit

Permalink
Merge pull request #3012 from MoralCode/backend-docker-builder
Browse files Browse the repository at this point in the history
[backend] refactor docker container to builder pattern
  • Loading branch information
sgoggins authored Mar 7, 2025
2 parents 9e93804 + ec0e139 commit cbd0fd6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 45 deletions.
54 changes: 36 additions & 18 deletions docker/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
# SPDX-License-Identifier: MIT


FROM golang:1.23 AS golang


# RUN ./scripts/docker/install-go.sh
ENV PATH="${PATH}:/usr/local/go/bin"
COPY ./scripts/ scripts/
RUN ./scripts/docker/install-golang-deps.sh


# FROM rust:1.78 as rust

# # Ensure Rust directories are writable
# RUN mkdir -p /root/.rustup/downloads /root/.cargo/registry && \
# chmod -R 777 /root/.rustup /root/.cargo

# # Add rust and cargo to PATH
# # ENV PATH="/root/.cargo/bin:${PATH}"

# # Install the specific version of Rust
# # RUN set -x \
# # && rustup install 1.78.0
# # RUN set -x \
# # && rustup default 1.78.0


# # Add rust and cargo to PATH
# ENV PATH="/usr/bin/:/root/.cargo/bin:/usr/local/bin:${PATH}"

FROM python:3.11-slim-bullseye

LABEL maintainer="[email protected]"
Expand All @@ -24,15 +54,12 @@ RUN set -x \
postgresql-client \
libpq-dev \
build-essential \
rustc \
cargo \
chromium \
tar \
jq \
chromium-driver \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
&& rm -rf /var/lib/apt/lists/*

# Install Firefox from Debian repositories for ARM64 architecture
RUN set -x \
Expand All @@ -58,18 +85,9 @@ RUN GECKODRIVER_VERSION=$(curl -s https://api.github.com/repos/mozilla/geckodriv
RUN firefox --version
RUN geckodriver --version

# Ensure Rust directories are writable
RUN mkdir -p /root/.rustup/downloads /root/.cargo/registry && \
chmod -R 777 /root/.rustup /root/.cargo

# Add rust and cargo to PATH
ENV PATH="/root/.cargo/bin:${PATH}"

# Install the specific version of Rust
RUN set -x \
&& rustup install 1.78.0
RUN set -x \
&& rustup default 1.78.0


EXPOSE 5000

Expand All @@ -82,8 +100,7 @@ COPY ./setup.py .
COPY ./scripts/ scripts/
COPY ./keyman/ keyman/

# Add rust and cargo to PATH
ENV PATH="/usr/bin/:/root/.cargo/bin:/usr/local/bin:${PATH}"


RUN python3 -m venv /opt/venv

Expand All @@ -101,10 +118,11 @@ RUN set -x \
&& /opt/venv/bin/pip install wheel \
&& /opt/venv/bin/pip install .

RUN ./scripts/docker/install-go.sh
ENV PATH="${PATH}:/usr/local/go/bin"
RUN ./scripts/docker/install-workers-deps.sh

COPY --from=golang "/root/scc" "./scc"
COPY --from=golang "/root/scorecard/scorecard" "./scorecard"

# RUN ./scripts/install/workers.sh

RUN mkdir -p repos/ logs/ /augur/facade/
Expand Down
29 changes: 29 additions & 0 deletions scripts/docker/install-golang-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -x

# Note this
CURRENT_DIR=$PWD;
# 18GB
# Install scc
SCC_DIR="$HOME/scc"
echo "Cloning Sloc Cloc and Code (SCC) to generate value data ..."
# this needs to be done from source. the latest version doesnt seem to exist on the package repo
# however, the latest version (v3.5.0) requires bumping the golang version in the Dockerfile
git clone --depth 1 --branch v3.4.0 https://github.com/boyter/scc "$SCC_DIR"
cd $SCC_DIR
go build;
echo "scc build done"
cd $CURRENT_DIR
# 18GB

# Install scorecard
SCORECARD_DIR="$HOME/scorecard"
echo "Cloning OSSF Scorecard to generate scorecard data ..."
# lock version to prevent future issues if the golang version is bumped
git clone --depth 1 --branch v5.1.1 https://github.com/ossf/scorecard $SCORECARD_DIR
cd $SCORECARD_DIR
go build;
echo "scorecard build done"
cd $CURRENT_DIR

# 16GB
27 changes: 0 additions & 27 deletions scripts/docker/install-workers-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,3 @@ do
/opt/venv/bin/pip install .
cd $OLD
done

# install nltk
# taken from ./scripts/install/nltk_dictionaries.sh
for i in stopwords punkt popular universal_tagset ; do
/opt/venv/bin/python -m nltk.downloader $i
done

# Note this
CURRENT_DIR=$PWD;

# Install scc
SCC_DIR="$HOME/scc"
echo "Cloning Sloc Cloc and Code (SCC) to generate value data ..."
git clone https://github.com/boyter/scc "$SCC_DIR"
cd $SCC_DIR
go build;
echo "scc build done"
cd $CURRENT_DIR

# Install scorecard
SCORECARD_DIR="$HOME/scorecard"
echo "Cloning OSSF Scorecard to generate scorecard data ..."
git clone https://github.com/ossf/scorecard $SCORECARD_DIR
cd $SCORECARD_DIR
go build;
echo "scorecard build done"
cd $CURRENT_DIR

0 comments on commit cbd0fd6

Please sign in to comment.