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

Improve dockerization #2947

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: |
ls -l
docker build . --file docker/backend/Dockerfile --tag my-image-name:$(date +%s)
run: docker build . --file docker/backend/Dockerfile --tag my-image-name:$(date +%s)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Current maintainers
- `Isaac Milarsky <https://github.com/IsaacMilarky>`_
- `John McGinnis <https://github.com/Ulincys>`_
- `Sean P. Goggins <https://github.com/sgoggins>`_
- `Mbaoma Mary <https://github.com/Mbaoma>`_

Former maintainers
--------------------
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#SPDX-License-Identifier: MIT
version: '3'
services:
augur-db:
image: postgres:16
Expand Down
8 changes: 8 additions & 0 deletions docker/backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.log
*.pyc
__pycache__/
.env
.git
node_modules/
dist/
venv/
142 changes: 63 additions & 79 deletions docker/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,116 +1,100 @@
# SPDX-License-Identifier: MIT
FROM python:3.11-slim-bullseye
# Stage 1: Builder
FROM python:3.11-slim-bullseye AS builder

LABEL maintainer="[email protected]"
LABEL version="0.76.6"

ENV DEBIAN_FRONTEND=noninteractive
ENV PATH="/usr/bin/:/usr/local/bin:/usr/lib:${PATH}"

RUN set -x \
&& apt-get update \
&& apt-get -y install \
# Install build dependencies
RUN apt-get update && apt-get -y install \
git \
bash \
curl \
gcc \
software-properties-common \
postgresql-contrib \
musl-dev \
python3-dev \
python3-distutils \
python3-venv \
wget \
curl \
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

# Install Firefox from Debian repositories for ARM64 architecture
RUN set -x \
&& apt-get update \
&& apt-get install -y firefox-esr

# Install Geckodriver
RUN GECKODRIVER_VERSION=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest | jq -r '.tag_name' | sed 's/v//') \
&& ARCH=$(uname -m) \
&& if [ "$ARCH" = "aarch64" ]; then \
GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/v${GECKODRIVER_VERSION}/geckodriver-v${GECKODRIVER_VERSION}-linux-aarch64.tar.gz"; \
GECKODRIVER_FILE="geckodriver-v${GECKODRIVER_VERSION}-linux-aarch64.tar.gz"; \
else \
GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/v${GECKODRIVER_VERSION}/geckodriver-v${GECKODRIVER_VERSION}-linux64.tar.gz"; \
GECKODRIVER_FILE="geckodriver-v${GECKODRIVER_VERSION}-linux64.tar.gz"; \
fi \
&& wget $GECKODRIVER_URL \
&& tar -xzf $GECKODRIVER_FILE \
&& mv geckodriver /usr/local/bin/ \
&& rm $GECKODRIVER_FILE

# Verify installations
RUN firefox --version
RUN geckodriver --version
&& rm -rf /var/lib/apt/lists/*

# Ensure Rust directories are writable
RUN mkdir -p /root/.rustup/downloads /root/.cargo/registry && \
chmod -R 777 /root/.rustup /root/.cargo
# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

# Add rust and cargo to PATH
# Add cargo and rustup 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
# Install specific version of Rust
RUN rustup install 1.78.0 && rustup default 1.78.0

EXPOSE 5000
# Create virtual environment
RUN python3 -m venv /opt/venv
RUN /opt/venv/bin/pip install --upgrade pip wheel

# Copy application code
WORKDIR /augur
COPY ./README.md .
COPY ./alembic.ini .
COPY ./augur/ augur/
COPY ./metadata.py .
COPY ./setup.py .
COPY ./scripts/ scripts/
COPY ./alembic.ini .
COPY ./metadata.py .
COPY ./augur/ augur/
COPY ./README.md .

# Add rust and cargo to PATH
ENV PATH="/usr/bin/:/root/.cargo/bin:/usr/local/bin:${PATH}"
# Install application dependencies
RUN /opt/venv/bin/pip install .

RUN python3 -m venv /opt/venv
# Stage 2: Runtime
FROM python:3.11-slim-bullseye AS runtime

RUN set -x \
&& /opt/venv/bin/pip install --upgrade pip
LABEL maintainer="[email protected]"
LABEL version="0.76.5"

RUN set -x \
&& /opt/venv/bin/pip install wheel

RUN set -x \
&& /opt/venv/bin/pip install .
# Install runtime dependencies, including jq, curl, and wget
RUN apt-get update && apt-get install -y \
postgresql-client \
firefox-esr \
chromium \
tar \
chromium-driver \
jq \
wget \
curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN set -x \
&& /opt/venv/bin/pip install --upgrade pip \
&& /opt/venv/bin/pip install wheel \
&& /opt/venv/bin/pip install .
# Install Geckodriver
RUN GECKODRIVER_VERSION=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest | jq -r '.tag_name' | sed 's/v//') \
&& ARCH=$(uname -m) \
&& if [ "$ARCH" = "aarch64" ]; then \
GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/v${GECKODRIVER_VERSION}/geckodriver-v${GECKODRIVER_VERSION}-linux-aarch64.tar.gz"; \
else \
GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/v${GECKODRIVER_VERSION}/geckodriver-v${GECKODRIVER_VERSION}-linux64.tar.gz"; \
fi \
&& wget $GECKODRIVER_URL \
&& tar -xzf geckodriver-v${GECKODRIVER_VERSION}-linux*.tar.gz \
&& mv geckodriver /usr/local/bin/ \
&& rm geckodriver-v${GECKODRIVER_VERSION}-linux*.tar.gz

RUN ./scripts/docker/install-go.sh
ENV PATH="${PATH}:/usr/local/go/bin"
RUN ./scripts/docker/install-workers-deps.sh
# Copy virtual environment and application code from builder
COPY --from=builder /opt/venv /opt/venv
COPY --from=builder /augur /augur

# RUN ./scripts/install/workers.sh
# Execute the install-workers-deps.sh script here
RUN chmod +x /augur/scripts/docker/install-workers-deps.sh /augur/scripts/docker/install-go.sh
RUN ./augur/scripts/docker/install-workers-deps.sh
RUN ./augur/scripts/docker/install-go.sh

RUN mkdir -p repos/ logs/ /augur/facade/
RUN mkdir -p /augur/facade/ repos/ logs/

COPY ./docker/backend/entrypoint.sh /
COPY ./docker/backend/init.sh /
RUN chmod +x /entrypoint.sh /init.sh

# Set the environment
ENV PATH="/opt/venv/bin:/root/.cargo/bin:${PATH}"

EXPOSE 5000
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
#ENTRYPOINT ["/entrypoint.sh"]
CMD /init.sh
CMD ["/init.sh"]
2 changes: 1 addition & 1 deletion docker/backend/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fi


if [ ! -v AUGUR_NO_CONFIG ]; then
./scripts/install/config.sh docker
./augur/scripts/install/config.sh docker
fi

if [[ -f /repo_groups.csv ]]; then
Expand Down
2 changes: 1 addition & 1 deletion environment.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AUGUR_GITHUB_API_KEY=<PUT YOUR GITHUB API KEY HERE>
AUGUR_GITHUB_USERNAME=<PUT YOUR GITHUB USERNAME HERE>
AUGUR_GITHUB_USERNAME=Mbaoma
AUGUR_GITLAB_API_KEY=<PUT YOUR GITLAB KEY HERE>
AUGUR_GITLAB_USERNAME=<PUT YOUR GITLAB USERNAME HERE>
AUGUR_DB=<PUT YOUR DATABASE CONNECTION STRING HERE>
Expand Down
25 changes: 2 additions & 23 deletions scripts/docker/install-workers-deps.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
set -x

OLD=$(pwd)
for i in $(find . | grep -i setup.py);
do

cd $(dirname $i)
/opt/venv/bin/pip install .
cd $OLD
Expand All @@ -13,25 +13,4 @@ done
# 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
done
Loading