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

[CIRCLECI] Dynamic-CI 💡 #3328

Merged
merged 124 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
4599ac7
First shot
Renizmy Jan 21, 2025
5a5940e
First shot
Renizmy Jan 21, 2025
306b90b
First shot
Renizmy Jan 21, 2025
18bc1b3
First shot
Renizmy Jan 21, 2025
0d387c9
First shot
Renizmy Jan 21, 2025
58b09b3
First shot
Renizmy Jan 21, 2025
67ace80
First shot
Renizmy Jan 21, 2025
ee00b3e
First shot
Renizmy Jan 21, 2025
cb1d418
First shot
Renizmy Jan 21, 2025
6631712
First shot
Renizmy Jan 21, 2025
c7b33e6
First shot
Renizmy Jan 21, 2025
286a4c2
First shot
Renizmy Jan 21, 2025
6b58e5c
First shot
Renizmy Jan 21, 2025
7b172d7
First shot
Renizmy Jan 21, 2025
16d9ffe
First shot
Renizmy Jan 21, 2025
f7f833c
First shot
Renizmy Jan 21, 2025
959f16e
First shot
Renizmy Jan 21, 2025
de5977c
First shot
Renizmy Jan 21, 2025
f41bf48
First shot
Renizmy Jan 21, 2025
2514301
First shot
Renizmy Jan 21, 2025
556206b
First shot
Renizmy Jan 21, 2025
19888f5
First shot
Renizmy Jan 21, 2025
9b35f2a
First shot
Renizmy Jan 21, 2025
3f095ab
First shot
Renizmy Jan 21, 2025
2941114
First shot
Renizmy Jan 21, 2025
dce6309
First shot
Renizmy Jan 21, 2025
1767249
First shot
Renizmy Jan 21, 2025
08299c7
First shot
Renizmy Jan 21, 2025
cbfaa7b
First shot
Renizmy Jan 21, 2025
fd001e2
First shot
Renizmy Jan 21, 2025
c323b1f
First shot
Renizmy Jan 21, 2025
a203408
First shot
Renizmy Jan 21, 2025
7daf0ec
First shot
Renizmy Jan 21, 2025
8bbfc5f
First shot
Renizmy Jan 21, 2025
e6dae63
Almost first shot
Renizmy Jan 21, 2025
071634d
Almost first shot
Renizmy Jan 21, 2025
3bf678b
Almost first shot
Renizmy Jan 21, 2025
7cee9be
Almost first shot
Renizmy Jan 21, 2025
57e3401
[ci] Update repository
helene-nguyen Jan 22, 2025
406dbde
[ci] Simplify ci for test
helene-nguyen Jan 22, 2025
6e5d922
[ci] Update linter
helene-nguyen Jan 22, 2025
f7c2d77
[ci] test without push
helene-nguyen Jan 22, 2025
e0f7f72
[ci] test without push
helene-nguyen Jan 22, 2025
d6d60d7
[ci] Test Remove platform for FIPS
helene-nguyen Jan 23, 2025
e8191b1
[ci] Add only arm for FIPS
helene-nguyen Jan 23, 2025
b45c5c5
[ci] Add builder for FIPS
helene-nguyen Jan 23, 2025
5c1b184
[ci] Add builder for FIPS
helene-nguyen Jan 23, 2025
12e998e
[ci] Add builder for FIPS
helene-nguyen Jan 23, 2025
7ae7cd3
[ci] Add builder for FIPS
helene-nguyen Jan 23, 2025
64f0248
[ci] Add builder for FIPS
helene-nguyen Jan 23, 2025
6a529bb
[ci] Test remove platform
helene-nguyen Jan 23, 2025
999ae95
[ci] Update Ironnet Docker file
helene-nguyen Jan 23, 2025
b92c5f1
[ci] Missing dot for FIPS
helene-nguyen Jan 23, 2025
5bb252f
[ci] try docker layer caching
helene-nguyen Jan 24, 2025
40dfc29
[ci] Check image inspection + caching works or not
helene-nguyen Jan 24, 2025
3a0fad3
[ci] Check tags + custom builder per connector
helene-nguyen Jan 24, 2025
e0f18cd
[ci] add echo
helene-nguyen Jan 24, 2025
f8075c4
[ci] Fix issue template
helene-nguyen Jan 24, 2025
d6661b8
[ci] correct template
helene-nguyen Jan 24, 2025
a6c1c4d
[ci] correct template
helene-nguyen Jan 24, 2025
6ce1a0d
[ci] correct template
helene-nguyen Jan 24, 2025
f4f6edd
[ci] correct template
helene-nguyen Jan 24, 2025
238e638
[ci] correct template
helene-nguyen Jan 24, 2025
9c12353
[ci] correct template
helene-nguyen Jan 24, 2025
49ed960
[ci] correct template
helene-nguyen Jan 24, 2025
af58dce
[ci] correct template
helene-nguyen Jan 24, 2025
7ca64ba
[ci] correct template
helene-nguyen Jan 24, 2025
b987c5b
[ci] correct template
helene-nguyen Jan 24, 2025
af9e508
[ci] correct template
helene-nguyen Jan 24, 2025
9063b56
[ci] correct template
helene-nguyen Jan 24, 2025
3f035da
[ci] correct template
helene-nguyen Jan 24, 2025
465ab9b
[ci] correct template
helene-nguyen Jan 24, 2025
5476bda
[ci] correct template
helene-nguyen Jan 24, 2025
c611da4
[ci] correct template
helene-nguyen Jan 24, 2025
e3c216e
[ci] correct template
helene-nguyen Jan 24, 2025
a2ffeb0
[ci] correct template
helene-nguyen Jan 24, 2025
02058a8
[ci] correct template
helene-nguyen Jan 24, 2025
29cc8fe
[ci] correct template
helene-nguyen Jan 24, 2025
e8af042
[ci] correct template
helene-nguyen Jan 24, 2025
77eb6f1
[ci] Test replace default tags
helene-nguyen Jan 24, 2025
c51e7ae
[ci] Test replace default tags
helene-nguyen Jan 24, 2025
69daac6
[ci] Trigger on specific branch
helene-nguyen Jan 24, 2025
e0386e5
[ci] Trigger on specific branch
helene-nguyen Jan 24, 2025
b8797ae
[ci] adapt Dockerfile + change logic build when rolling
helene-nguyen Jan 27, 2025
54efc75
[ci] adapt Dockerfile + change logic build when rolling
helene-nguyen Jan 27, 2025
afbd3fe
[ci] remove filters for test + lint
helene-nguyen Jan 27, 2025
d4329a6
[ci] Tests with executor for build + remove filter
helene-nguyen Jan 27, 2025
fd1bcff
[ci] Tests with executor for build + remove filter
helene-nguyen Jan 27, 2025
39407d1
[ci] Tests with executor for build + remove filter
helene-nguyen Jan 27, 2025
e4b1551
[ci] Tests with executor for build + remove filter + remove requires …
helene-nguyen Jan 27, 2025
d6a76d8
[ci] Tests with executor for build + remove filter + remove requires …
helene-nguyen Jan 27, 2025
278521a
[ci] change version + add condition for filtering release
helene-nguyen Jan 28, 2025
77d79c2
[ci] remove requires for tests
helene-nguyen Jan 28, 2025
2da8422
[ci] test release version + filters by tag
helene-nguyen Jan 28, 2025
6b5eb2f
[ci] remove condition
helene-nguyen Jan 28, 2025
eb452e1
[ci] Update jobs
helene-nguyen Jan 28, 2025
ef8f2ad
[ci] Test filters on tag only
helene-nguyen Jan 28, 2025
54b443c
[ci] Test filters on tag only
helene-nguyen Jan 28, 2025
17935f8
[ci] change order of filters
helene-nguyen Jan 28, 2025
7ff8d06
[ci] Test condition again
helene-nguyen Jan 28, 2025
0070491
[ci] Test to run latest tag
helene-nguyen Jan 28, 2025
9222980
[ci] remove notify for tests
helene-nguyen Jan 28, 2025
857da62
[ci] Test pre release tag
helene-nguyen Jan 28, 2025
6325ca8
[ci] test prerelease + notifications
helene-nguyen Jan 28, 2025
012b048
[ci] test prerelease + notifications
helene-nguyen Jan 28, 2025
87f7a6d
[ci] test prerelease + notifications
helene-nguyen Jan 28, 2025
f456261
[ci] test prerelease + notifications
helene-nguyen Jan 28, 2025
d307cd0
[ci] test prerelease + notifications
helene-nguyen Jan 28, 2025
307bc42
[ci] Test prerelease with tag circle branch
helene-nguyen Jan 28, 2025
276d5d4
[ci] Test prerelease with tag circle branch
helene-nguyen Jan 28, 2025
e6bf8ee
[ci] test complete on Pr, no build have to be triggered
helene-nguyen Jan 28, 2025
fb20a99
[ci] rename builds
helene-nguyen Jan 28, 2025
64fd509
[ci] rename builds
helene-nguyen Jan 28, 2025
735d52e
[ci] add ghcr push
helene-nguyen Jan 29, 2025
3e500fa
[ci] test push images rolling in both registries + remove notif
helene-nguyen Jan 30, 2025
d041ec3
[ci] test push images rolling in both registries + remove notif
helene-nguyen Jan 30, 2025
6902d90
[ci] remove --load as with --push it does not work
helene-nguyen Jan 30, 2025
a141d9a
[ci] Last one, remove comments template + add correct filters
helene-nguyen Jan 30, 2025
1112b04
[ci] Update .circleci/vars.yml
helene-nguyen Jan 30, 2025
fbc166f
[ci] Update .circleci/scripts/generate_ci.py
helene-nguyen Jan 30, 2025
8434599
[ci] Update .circleci/scripts/generate_ci.py
helene-nguyen Jan 30, 2025
f358592
[ci] Update .circleci/scripts/generate_ci.py
helene-nguyen Jan 30, 2025
237b385
[ci] update
helene-nguyen Jan 30, 2025
38310dd
[ci] uncomment notifications
helene-nguyen Jan 30, 2025
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
2,190 changes: 87 additions & 2,103 deletions .circleci/config.yml

Large diffs are not rendered by default.

118 changes: 118 additions & 0 deletions .circleci/scripts/generate_ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import os

import yaml
from jinja2 import Template

# Define the top-level directories
TOP_LEVEL_DIRS = [
"external-import",
"internal-enrichment",
"internal-export-file",
"internal-import-file",
"stream",
]

CI_DIR = ".circleci"
TEMPLATE_DIR = f"{CI_DIR}/templates"
TEMPLATE_PATH = f"{TEMPLATE_DIR}/dynamic.yml.j2"
VARS_PATH = f"{CI_DIR}/vars.yml"

REPOSITORY = "opencti"


def get_dirs() -> dir:
# Collect subdirectories for each top-level directory
dirs = {}
for top_dir in TOP_LEVEL_DIRS:
if os.path.exists(top_dir):
dirs[top_dir] = [
sub_dir
for sub_dir in os.listdir(top_dir)
if os.path.isdir(os.path.join(top_dir, sub_dir))
]
return dirs
helene-nguyen marked this conversation as resolved.
Show resolved Hide resolved


# Load the Jinja template
def get_parameters() -> dict:
helene-nguyen marked this conversation as resolved.
Show resolved Hide resolved
"""Load the parameters contained in a yaml file

The loaded dictionary describes image-specific details that deviate from the default case.
{
"images":
{
<name_of_the_image>:
{
"python" : specific python version
"fips": boolean to tell the pipeline to build an image with "fips" tag
},
...
}
}
"""

with open(f"{CI_DIR}/vars.yml", "r") as yaml_file:
return yaml.safe_load(yaml_file)


def get_template() -> Template:
with open(TEMPLATE_PATH, "r") as template_file:
return Template(template_file.read())


def get_pycti() -> dict:
helene-nguyen marked this conversation as resolved.
Show resolved Hide resolved
"""
Retrieve the pycti configuration, including its version and whether it should be replaced.

This function checks the environment for a `CIRCLE_TAG` variable to determine the pycti version.
`CIRCLE_TAG` only exists when release is done

If 'replace' flag is set to true, we will pull the pycti dependency from a specific branch rather than from the pypi registry

:return: pycti version
"""
pycti = {"version": os.getenv("CIRCLE_TAG")}
if pycti["version"]:
pycti["replace"] = False
else:
pycti["replace"] = True
return pycti


def get_tags() -> list[str]:
data = []
tags = os.getenv("BUILD_TAGS")
if tags:
data.extend(tags.split(","))

circle_tag = os.getenv("CIRCLE_TAG")
if circle_tag:
data.append(circle_tag)
if len(data) == 0:
print("[ERROR]: At least 1 tag is required")
exit(1)
return data


# Write the generated config to a CircleCI configuration file
def write_config(template):
output_path = "dynamic.yml"
with open(output_path, "w") as file:
file.write(template)
print(f"Generated CircleCI config at {output_path}")


def main():
template = get_template()
config = template.render(
dirs=get_dirs(),
param=get_parameters(),
pycti=get_pycti(),
tags=get_tags(),
repo=REPOSITORY,
)
write_config(config)


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions .circleci/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Jinja2==3.1.2
PyYAML==6.0.1
requests==2.32.3
66 changes: 66 additions & 0 deletions .circleci/templates/dynamic.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: 2.1

jobs:
{% for top_dir, sub_dirs in dirs.items() -%}
{% for sub_dir in sub_dirs %}
build_{{top_dir}}_{{sub_dir}}:
docker:
- image: cimg/base:stable-20.04
steps:
- checkout
- setup_remote_docker
- run:
name: Build {{top_dir}}/{{sub_dir}}
command: |
echo "Processing {{top_dir}}/{{sub_dir}}"
cd {{top_dir}}/{{sub_dir}}
docker run --privileged --rm tonistiigi/binfmt --install linux/amd64,linux/arm64
CIRCLE_TAG=${CIRCLE_TAG:-latest}
docker buildx create --use --name builder-connector-{{sub_dir}}
docker buildx inspect builder-connector-{{sub_dir}} --bootstrap
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
echo "$GHCR_PASS" | docker login ghcr.io -u "$GHCR_USERNAME" --password-stdin
{% set image_key = top_dir ~ '_' ~ sub_dir -%}

{% if param['images'][image_key] is defined -%}
base_image="{{repo}}/client-python-{{param['images'][image_key].python}}:{{version}}"
{% else -%}
base_image="{{repo}}/client-python-3-12:{{version}}"
{% endif -%}

{% if pycti.replace -%}
{% if "prerelease" in tags %}
find . -name requirements.txt -exec sed 's|^pycti==.*$|pycti @ git+https://github.com/OpenCTI-Platform/client-python@$CIRCLE_BRANCH|' -i {} \;
{% elif "rolling" in tags %}
find . -name requirements.txt -exec sed 's|^pycti==.*$|pycti @ git+https://github.com/OpenCTI-Platform/client-python@master|' -i {} \;
{% endif %}
{% endif -%}
docker buildx build . \
{% for tag in tags -%}
--tag {{repo}}/connector-{{sub_dir}}:{{tag}} \
--tag ghcr.io/opencti-platform/{{repo}}/connector-{{sub_dir}}:{{tag}} \
{% endfor -%}
--build-arg BASE_IMAGE=$base_image \
--push

{% if param['images'][image_key] is defined and param['images'][image_key]['fips'] == true -%}
docker buildx build -f Dockerfile_fips . \
{% for tag in tags -%}
--tag {{repo}}/connector-{{sub_dir}}:{{tag}}-fips \
--tag ghcr.io/opencti-platform/{{repo}}/connector-{{sub_dir}}:{{tag}}-fips \
{% endfor -%}
--build-arg BASE_IMAGE=$base_image \
--push
{% endif -%}

{% endfor %}
{% endfor %}
workflows:
version: 2.1
build_connectors:
jobs:
{%- for top_dir, sub_dirs in dirs.items() -%}
{%- for sub_dir in sub_dirs %}
- build_{{top_dir}}_{{sub_dir}}
{%- endfor -%}
{% endfor-%}
29 changes: 29 additions & 0 deletions .circleci/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# List of images with a different configuration than the default one
# default is a base python image 3.12, built with tag "rolling" or release semantic version
images:
helene-nguyen marked this conversation as resolved.
Show resolved Hide resolved
stream_webhook:
python: python3-11
stream_qradar:
python: python3-11
stream_splunk:
python: python3-11
stream_sentinel-intel:
python: python3-11
stream_sentinel:
python: python3-11
stream_harfanglab-intel:
python: python3-11
stream_harfanglab:
python: python3-11
external-import_harfanglab-incidents:
python: python3-11
internal-import-file_import-file-stix:
fips: true
internal-import-file_import-document:
fips: true
internal-export-file_export-file-stix:
fips: true
internal-export-file_export-file-csv:
fips: true
internal-export-file_export-file-txt:
fips: true
8 changes: 5 additions & 3 deletions external-import/ironnet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ COPY src /opt/opencti-connector-ironnet

# Install Python modules
# hadolint ignore=DL3003
RUN apk --no-cache add git build-base libmagic libffi-dev && \
cd /opt/opencti-connector-ironnet && \
RUN apk update && apk upgrade && \
apk --no-cache add git build-base libmagic libffi-dev libxml2-dev libxslt-dev

RUN cd /opt/opencti-connector-ironnet && \
pip3 install --no-cache-dir -r requirements.txt && \
apk del git build-base

# Expose and entrypoint
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]
6 changes: 4 additions & 2 deletions external-import/sentinelone-threats/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ COPY src /opt/opencti-connector-sentinelone-threats

# Install Python modules
# hadolint ignore=DL3003
RUN apk --no-cache add git build-base libmagic libffi-dev && \
cd /opt/opencti-connector-sentinelone-threats && \
RUN apk update && apk upgrade && \
apk --no-cache add git build-base libmagic libffi-dev libxml2-dev libxslt-dev

RUN cd /opt/opencti-connector-sentinelone-threats && \
pip3 install --no-cache-dir -r requirements.txt && \
apk del git build-base

Expand Down