diff --git a/.circleci/config.yml b/.circleci/config.yml index 7a99232e3..b3ef1aee7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,9 @@ version: 2.1 orbs: slack: circleci/slack@4.13.3 ms-teams: cloudradar-monitoring/ms-teams@0.0.1 +env: + DOCKER_REPO: opencti + GHCR_REPO: ghcr.io/OpenCTI-Platform/client-python jobs: ensure_formatting: docker: @@ -48,7 +51,43 @@ jobs: - ms-teams/report: only_on_fail: true webhook_url: $MS_TEAMS_WEBHOOK_URL - build: + + build-container: + executor: docker/docker + parameters: + python_version: + type: string + steps: + - checkout + - setup_remote_docker: + docker_layer_caching: true + - run: + name: Setup Docker Buildx + command: | + docker buildx create --driver docker-container --name multiarch --use + - run: + name: Login to Docker Hub + command: echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + - run: + name: Login to GitHub Container Registry + command: echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$GITHUB_USERNAME" --password-stdin + + - run: + name: Build and Push Alpine Multi-arch Image + command: | + VERSION=${CIRCLE_TAG:-latest} + PYTHON_VERSION_TAG=$(echo "<< parameters.python_version >>" | sed 's/\./-/g') + docker buildx build \ + --platform linux/amd64,linux/arm64 \ + --file Dockerfile.alpine \ + --tag ${{ env.DOCKER_REPO }}/client-python-${PYTHON_VERSION_TAG}:${VERSION} \ + --tag ${{ env.DOCKER_REPO }}/client-python-${PYTHON_VERSION_TAG}:latest \ + --tag ${{ env.GHCR_REPO }}/client-python-${PYTHON_VERSION_TAG}:${VERSION} \ + --tag ${{ env.GHCR_REPO }}/client-python-${PYTHON_VERSION_TAG}:latest \ + --push \ + --file Dockerfile + + build-library: working_directory: ~/opencti-client docker: - image: cimg/python:3.12 @@ -144,18 +183,26 @@ workflows: filters: tags: only: /.*/ - - build: + + - build-container: + matrix: + parameters: + python_version: ["3.11", "3.12"] + requires: + - build-library + filters: + tags: + only: /[0-9]+(\.[0-9]+)+(\.[0-9]+)?\.?(\w)*/ + + - build-library: filters: tags: only: /[0-9]+(\.[0-9]+)+(\.[0-9]+)?\.?(\w)*/ branches: ignore: /.*/ - requires: - - ensure_formatting - - linter - deploy: requires: - - build + - build-library filters: tags: only: /[0-9]+(\.[0-9]+)+(\.[0-9]+)?\.?(\w)*/ @@ -163,7 +210,7 @@ workflows: ignore: /.*/ - notify_rolling: requires: - - build + - build-library - notify: requires: - deploy diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..659fa505f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +ARG BASE_IMAGE="python:3.12-alpine3.20" +FROM ${BASE_IMAGE} + +# Install Python modules +COPY ./requirements.txt /opt/requirements.txt + +RUN apk --no-cache add git build-base libmagic libffi-dev && \ + pip3 install --no-cache-dir -r /opt/requirements.txt && \ + apk del git build-base && rm /opt/requirements.txt + +RUN adduser -D -g '' app +USER app \ No newline at end of file