Skip to content

Commit 99379b0

Browse files
author
alexandre.teilhet
committed
Merge branch 'develop'
2 parents b7576be + 8a323dd commit 99379b0

6 files changed

Lines changed: 88 additions & 18 deletions

File tree

.github/workflows/build.docker.yml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: build.docker.image.cortex
22
on:
3-
pull_request:
4-
types:
5-
- labeled
63
workflow_dispatch:
74
inputs:
85
is_prod:
@@ -15,6 +12,10 @@ on:
1512
description: "Publish docker image in dockerhub?"
1613
type: boolean
1714
default: false
15+
override_version:
16+
description: "Override version tag (e.g., pr-60 for pull requests)"
17+
type: string
18+
required: false
1819
outputs:
1920
image_id:
2021
description: "ImageId of the docker image"
@@ -49,7 +50,6 @@ jobs:
4950
id: get_version
5051

5152
build:
52-
if: ${{ github.event.label.name == 'docker:build' || github.event_name == 'workflow_dispatch' }}
5353
needs:
5454
- prepare
5555
permissions:
@@ -61,7 +61,7 @@ jobs:
6161
image_id: ${{ steps.push.outputs.imageid }}
6262
image_digest: ${{ steps.push.outputs.digest }}
6363
image_metadata: ${{ steps.push.outputs.metadata }}
64-
image_version: ${{ needs.prepare.outputs.image_version }}
64+
image_version: ${{ inputs.override_version || needs.prepare.outputs.image_version }}
6565
steps:
6666
- name: Set up Python
6767
uses: actions/setup-python@v5
@@ -140,8 +140,24 @@ jobs:
140140
infra/data/ci/dockerhub username | DOCKERHUB_USERNAME;
141141
infra/data/ci/dockerhub token | DOCKERHUB_TOKEN;
142142
143-
- name: Generate full docker tags
144-
id: meta
143+
- name: Generate docker tags for PR builds
144+
if: ${{ inputs.override_version != '' }}
145+
id: meta_pr
146+
uses: docker/metadata-action@v4
147+
with:
148+
images: |
149+
name=${{ vars.SB_GHCR }}/cortex
150+
tags: |
151+
type=raw,value=${{ inputs.override_version }}
152+
labels: |
153+
org.opencontainers.image.title=cortex
154+
org.opencontainers.image.description=A Powerful Observable Analysis and Active Response Engine
155+
org.opencontainers.image.vendor=StrangeBee
156+
org.opencontainers.image.version=${{ inputs.override_version }}
157+
158+
- name: Generate full docker tags for releases
159+
if: ${{ inputs.override_version == '' }}
160+
id: meta_release
145161
uses: docker/metadata-action@v4
146162
with:
147163
images: |
@@ -180,5 +196,5 @@ jobs:
180196
context: target/docker/stage
181197
push: true
182198
platforms: linux/amd64,linux/arm64
183-
tags: ${{ steps.meta.outputs.tags }}
184-
labels: ${{ steps.meta.outputs.labels }}
199+
tags: ${{ inputs.override_version != '' && steps.meta_pr.outputs.tags || steps.meta_release.outputs.tags }}
200+
labels: ${{ inputs.override_version != '' && steps.meta_pr.outputs.labels || steps.meta_release.outputs.labels }}

.github/workflows/deploy.nomad.yml

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
description: "If true, pull will be done from thehiveproject/cortex docker hub repo"
1313
default: false
1414
pull_request:
15-
types: [ labeled ]
15+
types: [ labeled, synchronize ]
1616

1717
# Here we define if we should go with a pr-XXX deployment version, or a vXXX (release) version
1818
# this depends on the event name
@@ -22,11 +22,21 @@ env:
2222
deployment_version: ${{ github.event_name == 'pull_request' && format('{0}-{1}', 'pr', github.event.number) || format('{0}{1}', 'v', inputs.docker_image_version) }}
2323

2424
concurrency:
25-
group: ${{ github.workflow }}-${{ github.ref }}
25+
group: deploy-${{ github.workflow }}-${{ github.ref }}
2626
cancel-in-progress: true
2727

2828
jobs:
29+
build:
30+
if: ${{ (github.event.label.name == 'ci:deploy' || contains(github.event.pull_request.labels.*.name, 'ci:deploy')) || github.event_name == 'workflow_dispatch' }}
31+
uses: ./.github/workflows/build.docker.yml
32+
with:
33+
is_prod: false
34+
override_version: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || '' }}
35+
secrets: inherit
36+
2937
prepare:
38+
needs:
39+
- build
3040
runs-on:
3141
- linux
3242
outputs:
@@ -50,7 +60,7 @@ jobs:
5060
DV2=$(echo $DV | sed 's/\.//g')
5161
echo rewriten_deployment_version=$(echo $DV2 | sed 's/-//g') >> $GITHUB_OUTPUT
5262
deploy:
53-
if: ${{ github.event.label.name == 'ci:deploy' || github.event_name == 'workflow_dispatch' }}
63+
if: ${{ (github.event.label.name == 'ci:deploy' || contains(github.event.pull_request.labels.*.name, 'ci:deploy')) || github.event_name == 'workflow_dispatch' }}
5464
needs:
5565
- prepare
5666
permissions:
@@ -70,20 +80,64 @@ jobs:
7080
secrets: |
7181
/nomad-dev/creds/developers-token-dev secret_id | NOMAD_TOKEN;
7282
- uses: actions/checkout@v4
83+
84+
- name: Setup Nomad CLI
85+
uses: hashicorp/setup-nomad@main
86+
7387
- name: Setup `nomad-pack`
7488
uses: hashicorp/setup-nomad-pack@main
7589
id: setup
90+
91+
- name: Verify installations
92+
run: |
93+
nomad version
94+
nomad-pack version
95+
7696
- name: Deploy job using Nomad Pack
7797
id: run
7898
# We pass two different version variables: one for Docker pull, the other for Nomad services
7999
run: |
80-
nomad-pack run -var from_docker_hub=${{ inputs.from_docker_hub }} \
100+
nomad-pack run -var from_docker_hub=${{ inputs.from_docker_hub || false }} \
81101
-var docker_image="${{ vars.SB_GHCR }}/cortex" \
82-
-var docker_image_version=${{ inputs.docker_image_version || env.deployment_version }} \
102+
-var docker_image_version=${{ needs.build.outputs.image_version || inputs.docker_image_version || env.deployment_version }} \
83103
-var service_version=${{ needs.prepare.outputs.expected_deployment_version }} ./deployment/nomad/packs/cortex
84104
env:
85105
NOMAD_ADDR: "http://10.30.4.180:4646"
86106
NOMAD_TOKEN: "${{ env.NOMAD_TOKEN }}"
107+
108+
- name: Wait for deployment to be healthy
109+
run: |
110+
JOB_NAME="cortex-${{ needs.prepare.outputs.expected_deployment_version }}"
111+
echo "Waiting for deployment of job: $JOB_NAME"
112+
113+
# Get the latest deployment ID
114+
DEPLOYMENT_ID=$(nomad job deployments -json "$JOB_NAME" | jq -r '.[0].ID')
115+
116+
if [ "$DEPLOYMENT_ID" = "null" ] || [ -z "$DEPLOYMENT_ID" ]; then
117+
echo "No deployment found for job $JOB_NAME"
118+
exit 1
119+
fi
120+
121+
echo "Monitoring deployment: $DEPLOYMENT_ID"
122+
123+
# Monitor the deployment status with polling every 10 seconds
124+
nomad deployment status -monitor -wait 10s "$DEPLOYMENT_ID"
125+
126+
# Check final deployment status
127+
DEPLOYMENT_STATUS=$(nomad deployment status -json "$DEPLOYMENT_ID" | jq -r '.Status')
128+
129+
if [ "$DEPLOYMENT_STATUS" = "successful" ]; then
130+
echo "✅ Deployment completed successfully!"
131+
exit 0
132+
else
133+
echo "❌ Deployment failed with status: $DEPLOYMENT_STATUS"
134+
exit 1
135+
fi
136+
env:
137+
NOMAD_ADDR: "http://10.30.4.180:4646"
138+
NOMAD_TOKEN: "${{ env.NOMAD_TOKEN }}"
139+
continue-on-error: false
140+
87141
setup:
88142
needs:
89143
- prepare

deployment/nomad/packs/cortex/variables.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ variable "docker_image_version" {
6060
variable "from_docker_hub" {
6161
description = "if we should deploy from Docker hub instead of ghcr.io"
6262
type = bool
63-
default = "false"
63+
default = false
6464
}
6565

6666
variable "service_version" {

package/docker/entrypoint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ then
169169

170170
chown -R cortex:cortex "$CONFIG_FILE" /etc/cortex
171171
test -e /var/run/docker.sock && chown cortex:cortex /var/run/docker.sock
172-
su - cortex -c "/opt/cortex/bin/cortex \
172+
su -m cortex -c "/opt/cortex/bin/cortex \
173173
-Dconfig.file=$CONFIG_FILE \
174174
-Dlogger.file=/etc/cortex/logback.xml \
175175
-Dpidfile.path=/dev/null \

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ Seq[(String, ModuleID)](
1414

1515
// The Play plugin
1616
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.9")
17-
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.5")
17+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.5")

version.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ThisBuild / version := "4.0.0-1"
1+
ThisBuild / version := "4.0.1-1"

0 commit comments

Comments
 (0)