Skip to content

Commit 097524c

Browse files
author
Thomas Franco
committed
Merge branch 'develop'
2 parents 6ef0aa1 + bdd2f4b commit 097524c

File tree

15 files changed

+309
-212
lines changed

15 files changed

+309
-212
lines changed

.github/actions/get_code_version/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ runs:
1818
run: |
1919
V=$(sbt -no-colors --error "print version" | awk 'END{print $1}')
2020
echo "app_version=$V"
21-
echo "app_version=$V" >> $GITHUB_OUTPUT
21+
echo "app_version=$V" >> $GITHUB_OUTPUT
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: build.docker.image.baselayer
2+
on:
3+
schedule:
4+
- cron: "19 2 * * *"
5+
pull_request:
6+
types:
7+
- labeled
8+
workflow_dispatch:
9+
workflow_call:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
build:
17+
permissions:
18+
actions: read
19+
contents: read
20+
packages: write
21+
runs-on: [ linux ]
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Generate full docker tags
29+
id: meta
30+
uses: docker/metadata-action@v4
31+
with:
32+
images: |
33+
name=${{ vars.SB_GHCR }}/cortex-baselayer
34+
tags: |
35+
type=raw,value=rolling
36+
labels: |
37+
org.opencontainers.image.title=cortex-baselayer
38+
org.opencontainers.image.description=baselayer for Cortex final docker image
39+
org.opencontainers.image.vendor=StrangeBee
40+
org.opencontainers.image.version=rolling
41+
42+
- name: Login to GitHub Container Registry
43+
uses: docker/login-action@v3
44+
with:
45+
registry: ghcr.io
46+
username: ${{ github.actor }}
47+
password: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: Build and push docker image
50+
uses: docker/build-push-action@v3
51+
id: push
52+
with:
53+
context: .
54+
file: baseLayer.Dockerfile
55+
push: true
56+
platforms: linux/amd64,linux/arm64
57+
tags: ${{ steps.meta.outputs.tags }}
58+
59+
notify:
60+
needs: [ build ]
61+
runs-on: [ ubuntu-latest ]
62+
if: failure()
63+
steps:
64+
- name: Slack notification
65+
uses: Gamesight/slack-workflow-status@master
66+
with:
67+
repo_token: ${{secrets.GITHUB_TOKEN}}
68+
slack_webhook_url: ${{secrets.SLACK_WEBHOOK_URL}}
69+
channel: "#ci-cortex"
70+
name: Cortex baselayer build
71+
include_commit_message: true
72+
include_jobs: true

.github/workflows/build.docker.yml

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
name: build.docker.image.dev
1+
name: build.docker.image.cortex
22
on:
33
pull_request:
44
types:
55
- labeled
66
workflow_dispatch:
7+
inputs:
8+
is_prod:
9+
description: "Publish docker image in dockerhub?"
10+
type: boolean
11+
default: false
712
workflow_call:
13+
inputs:
14+
is_prod:
15+
description: "Publish docker image in dockerhub?"
16+
type: boolean
17+
default: false
818
outputs:
919
image_id:
1020
description: "ImageId of the docker image"
@@ -19,7 +29,6 @@ on:
1929
description: "Version number of the Docker image"
2030
value: ${{ jobs.build.outputs.image_version }}
2131

22-
2332
concurrency:
2433
group: ${{ github.workflow }}-${{ github.ref }}
2534
cancel-in-progress: true
@@ -31,7 +40,7 @@ jobs:
3140
contents: write
3241
runs-on: [ self-hosted, linux, domain=sb ]
3342
outputs:
34-
image_version: ${{ steps.get_version.outputs.version }}
43+
image_version: ${{ steps.get_version.outputs.app_version }}
3544
steps:
3645
- uses: actions/checkout@v4
3746
- name: Set up Docker Buildx
@@ -54,6 +63,43 @@ jobs:
5463
image_metadata: ${{ steps.push.outputs.metadata }}
5564
image_version: ${{ needs.prepare.outputs.image_version }}
5665
steps:
66+
- name: Set up Python
67+
uses: actions/setup-python@v5
68+
with:
69+
python-version: "3.13"
70+
- name: echo version
71+
id: image_details
72+
run: |
73+
'''
74+
Following https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions
75+
SemVer should be used in EVERY project for standard usage of versions
76+
'''
77+
import os
78+
import re
79+
80+
image_details = {}
81+
82+
if '+' in os.getenv('IMAGE_VERSION'):
83+
image_details['build_version'] = os.getenv('IMAGE_VERSION').split('+')[1]
84+
85+
if '-' in os.getenv('IMAGE_VERSION'):
86+
image_details['prerelease_version'] = os.getenv('IMAGE_VERSION').split('-')[1].split('+')[0]
87+
88+
image_details['core_version'] = os.getenv('IMAGE_VERSION').split('-')[0].split('+')[0]
89+
90+
image_details['major_version'] = os.getenv('IMAGE_VERSION').split('.')[0]
91+
image_details['major_minor_version'] = re.search(r'(\d\.\d)', os.getenv('IMAGE_VERSION')).group()
92+
93+
with open(os.environ['GITHUB_OUTPUT'], 'a') as gho:
94+
print(f'image_details={image_details}', file=gho)
95+
env:
96+
IMAGE_VERSION: ${{ needs.prepare.outputs.image_version }}
97+
shell: python
98+
99+
- name: simply print python results
100+
run: |
101+
echo ${{ steps.image_details.outputs.image_details }}
102+
57103
- uses: actions/checkout@v4
58104

59105
- name: Set up Docker Buildx
@@ -78,38 +124,54 @@ jobs:
78124
- name: Build packages
79125
run: sbt Docker/stage
80126

81-
# I'm not really at ease with these tags
82-
# to me "latest" should be set manually, through a tag, for now
83-
# but further, it should "calculate" it, regarding the latest Docker image version available
84-
# for exemple if latest available is 3.2.0-1 and the sbt command returns 3.2.1-1,
85-
# then latest should apply
86-
# Moreover, the -1 is VERY important, because it increases with the number of builds:
87-
# - if a Docker image exists with tag 3.2.0-1, it should NOT be overidden but a new
88-
# 3.2.0-2 should be created, and the -1 cleaned up later
89-
#####
90-
# TODO: work on tagging
91-
#
92-
#
127+
- name: setup vault token
128+
if: inputs.is_prod
129+
run: echo "VAULT_TOKEN=$VAULT_TOKEN" >> $GITHUB_ENV
130+
131+
- name: Import prod secrets
132+
if: inputs.is_prod
133+
id: secrets_prod
134+
uses: hashicorp/[email protected]
135+
with:
136+
url: https://vault.service.infra.sb:8200
137+
token: ${{ env.VAULT_TOKEN }}
138+
tlsSkipVerify: true
139+
secrets: |
140+
infra/data/ci/dockerhub username | DOCKERHUB_USERNAME;
141+
infra/data/ci/dockerhub token | DOCKERHUB_TOKEN;
142+
93143
- name: Generate full docker tags
94144
id: meta
95145
uses: docker/metadata-action@v4
96146
with:
97147
images: |
98148
name=${{ vars.SB_GHCR }}/cortex
149+
name=thehiveproject/cortex,enable=${{ inputs.is_prod }}
99150
tags: |
100-
type=raw,value=devel
151+
type=raw,value=${{ fromJson(steps.image_details.outputs.image_details)['core_version'] }}
101152
type=raw,value=${{ needs.prepare.outputs.image_version }}
153+
type=raw,value=${{ fromJson(steps.image_details.outputs.image_details)['major_version'] }}
154+
type=raw,value=${{ fromJson(steps.image_details.outputs.image_details)['major_minor_version'] }}
102155
labels: |
103156
org.opencontainers.image.title=cortex
104-
org.opencontainers.image.description=a Powerful Observable Analysis and Active Response Engine
157+
org.opencontainers.image.description=A Powerful Observable Analysis and Active Response Engine
105158
org.opencontainers.image.vendor=StrangeBee
159+
org.opencontainers.image.version=${{ needs.prepare.outputs.image_version }}
160+
106161
- name: Login to GitHub Container Registry
107162
uses: docker/login-action@v3
108163
with:
109164
registry: ghcr.io
110165
username: ${{ github.actor }}
111166
password: ${{ secrets.GITHUB_TOKEN }}
112167

168+
- name: Login to GitHub Container Registry
169+
if: inputs.is_prod
170+
uses: docker/login-action@v3
171+
with:
172+
username: ${{ steps.secrets_prod.outputs.DOCKERHUB_USERNAME }}
173+
password: ${{ steps.secrets_prod.outputs.DOCKERHUB_TOKEN }}
174+
113175
- name: Build and push docker image
114176
uses: docker/build-push-action@v3
115177
id: push
@@ -118,3 +180,4 @@ jobs:
118180
push: true
119181
platforms: linux/amd64,linux/arm64
120182
tags: ${{ steps.meta.outputs.tags }}
183+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/deploy.nomad.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ on:
55
docker_image_version:
66
type: string
77
required: false
8-
description: "Docker image version to deploy (default 'devel')"
9-
default: 'devel'
8+
description: "Docker image version to deploy"
109
from_docker_hub:
1110
type: boolean
1211
required: false
@@ -20,7 +19,7 @@ on:
2019
# pull_request = pr-XXX
2120
# manual = vXXX
2221
env:
23-
deployment_version: ${{ github.event_name == 'pull_request' && format('{0}-{1}', 'pr', github.event.number) || format('{0}{1}', (inputs.docker_image_version != 'devel' && 'v' || ''), inputs.docker_image_version) }}
22+
deployment_version: ${{ github.event_name == 'pull_request' && format('{0}-{1}', 'pr', github.event.number) || format('{0}{1}', 'v', inputs.docker_image_version) }}
2423

2524
concurrency:
2625
group: ${{ github.workflow }}-${{ github.ref }}
@@ -77,7 +76,11 @@ jobs:
7776
- name: Deploy job using Nomad Pack
7877
id: run
7978
# We pass two different version variables: one for Docker pull, the other for Nomad services
80-
run: nomad-pack run -var from_docker_hub=${{ inputs.from_docker_hub }} -var docker_image_version=${{ inputs.docker_image_version || env.deployment_version }} -var service_version=${{ needs.prepare.outputs.expected_deployment_version }} ./deployment/nomad/packs/cortex
79+
run: |
80+
nomad-pack run -var from_docker_hub=${{ inputs.from_docker_hub }} \
81+
-var docker_image="${{ vars.SB_GHCR }}/cortex" \
82+
-var docker_image_version=${{ inputs.docker_image_version || env.deployment_version }} \
83+
-var service_version=${{ needs.prepare.outputs.expected_deployment_version }} ./deployment/nomad/packs/cortex
8184
env:
8285
NOMAD_ADDR: "http://10.30.4.180:4646"
8386
NOMAD_TOKEN: "${{ env.NOMAD_TOKEN }}"

.github/workflows/setup.fixtures.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77
inputs:
88
expected_deployment_version:
99
type: string
10-
required: false
11-
description: "Docker image version to deploy (default 'latest')"
12-
default: "latest"
10+
required: true
11+
description: "Docker image version to deploy"
1312
workflow_call:
1413
inputs:
1514
expected_deployment_version:
1615
type: string
17-
required: false
18-
description: "Docker image version to deploy (default 'latest')"
19-
default: "latest"
16+
required: true
17+
description: "Docker image version to deploy"
2018

2119
jobs:
2220
setup:

app/org/thp/cortex/services/K8sJobRunnerSrv.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package org.thp.cortex.services
22

33
import akka.actor.ActorSystem
4-
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimVolumeSourceBuilder
5-
import io.fabric8.kubernetes.api.model.batch.{JobBuilder => KJobBuilder}
4+
import io.fabric8.kubernetes.api.model.{PersistentVolumeClaimVolumeSourceBuilder, StatusDetails}
5+
import io.fabric8.kubernetes.api.model.batch.v1.{JobBuilder => KJobBuilder}
66
import io.fabric8.kubernetes.client.DefaultKubernetesClient
77
import org.thp.cortex.models._
88
import org.thp.cortex.util.FunctionalCondition._
99
import play.api.{Configuration, Logger}
1010

1111
import java.nio.file._
12+
import java.util
1213
import javax.inject.{Inject, Singleton}
1314
import scala.concurrent.duration.{DurationInt, FiniteDuration}
1415
import scala.jdk.CollectionConverters._
@@ -113,7 +114,7 @@ class K8sJobRunnerSrv(
113114
.build()
114115

115116
val execution = Try {
116-
val created_kjob = client.batch().jobs().create(kjob)
117+
val created_kjob = client.batch().v1().jobs().create(kjob)
117118
val created_env = created_kjob
118119
.getSpec.getTemplate.getSpec.getContainers.get(0)
119120
.getEnv.asScala
@@ -123,7 +124,7 @@ class K8sJobRunnerSrv(
123124
s" image : $dockerImage\n" +
124125
s" mount : pvc $persistentVolumeClaimName subdir $relativeJobDirectory as /job" +
125126
created_env.map(ev => s"\n env : ${ev.getName} = ${ev.getValue}").mkString)
126-
val ended_kjob = client.batch().jobs().withLabel("cortex-job-id", job.id)
127+
val ended_kjob = client.batch().v1().jobs().withLabel("cortex-job-id", job.id)
127128
.waitUntilCondition(x => Option(x).flatMap(j =>
128129
Option(j.getStatus).flatMap(s =>
129130
Some(s.getConditions.asScala.map(_.getType).exists(t =>
@@ -139,8 +140,8 @@ class K8sJobRunnerSrv(
139140
}
140141
// let's find the job by the attribute we know is fundamentally
141142
// unique, rather than one constructed from it
142-
val deleted = client.batch().jobs().withLabel("cortex-job-id", job.id).delete()
143-
if(deleted) {
143+
val deleted: util.List[StatusDetails] = client.batch().v1().jobs().withLabel("cortex-job-id", job.id).delete()
144+
if(!deleted.isEmpty) {
144145
logger.info(s"Deleted Kubernetes Job for job ${job.id}")
145146
} else {
146147
logger.info(s"While trying to delete Kubernetes Job for ${job.id}, the job was not found; this is OK")

baseLayer.Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM python:3.12.9-bookworm
2+
3+
LABEL MAINTAINER="TheHive Project <[email protected]>" repository="https://github.com/TheHive-Project/TheHive"
4+
ENV JAVA_HOME=/usr/lib/jvm/java-11-amazon-corretto
5+
RUN apt update && \
6+
apt upgrade -y && \
7+
apt install -y curl \
8+
gnupg && \
9+
curl -fL https://apt.corretto.aws/corretto.key | gpg --dearmor -o /usr/share/keyrings/corretto.gpg && \
10+
echo 'deb [signed-by=/usr/share/keyrings/corretto.gpg] https://apt.corretto.aws stable main' > /etc/apt/sources.list.d/corretto.list && \
11+
apt update && \
12+
apt install -y java-11-amazon-corretto-jdk && \
13+
curl -fsSL https://download.docker.com/linux/debian/gpg -o /usr/share/keyrings/docker.asc && \
14+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" > /etc/apt/sources.list.d/docker.list && \
15+
apt update && \
16+
apt install -y docker-ce \
17+
docker-ce-cli \
18+
containerd.io \
19+
docker-ce-rootless-extras \
20+
uidmap \
21+
iproute2 \
22+
fuse-overlayfs && \
23+
rm -rf /var/lib/apt/lists/* && \
24+
apt autoclean -y -q && \
25+
apt autoremove -y -q
26+
CMD ["bash"]

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Common._
1+
import Common.*
22

33
ThisBuild / scalaVersion := Dependencies.scalaVersion
44
ThisBuild / evictionErrorLevel := util.Level.Warn

0 commit comments

Comments
 (0)