build-and-publish-release.yml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. name: Build and Publish Release
  2. on:
  3. push:
  4. tags:
  5. - 'v[0-9]+.[0-9]+.[0-9]+'
  6. workflow_dispatch:
  7. inputs:
  8. release_version:
  9. description: "Version of the release"
  10. required: true
  11. concurrency:
  12. group: build-opencost
  13. cancel-in-progress: true
  14. env:
  15. # Use docker.io for Docker Hub if empty
  16. REGISTRY: ghcr.io
  17. # github.repository as <account>/<repo>
  18. IMAGE_NAME: ${{ github.repository }}
  19. jobs:
  20. build-and-publish-opencost:
  21. runs-on: ubuntu-latest
  22. permissions:
  23. contents: read
  24. packages: write
  25. steps:
  26. - name: Get Version From Tag
  27. id: tag
  28. if: ${{ github.event_name }} == 'push'
  29. run: |
  30. echo "TRIGGERED_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
  31. - name: Determine Version Number
  32. id: version_number
  33. run: |
  34. if [ -z "${TRIGGERED_TAG}" ];
  35. then
  36. version=${{ inputs.release_version }}
  37. else
  38. version=$TRIGGERED_TAG
  39. fi
  40. if [[ ${version:0:1} == "v" ]];
  41. then
  42. echo "RELEASE_VERSION=${version:1}" >> $GITHUB_OUTPUT
  43. else
  44. echo "RELEASE_VERSION=$version" >> $GITHUB_OUTPUT
  45. fi
  46. - name: Show Input Values
  47. run: |
  48. echo "release version: ${{ inputs.release_version }}"
  49. - name: Make Branch Name
  50. id: branch
  51. run: |
  52. VERSION_NUMBER=${{ steps.version_number.outputs.RELEASE_VERSION }}
  53. echo "BRANCH_NAME=v${VERSION_NUMBER%.*}" >> $GITHUB_ENV
  54. - name: Checkout Repo
  55. uses: actions/checkout@v4
  56. with:
  57. repository: 'opencost/opencost'
  58. ref: '${{ steps.branch.outputs.BRANCH_NAME }}'
  59. path: ./opencost
  60. - name: Set SHA
  61. id: sha
  62. run: |
  63. pushd ./opencost
  64. echo "OC_SHORTHASH=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  65. popd
  66. # Login against a Docker registry except on PR
  67. # https://github.com/docker/login-action
  68. - name: Log into registry ${{ env.REGISTRY }}
  69. uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
  70. with:
  71. registry: ${{ env.REGISTRY }}
  72. username: ${{ github.actor }}
  73. password: ${{ secrets.GITHUB_TOKEN }}
  74. - name: Set OpenCost Image Tags
  75. id: tags
  76. run: |
  77. echo "IMAGE_TAG=ghcr.io/opencost/opencost:${{ steps.sha.outputs.OC_SHORTHASH }}" >> $GITHUB_OUTPUT
  78. echo "IMAGE_TAG_LATEST=ghcr.io/opencost/opencost:latest" >> $GITHUB_OUTPUT
  79. echo "IMAGE_TAG_VERSION=ghcr.io/opencost/opencost:${{ steps.version_number.outputs.RELEASE_VERSION }}" >> $GITHUB_OUTPUT
  80. echo "IMAGE_TAG_UI=ghcr.io/opencost/opencost-ui:${{ steps.sha.outputs.OC_SHORTHASH }}" >> $GITHUB_OUTPUT
  81. echo "IMAGE_TAG_UI_LATEST=ghcr.io/opencost/opencost-ui:latest" >> $GITHUB_OUTPUT
  82. echo "IMAGE_TAG_UI_VERSION=ghcr.io/opencost/opencost-ui:${{ steps.version_number.outputs.RELEASE_VERSION }}" >> $GITHUB_OUTPUT
  83. # echo "IMAGE_TAG_QUAY=quay.io/kubecost1/kubecost-cost-model:${{ steps.sha.outputs.OC_SHORTHASH }}" >> $GITHUB_OUTPUT
  84. # echo "IMAGE_TAG_LATEST_QUAY=quay.io/kubecost1/kubecost-cost-model:latest" >> $GITHUB_OUTPUT
  85. # echo "IMAGE_TAG_VERSION_QUAY=quay.io/kubecost1/kubecost-cost-model:prod-${{ steps.version_number.outputs.RELEASE_VERSION }}" >> $GITHUB_OUTPUT
  86. # echo "IMAGE_TAG_UI_QUAY=quay.io/kubecost1/opencost-ui:${{ steps.sha.outputs.OC_SHORTHASH }}" >> $GITHUB_OUTPUT
  87. # echo "IMAGE_TAG_UI_LATEST_QUAY=quay.io/kubecost1/opencost-ui:latest" >> $GITHUB_OUTPUT
  88. # echo "IMAGE_TAG_UI_VERSION_QUAY=quay.io/kubecost1/opencost-ui:prod-${{ inputs.release_version }}" >> $GITHUB_OUTPUT
  89. - name: Set up Docker Buildx
  90. uses: docker/setup-buildx-action@v3
  91. with:
  92. buildkitd-flags: --debug
  93. - name: Install Go
  94. uses: actions/setup-go@v5
  95. with:
  96. go-version: 'stable'
  97. - name: Set up just
  98. uses: extractions/setup-just@v1
  99. - name: Install crane
  100. uses: imjasonh/setup-crane@v0.3
  101. ## Install manifest-tool, which is required to combine multi-arch images
  102. ## https://github.com/estesp/manifest-tool
  103. - name: Install manifest-tool
  104. run: |
  105. mkdir -p manifest-tool
  106. pushd manifest-tool
  107. wget -q https://github.com/estesp/manifest-tool/releases/download/v2.0.8/binaries-manifest-tool-2.0.8.tar.gz
  108. tar -xzf binaries-manifest-tool-2.0.8.tar.gz
  109. cp manifest-tool-linux-amd64 manifest-tool
  110. echo "$(pwd)" >> $GITHUB_PATH
  111. # - name: Login to Quay
  112. # uses: docker/login-action@v3
  113. # with:
  114. # registry: quay.io
  115. # username: ${{ secrets.QUAY_USERNAME }}
  116. # password: ${{ secrets.QUAY_PASSWORD }}
  117. - name: Build and push (multiarch) OpenCost
  118. working-directory: ./opencost
  119. run: |
  120. just build '${{ steps.tags.outputs.IMAGE_TAG }}' '${{ steps.version_number.outputs.RELEASE_VERSION }}'
  121. crane copy '${{ steps.tags.outputs.IMAGE_TAG }}' '${{ steps.tags.outputs.IMAGE_TAG_LATEST }}'
  122. crane copy '${{ steps.tags.outputs.IMAGE_TAG }}' '${{ steps.tags.outputs.IMAGE_TAG_VERSION }}'
  123. # crane copy '${{ steps.tags.outputs.IMAGE_TAG }}' '${steps.tags.outputs.IMAGE_TAG_QUAY}'
  124. # crane copy '${{ steps.tags.outputs.IMAGE_TAG }}' '${steps.tags.outputs.IMAGE_TAG_LATEST_QUAY}'
  125. # crane copy '${{ steps.tags.outputs.IMAGE_TAG }}' '${steps.tags.outputs.IMAGE_TAG_VERSION_QUAY}'
  126. - name: Build and push (multiarch) OpenCost UI
  127. working-directory: ./opencost/ui
  128. run: |
  129. just build '${{ steps.tags.outputs.IMAGE_TAG_UI }}' '${{ steps.version_number.outputs.RELEASE_VERSION }}'
  130. crane copy '${{ steps.tags.outputs.IMAGE_TAG_UI }}' '${{ steps.tags.outputs.IMAGE_TAG_UI_LATEST }}'
  131. crane copy '${{ steps.tags.outputs.IMAGE_TAG_UI }}' '${{ steps.tags.outputs.IMAGE_TAG_UI_VERSION }}'
  132. # crane copy '${steps.tags.outputs.IMAGE_TAG_UI}' '${steps.tags.outputs.IMAGE_TAG_UI_QUAY}'
  133. # crane copy '${steps.tags.outputs.IMAGE_TAG_UI}' '${steps.tags.outputs.IMAGE_TAG_UI_LATEST_QUAY}'
  134. # crane copy '${steps.tags.outputs.IMAGE_TAG_UI}' '${steps.tags.outputs.IMAGE_TAG_UI_VERSION_QUAY}'