Skip to content

Commit d81c62c

Browse files
gqvzCopilot
andauthored
Add docker layer caching (intelowlproject#3318) (intelowlproject#3358)
* feat: optimize Dockerfile and add build caching for CI * Update .github/workflows/docker-build-cache.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update .github/workflows/pull_request_automation.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove cache-to settings from Docker build steps Removed cache-to configuration for Docker builds. * Add django-server-requirements.txt to Dockerfile * Add cache mounts for npm, apt, and pip installations * Use registry cache * Remove bake * Discard changes to start --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8f1051f commit d81c62c

4 files changed

Lines changed: 73 additions & 11 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
permissions:
2+
contents: read
3+
packages: write
4+
5+
name: Docker Build Cache
6+
7+
on:
8+
push:
9+
branches: [develop]
10+
paths-ignore:
11+
- "**.md"
12+
- "docs/**"
13+
- "integrations/**"
14+
15+
jobs:
16+
build-main-image:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout IntelOwl
21+
uses: actions/checkout@v6.0.2
22+
23+
- name: Set image repo
24+
run: echo "IMAGE_REPO=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
25+
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
29+
- name: Login to GHCR
30+
uses: docker/login-action@v3
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Build main image and push cache
37+
uses: docker/build-push-action@v6
38+
with:
39+
context: .
40+
file: docker/Dockerfile
41+
push: false
42+
build-args: |
43+
REPO_DOWNLOADER_ENABLED=false
44+
cache-from: type=registry,ref=${{ env.IMAGE_REPO }}:cache-main
45+
cache-to: type=registry,ref=${{ env.IMAGE_REPO }}:cache-main,mode=max

.github/workflows/pull_request_automation.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ jobs:
7676
cp docker/env_file_app_template docker/env_file_app
7777
cp docker/env_file_postgres_template docker/env_file_postgres
7878
79+
- name: Set image repo
80+
run: echo "IMAGE_REPO=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
81+
82+
- name: Login to GHCR
83+
uses: docker/login-action@v3
84+
with:
85+
registry: ghcr.io
86+
username: ${{ github.actor }}
87+
password: ${{ secrets.GITHUB_TOKEN }}
88+
7989
- name: Startup script launch (Slow)
8090
if: contains(github.base_ref, 'master')
8191
run: |
@@ -96,7 +106,7 @@ jobs:
96106
BUILDKIT_PROGRESS: "plain"
97107
STAGE: "ci"
98108
REPO_DOWNLOADER_ENABLED: false
99-
109+
100110
- name: Docker debug
101111
if: always()
102112
run: |
@@ -154,4 +164,4 @@ jobs:
154164
- name: Test with Jest
155165
run: |
156166
npm run test -- --silent --coverage
157-
working-directory: ./frontend
167+
working-directory: ./frontend

docker/Dockerfile

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
FROM node:lts-alpine3.21 AS frontend-build
44

55
WORKDIR /
6+
7+
COPY frontend/package.json frontend/package-lock.json ./
8+
RUN npm install npm@11.11.0 --location=global && npm install
9+
610
# copy react source code
711
COPY frontend/ .
812
# copy version file as an env file
913
COPY docker/.env .env.local
10-
# install and build
11-
RUN npm install npm@latest --location=global \
12-
&& npm install \
13-
&& PUBLIC_URL=/static/reactapp/ npm run build
14+
RUN PUBLIC_URL=/static/reactapp/ npm run build
1415

1516
# Stage 2: Backend
1617
FROM python:3.11.7 AS backend-build
@@ -49,13 +50,15 @@ RUN apt-get update \
4950

5051
COPY requirements/project-requirements.txt $PYTHONPATH/project-requirements.txt
5152
COPY requirements/certego-requirements.txt $PYTHONPATH/certego-requirements.txt
53+
COPY requirements/django-server-requirements.txt $PYTHONPATH/requirements/django-server-requirements.txt
5254
WORKDIR $PYTHONPATH
5355

5456
RUN pip3 install --no-cache-dir --use-pep517 --compile -r project-requirements.txt \
5557
&& pip3 install --no-cache-dir pycti==${PYCTI_VERSION} \
5658
&& pip3 install --no-cache-dir --compile -r certego-requirements.txt
5759

58-
COPY . $PYTHONPATH
60+
COPY api_app/analyzers_manager/repo_downloader.sh ${PYTHONPATH}/api_app/analyzers_manager/repo_downloader.sh
61+
COPY docker/scripts/watchman_install.sh ${PYTHONPATH}/docker/scripts/watchman_install.sh
5962

6063
RUN touch ${LOG_PATH}/django/api_app.log ${LOG_PATH}/django/api_app_errors.log \
6164
&& touch ${LOG_PATH}/django/intel_owl.log ${LOG_PATH}/django/intel_owl_errors.log \
@@ -65,10 +68,12 @@ RUN touch ${LOG_PATH}/django/api_app.log ${LOG_PATH}/django/api_app_errors.log \
6568
&& touch ${LOG_PATH}/django/authentication.log ${LOG_PATH}/django/authentication_errors.log \
6669
&& touch ${LOG_PATH}/asgi/daphne.log \
6770
&& mkdir -p -m 755 ${PYTHONPATH}/.cache \
68-
&& chown -R www-data:www-data ${LOG_PATH} /opt/deploy/ ${PYTHONPATH}/.cache \
69-
&& ${PYTHONPATH}/docker/scripts/watchman_install.sh \
70-
# download github stuff
71-
&& ${PYTHONPATH}/api_app/analyzers_manager/repo_downloader.sh
71+
&& ${PYTHONPATH}/api_app/analyzers_manager/repo_downloader.sh \
72+
&& ${PYTHONPATH}/docker/scripts/watchman_install.sh
73+
74+
COPY . $PYTHONPATH
75+
76+
RUN chown -R www-data:www-data ${LOG_PATH} /opt/deploy/ ${PYTHONPATH}/.cache
7277

7378
FROM backend-build
7479

docker/ci.override.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ services:
1414
dockerfile: docker/Dockerfile
1515
args:
1616
REPO_DOWNLOADER_ENABLED: ${REPO_DOWNLOADER_ENABLED}
17+
cache_from:
18+
- type=registry,ref=${IMAGE_REPO:-ghcr.io/intelowlproject/intelowl}:cache-main
1719
image: intelowlproject/intelowl:ci
1820
env_file:
1921
- env_file_app_ci

0 commit comments

Comments
 (0)