Skip to content

Commit

Permalink
Merge pull request #894 from arkid15r/update-docker-image
Browse files Browse the repository at this point in the history
Optimize docker image
  • Loading branch information
securestep9 authored Sep 8, 2024
2 parents 008d673 + 10eb61a commit 51b8c9f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 16 deletions.
51 changes: 49 additions & 2 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ concurrency:
group: ${{ github.repository }}-${{ github.workflow }}-${{ github.head_ref || github.ref_name }}

jobs:
# Code quality checks.
pre-commit:
name: Run pre-commit
runs-on: ubuntu-latest
Expand Down Expand Up @@ -51,6 +52,7 @@ jobs:
with:
category: /language:${{ matrix.language }}

# Code tests.
run-tests:
name: Run tests
needs:
Expand Down Expand Up @@ -90,8 +92,7 @@ jobs:

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade poetry
python -m pip install --upgrade pip poetry
poetry install
- name: Build package
Expand Down Expand Up @@ -138,6 +139,7 @@ jobs:
python -m pip install dist/*.tar.gz
nettacker --version
# Docker related jobs.
test-docker-image:
name: Test Docker image
needs:
Expand Down Expand Up @@ -194,6 +196,49 @@ jobs:
poetry run python nettacker.py -i 127.0.0.1 -L fa -u user1,user2 -p pass1,pass2 --profile all \
-g 21,25,80,443 -t 1000 -T 3 --graph d3_tree_v2_graph -v --skip-service-discovery
test-docker-image-build:
name: Test Docker ${{ matrix.docker-version }} image build
needs:
- run-tests
runs-on: ubuntu-latest
strategy:
matrix:
docker-version:
- '24.0.6-1~ubuntu.22.04~jammy'
- '23.0.6-1~ubuntu.22.04~jammy'
- '20.10.13~3-0~ubuntu-jammy'
steps:
- name: Uninstall pre-installed Docker
run: |
sudo apt-get remove docker-ce docker-ce-cli
# https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository
- name: Install Docker ${{ matrix.docker-version }}
run: |
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce=5:${{ matrix.docker-version }} docker-ce-cli=5:${{ matrix.docker-version }}
- name: Check out repository
uses: actions/checkout@v4

- name: Print Docker version
run: docker -v

- name: Build Nettacker image
run: docker build . -t nettacker

- name: Run pip install
run: docker run nettacker pip install .

publish-nettacker-dev-to-docker-registry:
name: Publish nettacker:dev Docker image
if: |
Expand All @@ -202,6 +247,7 @@ jobs:
github.ref_name == 'master'
needs:
- test-docker-image
- test-docker-image-build
runs-on: ubuntu-latest
steps:
- name: Check out repository
Expand Down Expand Up @@ -232,6 +278,7 @@ jobs:
startsWith(github.event.ref, 'refs/tags/v')
needs:
- test-docker-image
- test-docker-image-build
runs-on: ubuntu-latest
steps:
- name: Check out repository
Expand Down
23 changes: 16 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
FROM python:3.11.9-slim
RUN apt update

RUN mkdir -p .data/results && \
apt-get update && \
apt-get install -y gcc libssl-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
pip install --upgrade pip poetry

WORKDIR /usr/src/owaspnettacker
COPY . .
RUN mkdir -p .data/results
RUN apt-get update
RUN apt-get install -y gcc libssl-dev
RUN pip3 install --upgrade poetry
RUN python -m poetry install

COPY .data .data
COPY nettacker nettacker
COPY nettacker.py poetry.lock pyproject.toml README.md ./

RUN poetry install --no-root --without dev --without test

ENV docker_env=true

CMD [ "poetry", "run", "python", "./nettacker.py" ]
13 changes: 6 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
version: "3"

services:
nettacker:
build:
context: .
dockerfile: "Dockerfile"
command: poetry run python nettacker.py --start-api --api-host 0.0.0.0
dockerfile: Dockerfile
command: poetry run python ./nettacker.py --start-api --api-host 0.0.0.0
container_name: nettacker
environment:
- docker_env=true
ports:
- 5000:5000
volumes:
- ./:/usr/src/owaspnettacker
environment:
- docker_env=true
- ./nettacker:/usr/src/owaspnettacker/nettacker

0 comments on commit 51b8c9f

Please sign in to comment.