|
| 1 | +name: Build & Push Images |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + version_tag: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + event_processor_tag: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + environment: |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + ghcr_token: |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + sign_cert: |
| 19 | + required: true |
| 20 | + type: string |
| 21 | + sign_key: |
| 22 | + required: true |
| 23 | + type: string |
| 24 | + sign_container: |
| 25 | + required: true |
| 26 | + type: string |
| 27 | + |
| 28 | +jobs: |
| 29 | + build_images: |
| 30 | + name: Build Docker Images without dependencies |
| 31 | + strategy: |
| 32 | + fail-fast: false |
| 33 | + matrix: |
| 34 | + service: ['backend', 'frontend', 'user-auditor', 'web-pdf'] |
| 35 | + uses: ./.github/workflows/images-without-dependencies.yml |
| 36 | + with: |
| 37 | + microservice: ${{ matrix.service }} |
| 38 | + tag: ${{ inputs.version_tag }} |
| 39 | + secrets: inherit |
| 40 | + |
| 41 | + build_images_with_dependencies: |
| 42 | + name: Build & Push Images with dependencies |
| 43 | + needs: |
| 44 | + - build_images |
| 45 | + runs-on: signing |
| 46 | + steps: |
| 47 | + - name: Check out code into the right branch |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Login to GitHub Container Registry |
| 51 | + run: | |
| 52 | + docker login ghcr.io -u utmstack -p ${{ inputs.ghcr_token }} |
| 53 | + echo "Logged in to GitHub Container Registry" |
| 54 | + |
| 55 | + - name: Download base images |
| 56 | + run: | |
| 57 | + docker pull ghcr.io/threatwinds/eventprocessor/base:${{ inputs.event_processor_tag }} |
| 58 | + echo "Downloaded base images" |
| 59 | +
|
| 60 | + - name: Build Agent |
| 61 | + run: | |
| 62 | + cd ${{ github.workspace }}/agent/service/config; (Get-Content const.go) | Foreach-Object { $_ -replace 'const REPLACE_KEY string = ""', 'const REPLACE_KEY string = "${{ secrets.AGENT_SECRET_PREFIX }}"' } | Set-Content const.go |
| 63 | + |
| 64 | + $env:GOOS = "linux" |
| 65 | + $env:GOARCH = "amd64" |
| 66 | + cd ${{ github.workspace }}/agent/service; go build -o utmstack_agent_service -v . |
| 67 | + cd ${{ github.workspace }}/agent/installer; go build -o utmstack_agent_installer -v . |
| 68 | + |
| 69 | + $env:GOOS = "windows" |
| 70 | + cd ${{ github.workspace }}/agent/service; go build -o utmstack_agent_service.exe -v . |
| 71 | + signtool sign /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 /f "${{ inputs.sign_cert }}" /csp "eToken Base Cryptographic Provider" /k "[{{${{ inputs.sign_key }}}}]=${{ inputs.sign_container }}" "utmstack_agent_service.exe" |
| 72 | + cd ${{ github.workspace }}/agent/installer; go build -o utmstack_agent_installer.exe -v . |
| 73 | + signtool sign /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 /f "${{ inputs.sign_cert }}" /csp "eToken Base Cryptographic Provider" /k "[{{${{ inputs.sign_key }}}}]=${{ inputs.sign_container }}" "utmstack_agent_installer.exe" |
| 74 | +
|
| 75 | + Copy-Item -Path "C:/dependencies/${{ inputs.environment }}/agent/*" -Destination "./dependencies/" |
| 76 | +
|
| 77 | + echo "Agent build completed" |
| 78 | + |
| 79 | + - name: Build Plugins |
| 80 | + run: | |
| 81 | + export GOOS=linux |
| 82 | + export GOARCH=amd64 |
| 83 | + cd ${{ github.workspace }}/plugins |
| 84 | + make build |
| 85 | + |
| 86 | + - name: Build Event Processor Image |
| 87 | + run: | |
| 88 | + New-Item -ItemType Directory -Force -Path "./geolocation/" |
| 89 | + Copy-Item -Path "C:/dependencies/${{ inputs.environment }}/geolocation/*" -Destination "./geolocation/" |
| 90 | +
|
| 91 | + docker build -t ghcr.io/utmstack/utmstack/eventprocessor:${{ inputs.version_tag }}-community \ |
| 92 | + --build-arg BASE_IMAGE=ghcr.io/threatwinds/eventprocessor/base:${{ inputs.event_processor_tag }} \ |
| 93 | + -f ./event_processor.Dockerfile \ |
| 94 | + . |
| 95 | + echo "Event Processor image built" |
| 96 | +
|
| 97 | + - name: Build Agent Manager Image |
| 98 | + run: | |
| 99 | + go build -o ./agent-manager/agent-manager -v ./agent-manager |
| 100 | + docker build -t ghcr.io/utmstack/utmstack/agent-manager:${{ inputs.version_tag }}-community \ |
| 101 | + -f ./agent-manager/Dockerfile \ |
| 102 | + . |
| 103 | + echo "Agent Manager image built" |
| 104 | +
|
| 105 | + - name: Push images with dependencies |
| 106 | + run: | |
| 107 | + docker push ghcr.io/utmstack/utmstack/eventprocessor:${{ inputs.version_tag }}-community |
| 108 | + docker push ghcr.io/utmstack/utmstack/agent-manager:${{ inputs.version_tag }}-community |
| 109 | + echo "Pushed images with dependencies" |
| 110 | + |
| 111 | + - name: Push new release |
| 112 | + run: | |
| 113 | + echo "Pushing new release..." |
| 114 | + $changelog = Get-Content -Path "CHANGELOG.md" -Raw |
| 115 | +
|
| 116 | + $cmAuth = $env:CM_AUTH | ConvertFrom-Json |
| 117 | +
|
| 118 | + $body = @{ |
| 119 | + version = ${{ inputs.version_tag }} |
| 120 | + changelog = $changelog |
| 121 | + images = "ghcr.io/utmstack/utmstack/backend,ghcr.io/utmstack/utmstack/frontend,ghcr.io/utmstack/utmstack/user-auditor,ghcr.io/utmstack/utmstack/web-pdf,ghcr.io/utmstack/utmstack/eventprocessor,ghcr.io/utmstack/utmstack/agent-manager" |
| 122 | + edition = "community" |
| 123 | + } | ConvertTo-Json -Depth 3 |
| 124 | +
|
| 125 | + $response = Invoke-RestMethod -Method Post ` |
| 126 | + -Uri "https://customermanager.utmstack.com/${{ inputs.environment }}/api/v1/releases/register" ` |
| 127 | + -Headers @{ |
| 128 | + id = $cmAuth.id |
| 129 | + key = $cmAuth.key |
| 130 | + } ` |
| 131 | + -Body $body ` |
| 132 | + -ContentType "application/json" |
| 133 | +
|
| 134 | + $response |
0 commit comments