1- name : build.docker.image.dev
1+ name : build.docker.image.cortex
22on :
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"
1929 description : " Version number of the Docker image"
2030 value : ${{ jobs.build.outputs.image_version }}
2131
22-
2332concurrency :
2433 group : ${{ github.workflow }}-${{ github.ref }}
2534 cancel-in-progress : true
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
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+ 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 }}
0 commit comments