diff --git a/.github/workflows/build-op-image.yaml b/.github/workflows/build-op-image.yaml index 4def1f144..5b9db3b3d 100644 --- a/.github/workflows/build-op-image.yaml +++ b/.github/workflows/build-op-image.yaml @@ -24,20 +24,55 @@ on: - 'master' env: - REGISTRY_REPO: 'sarathchandra24' + DOCKER_REPO: 'sarathchandra24' DOCKER_IMAGE: 'fluent-operator' GITHUB_IMAGE: "${{ github.repository }}/fluent-operator" jobs: + build-image-metadata: + runs-on: ubuntu-latest + name: Build Image Metadata + outputs: + FULL_IMG_NAME: ${{ steps.set-outputs.outputs.FULL_IMAGE_NAME }} + IMG_NAME: ${{ steps.set-outputs.outputs.IMAGE_NAME }} + DOCKER_IMG_NAME: ${{ steps.set-outputs.outputs.DOCKER_IMG_NAME }} + version: ${{ steps.image-metadata.outputs.version }} + tags: ${{ steps.image-metadata.outputs.tags }} + labels: ${{ steps.image-metadata.outputs.labels }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install jq + uses: dcarbone/install-jq-action@v2.1.0 + + - name: docker metadata + id: image-metadata + uses: docker/metadata-action@v5 + with: + images: "ghcr.io/${{ env.GITHUB_IMAGE }}" + tags: | + raw,latest + type=ref,event=branch + type=ref,event=pr + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Set outputs + id: set-outputs + run: | + echo "FULL_IMAGE_NAME=$(${{ steps.image-metadata.outputs.json }} | jq '.tags[0]')" >> $GITHUB_OUTPUT + echo "IMAGE_NAME=${{ env.GITHUB_IMAGE }}" >> $GITHUB_OUTPUT + echo "DOCKER_IMG_NAME=${{env.DOCKER_REPO}}/${{ env.DOCKER_IMAGE }}" >> $GITHUB_OUTPUT + operator-build: runs-on: ubuntu-latest timeout-minutes: 30 name: Build Image for Fluent Operator - outputs: - IMG_VERSION: ${{ steps.image-metadata.outputs.version }} - IMG_NAME: ${{ steps.image-metadata.outputs.tags }} - OPERATOR_DOCKER_IMG: "${{ env.REGISTRY_REPO }}/${{ env.DOCKER_IMAGE }}" - + needs: + - build-image-metadata steps: - name: Checkout code uses: actions/checkout@v2 @@ -56,19 +91,6 @@ jobs: registry: ghcr.io username: ${{ github.actor_id }} password: ${{ secrets.GITHUB_TOKEN }} - - - name: docker metadata - id: image-metadata - uses: docker/metadata-action@v5 - with: - images: "ghcr.io/${{ env.GITHUB_IMAGE }}" - tags: | - raw,latest - type=ref,event=branch - type=ref,event=pr - type=ref,event=tag - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - name: Build and push uses: docker/build-push-action@v2 @@ -77,16 +99,17 @@ jobs: file: ./cmd/fluent-manager/Dockerfile push: true platforms: linux/amd64,linux/arm64 - tags: ${{ steps.image-metadata.outputs.tags }} - labels: ${{ steps.image-metadata.outputs.labels }} + tags: ${{ needs.build-image-metadata.outputs.tags }} + labels: ${{ needs.build-image-metadata.outputs.labels }} scan-operator-image: name: Scan Docker Image needs: - operator-build + - build-image-metadata uses: ./.github/workflows/call-scan-images.yaml with: - source_image: "${{ needs.operator-build.outputs.IMG_NAME }}" + source_image: "${{ needs.build-image-metadata.outputs.FULL_IMG_NAME }}" source_registry: ghcr.io platforms: '["linux/arm64", "linux/amd64"]' secrets: @@ -100,10 +123,11 @@ jobs: needs: - operator-build - scan-operator-image + - build-image-metadata with: - source_image: "${{ needs.operator-build.outputs.IMG_NAME }}" + source_image: "${{ needs.build-image-metadata.outputs.FULL_IMG_NAME }}" source_registry: ghcr.io - target_image: ${{ needs.operator-build.outputs.OPERATOR_DOCKER_IMG }} + target_image: ${{ needs.build-image-metadata.outputs.DOCKER_IMG_NAME }} target_registry: docker.io platforms: "['linux/arm64', 'linux/amd64']" secrets: