Açıklama Yok

Procedure_push_docker_images.yml 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. run-name: Launch Push Docker Images - ${{ inputs.id }}
  2. name: Push Docker Images
  3. on:
  4. workflow_dispatch:
  5. inputs:
  6. image_tag:
  7. description: 'Docker image tag'
  8. default: '4.14.3'
  9. required: true
  10. docker_reference:
  11. description: 'wazuh-docker reference'
  12. required: true
  13. filebeat_module_version:
  14. description: 'Filebeat module version'
  15. default: '0.5'
  16. required: true
  17. revision:
  18. description: 'Package revision'
  19. default: '1'
  20. required: true
  21. id:
  22. description: "ID used to identify the workflow uniquely."
  23. type: string
  24. required: false
  25. dev:
  26. description: "Add tag suffix '-dev' to the image tag ?"
  27. type: boolean
  28. default: true
  29. required: false
  30. workflow_call:
  31. inputs:
  32. image_tag:
  33. description: 'Docker image tag'
  34. default: '4.14.3'
  35. required: true
  36. type: string
  37. docker_reference:
  38. description: 'wazuh-docker reference'
  39. required: false
  40. type: string
  41. filebeat_module_version:
  42. description: 'Filebeat module version'
  43. default: '0.5'
  44. required: true
  45. type: string
  46. revision:
  47. description: 'Package revision'
  48. default: '1'
  49. required: true
  50. type: string
  51. id:
  52. description: "ID used to identify the workflow uniquely."
  53. type: string
  54. required: false
  55. dev:
  56. description: "Add tag suffix '-dev' to the image tag ?"
  57. type: boolean
  58. default: false
  59. required: false
  60. jobs:
  61. build-and-push:
  62. runs-on: ubuntu-22.04
  63. permissions:
  64. id-token: write
  65. contents: read
  66. env:
  67. IMAGE_REGISTRY: ${{ inputs.dev && vars.IMAGE_REGISTRY_DEV || vars.IMAGE_REGISTRY_PROD }}
  68. IMAGE_TAG: ${{ inputs.image_tag }}
  69. FILEBEAT_MODULE_VERSION: ${{ inputs.filebeat_module_version }}
  70. REVISION: ${{ inputs.revision }}
  71. steps:
  72. - name: Print inputs
  73. run: |
  74. echo "---------------------------------------------"
  75. echo "Running Procedure_push_docker_images workflow"
  76. echo "---------------------------------------------"
  77. echo "* BRANCH: ${{ github.ref }}"
  78. echo "* COMMIT: ${{ github.sha }}"
  79. echo "---------------------------------------------"
  80. echo "Inputs provided:"
  81. echo "---------------------------------------------"
  82. echo "* id: ${{ inputs.id }}"
  83. echo "* image_tag: ${{ inputs.image_tag }}"
  84. echo "* docker_reference: ${{ inputs.docker_reference }}"
  85. echo "* filebeat_module_version: ${{ inputs.filebeat_module_version }}"
  86. echo "* revision: ${{ inputs.revision }}"
  87. echo "* dev: ${{ inputs.dev }}"
  88. echo "---------------------------------------------"
  89. - name: Checkout repository
  90. uses: actions/checkout@v4
  91. with:
  92. ref: ${{ inputs.docker_reference }}
  93. - name: free disk space
  94. uses: ./.github/free-disk-space
  95. - name: Set up QEMU
  96. uses: docker/setup-qemu-action@v3
  97. - name: Set up Docker Buildx
  98. uses: docker/setup-buildx-action@v3
  99. - name: Configure aws credentials
  100. if: ${{ inputs.dev == true }}
  101. uses: aws-actions/configure-aws-credentials@v4
  102. with:
  103. role-to-assume: ${{ secrets.AWS_IAM_DOCKER_ROLE }}
  104. aws-region: "${{ secrets.AWS_REGION }}"
  105. - name: Log in to Amazon ECR
  106. if: ${{ inputs.dev == true }}
  107. uses: aws-actions/amazon-ecr-login@v2
  108. - name: Log in to Docker Hub
  109. if: ${{ inputs.dev == false }}
  110. uses: docker/login-action@v3
  111. with:
  112. username: ${{ secrets.DOCKERHUB_USERNAME }}
  113. password: ${{ secrets.DOCKERHUB_PASSWORD }}
  114. - name: Build Wazuh images
  115. run: |
  116. IMAGE_TAG="${{ inputs.image_tag }}"
  117. FILEBEAT_MODULE_VERSION=${{ inputs.filebeat_module_version }}
  118. REVISION=${{ inputs.revision }}
  119. if [[ "$IMAGE_TAG" == *"-"* ]]; then
  120. IFS='-' read -r -a tokens <<< "$IMAGE_TAG"
  121. if [ -z "${tokens[1]}" ]; then
  122. echo "Invalid image tag: $IMAGE_TAG"
  123. exit 1
  124. fi
  125. DEV_STAGE=${tokens[1]}
  126. WAZUH_VER=${tokens[0]}
  127. ./build-images.sh -v $WAZUH_VER -r $REVISION -d $DEV_STAGE -f $FILEBEAT_MODULE_VERSION -rg $IMAGE_REGISTRY -m
  128. else
  129. ./build-images.sh -v $IMAGE_TAG -r $REVISION -f $FILEBEAT_MODULE_VERSION -rg $IMAGE_REGISTRY -m
  130. fi
  131. # Save .env file (generated by build-images.sh) contents to $GITHUB_ENV
  132. ENV_FILE_PATH="../.env"
  133. if [ -f $ENV_FILE_PATH ]; then
  134. while IFS= read -r line || [ -n "$line" ]; do
  135. echo "$line" >> $GITHUB_ENV
  136. done < $ENV_FILE_PATH
  137. else
  138. echo "The environment file $ENV_FILE_PATH does not exist!"
  139. exit 1
  140. fi
  141. working-directory: ./build-docker-images
  142. - name: Image exists validation
  143. if: ${{ inputs.dev == false }}
  144. id: validation
  145. run: |
  146. IMAGE_TAG=${{ inputs.image_tag }}
  147. PURPOSE=""
  148. if [[ "$IMAGE_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  149. if docker manifest inspect $IMAGE_REGISTRY/wazuh/wazuh-manager:$IMAGE_TAG > /dev/null 2>&1; then
  150. PURPOSE="regeneration"
  151. echo "Image wazuh/wazuh-manager:$IMAGE_TAG exists. Setting PURPOSE to 'regeneration'"
  152. else
  153. PURPOSE="new release"
  154. echo "Image wazuh/wazuh-manager:$IMAGE_TAG does NOT exist. Setting PURPOSE to 'new release'"
  155. fi
  156. echo "✅ Release tag: '$IMAGE_TAG'"
  157. elif [[ "$IMAGE_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+-(alpha|beta|rc)[0-9]+$ ]]; then
  158. PURPOSE="new stage"
  159. echo "✅ Stage tag: '$IMAGE_TAG'. Setting PURPOSE to 'new stage'"
  160. else
  161. echo "❌ No release or stage tag ('$IMAGE_TAG'), the GH issue will not be created"
  162. fi
  163. echo "purpose=$PURPOSE" >> $GITHUB_OUTPUT
  164. - name: GH issue notification
  165. if: ${{ inputs.dev == false && steps.validation.outputs.purpose != '' }}
  166. run: |
  167. IMAGE_TAG=${{ inputs.image_tag }}
  168. GH_TITLE=""
  169. GH_MESSAGE=""
  170. PURPOSE="${{ steps.validation.outputs.purpose }}"
  171. ## Setting GH issue title
  172. GH_TITLE="Artifactory vulnerabilities update \`v$IMAGE_TAG\`"
  173. ## Setting GH issue body
  174. GH_MESSAGE=$(cat <<- EOF | tr -d '\r' | sed 's/^[[:space:]]*//'
  175. ### Description
  176. - [ ] Update the [Artifactory vulnerabilities](${{ secrets.NOTIFICATION_SHEET_URL }}) sheet with the \`v$IMAGE_TAG\` vulnerabilities.
  177. **Purpose**: $PURPOSE
  178. >[!NOTE]
  179. >To update the \`Tentative Release\` column, follow these steps:
  180. https://github.com/wazuh/${{ secrets.NOTIFICATION_REPO }}/issues/2049#issuecomment-2671590268
  181. EOF
  182. )
  183. # Print the GH Variables content
  184. echo "--- Variable Content ---"
  185. echo "$GH_TITLE"
  186. echo "------------------------"
  187. echo "--- Variable Content ---"
  188. echo "$GH_MESSAGE"
  189. echo "------------------------"
  190. ## GH issue creation
  191. ISSUE_URL=$(gh issue create \
  192. -R wazuh/${{ secrets.NOTIFICATION_REPO }} \
  193. --title "$GH_TITLE" \
  194. --body "$GH_MESSAGE" \
  195. --label "level/task" \
  196. --label "type/maintenance" \
  197. --label "request/operational")
  198. ## Adding the issue to the team project
  199. PROJECT_ITEM_ID=$(gh project item-add \
  200. ${{ secrets.NOTIFICATION_PROJECT_NUMBER }} \
  201. --url $ISSUE_URL \
  202. --owner wazuh \
  203. --format json \
  204. | jq -r '.id')
  205. ## Setting Objective
  206. gh project item-edit --id $PROJECT_ITEM_ID --project-id ${{ secrets.NOTIFICATION_PROJECT_ID }} --field-id ${{ secrets.NOTIFICATION_PROJECT_OBJECTIVE_ID }} --text "Security scans"
  207. ## Setting Priority
  208. gh project item-edit --id $PROJECT_ITEM_ID --project-id ${{ secrets.NOTIFICATION_PROJECT_ID }} --field-id ${{ secrets.NOTIFICATION_PROJECT_PRIORITY_ID }} --single-select-option-id ${{ secrets.NOTIFICATION_PROJECT_PRIORITY_OPTION_ID }}
  209. ## Setting Size
  210. gh project item-edit --id $PROJECT_ITEM_ID --project-id ${{ secrets.NOTIFICATION_PROJECT_ID }} --field-id ${{ secrets.NOTIFICATION_PROJECT_SIZE_ID }} --single-select-option-id ${{ secrets.NOTIFICATION_PROJECT_SIZE_OPTION_ID }}
  211. ## Setting Subteam
  212. gh project item-edit --id $PROJECT_ITEM_ID --project-id ${{ secrets.NOTIFICATION_PROJECT_ID }} --field-id ${{ secrets.NOTIFICATION_PROJECT_SUBTEAM_ID }} --single-select-option-id ${{ secrets.NOTIFICATION_PROJECT_SUBTEAM_OPTION_ID }}
  213. env:
  214. GH_TOKEN: ${{ secrets.NOTIFICATION_GH_ARTIFACT_TOKEN }}