diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 38642a59..c586d0a0 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -1,4 +1,4 @@ -name: Unit Tests +name: Unit Tests and Build Docker Image on: schedule: @@ -17,6 +17,9 @@ on: jobs: test-finops-agent: runs-on: Kubecost-Linux-Medium-x86 + permissions: + contents: read + packages: write steps: - name: Install Go @@ -26,11 +29,11 @@ jobs: - uses: actions/checkout@v4 with: - path: ./finops-agent + path: ./ibm-finops-agent - uses: actions/checkout@v4 with: - repository: 'kubecost/opencost' + repository: 'opencost/opencost' ref: 'bolt/opencost-mods' fetch-depth: 0 path: ./opencost @@ -54,10 +57,10 @@ jobs: # The directory is important. We cover both OC and KCM with the # ./kubecost/**/go.sum hash. Critically important because of the # "replace" in KCM's go.mod - key: ${{ runner.os }}-go-${{ hashFiles('./finops-agent/**/go.sum') }} + key: ${{ runner.os }}-go-${{ hashFiles('./ibm-finops-agent/**/go.sum') }} - name: Test - working-directory: ./finops-agent + working-directory: ./ibm-finops-agent run: | go test -v ./... --coverprofile=coverage.out @@ -69,7 +72,7 @@ jobs: echo $PR_NUM > pr_num.txt echo $GITHUB_BASE_REF > base.txt echo $GITHUB_HEAD_REF > head.txt - mv ./finops-agent/coverage.out coverage.out + mv ./ibm-finops-agent/coverage.out coverage.out - name: save coverage file uses: actions/upload-artifact@v4 @@ -82,10 +85,45 @@ jobs: base.txt head.txt - - name: Build - working-directory: ./finops-agent + - name: Build Go binary + working-directory: ./ibm-finops-agent run: | - go build -o finops-agent ./cmd/finops-agent/main.go + go build -o ibm-finops-agent ./cmd/finops-agent/main.go + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }}/ibm-finops-agent + tags: | + type=sha,prefix=pr- + type=ref,event=pr + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./ibm-finops-agent/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + DUCK_VERSION=v0.9.2 + version=${{ github.sha }} + commit=${{ github.sha }} # notify-fail: # needs: [test-cost-model] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..8e187a03 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,98 @@ +FROM redhat/ubi9:latest AS build-env +ARG TARGETPLATFORM +ARG DUCK_VERSION +RUN yum install -y unzip \ + wget \ + ca-certificates \ + yum-utils + +# Install Go 1.24.0 +RUN wget https://go.dev/dl/go1.24.0.linux-amd64.tar.gz && \ + rm -rf /usr/local/go && \ + tar -C /usr/local -xzf go1.24.0.linux-amd64.tar.gz && \ + rm go1.24.0.linux-amd64.tar.gz + +ENV PATH="${PATH}:/usr/local/go/bin" +ENV GOPROXY=https://proxy.golang.org,direct +ENV GO111MODULE=on +ENV GOSUMDB=off + +RUN go version + +RUN mkdir /app +WORKDIR /app + +ARG version=dev +ARG commit=HEAD + +# First copy all go.mod and go.sum files +COPY ./opencost/core/go.mod ./opencost/core/go.mod +COPY ./opencost/core/go.sum ./opencost/core/go.sum + +COPY ./opencost/modules/prometheus-source/go.mod ./opencost/modules/prometheus-source/go.mod +COPY ./opencost/modules/prometheus-source/go.sum ./opencost/modules/prometheus-source/go.sum + +COPY ./opencost/go.mod ./opencost/go.mod +COPY ./opencost/go.sum ./opencost/go.sum + +# Then copy the source code +COPY ./opencost/core ./opencost/core +COPY ./opencost/modules/prometheus-source ./opencost/modules/prometheus-source +COPY ./opencost ./opencost + +# Now run go mod download for each module +RUN cd ./opencost/core && go mod download +RUN cd ./opencost/modules/prometheus-source && go mod download +RUN cd ./opencost && go mod download + +# ibm-finops-agent +COPY ./ibm-finops-agent/go.mod ./ibm-finops-agent/go.mod +COPY ./ibm-finops-agent/go.sum ./ibm-finops-agent/go.sum +COPY ./ibm-finops-agent ./ibm-finops-agent +RUN cd ./ibm-finops-agent && go mod download + +# Build the binary +RUN cd ./ibm-finops-agent/cmd/finops-agent && set -e ;\ + go build -a -installsuffix cgo \ + -ldflags \ + "-X github.com/kubecost/ibm-finops-agent/cmd/finops-agent/version.Version=${version} \ + -X github.com/kubecost/ibm-finops-agent/cmd/finops-agent/version.GitCommit=${commit}" \ + -o /go/bin/app + + +FROM redhat/ubi9-micro:latest + +ARG commit +ARG version +ARG occommit + +LABEL com.ibm-finops-agent.base.version="${version}" +LABEL com.ibm-finops-agent.base.commit="${commit}" + +# REQUIRED FOR RED HAT OPENSHIFT OPERATOR +LABEL name="ibm-finops-agent" \ + summary="IBM FinOps Agent" \ + description="IBM FinOps Agent" \ + vendor="IBM" \ + maintainer="kubecost-image-support@wwpdl.vnet.ibm.com" \ + version="${version}" \ + release="${version}" + +# Copy ca-certificates and ClickHouse files from the download-env stage +COPY --from=build-env /etc/pki/ca-trust /etc/pki/ca-trust +ENV CONTAINERIZED="true" + +# Add timezone data and set timezone to GMT +ENV TZ=UTC + +# ADD ./ibm-finops-agent/configs/default.json /models/default.json +# ADD ./ibm-finops-agent/configs/azure.json /models/azure.json +# ADD ./ibm-finops-agent/configs/aws.json /models/aws.json +# ADD ./ibm-finops-agent/configs/gcp.json /models/gcp.json +# ADD ./ibm-finops-agent/configs/alibaba.json /models/alibaba.json +# ADD ./ibm-finops-agent/assets/kubecost_logo@2x.jpg /assets/kubecost_logo@2x.jpg +# ADD ./ibm-finops-agent/configs/carbonlookupdata.csv /static/carbonlookupdata.csv +# ADD ./ibm-finops-agent/ubi9_eula.txt /licenses/ubi9_eula.txt +COPY --from=build-env /go/bin/app /go/bin/app +USER 1001 +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/ubi9_eula.txt b/ubi9_eula.txt new file mode 100644 index 00000000..4275d7b7 --- /dev/null +++ b/ubi9_eula.txt @@ -0,0 +1,86 @@ +Red Hat Universal Base Image +End User License Agreement +March 2019 + +PLEASE READ THIS END USER LICENSE AGREEMENT CAREFULLY BEFORE USING SOFTWARE FROM RED HAT. BY USING RED HAT +SOFTWARE, YOU SIGNIFY YOUR ASSENT TO AND ACCEPTANCE OF THIS END USER LICENSE AGREEMENT AND ACKNOWLEDGE YOU +HAVE READ AND UNDERSTAND THE TERMS. AN INDIVIDUAL ACTING ON BEHALF OF AN ENTITY REPRESENTS THAT HE OR SHE HAS THE +AUTHORITY TO ENTER INTO THIS END USER LICENSE AGREEMENT ON BEHALF OF THAT ENTITY. IF YOU DO NOT ACCEPT THE TERMS +OF THIS AGREEMENT, THEN YOU MUST NOT USE THE RED HAT SOFTWARE. THIS END USER LICENSE AGREEMENT DOES NOT PROVIDE +ANY RIGHTS TO RED HAT SERVICES SUCH AS SOFTWARE MAINTENANCE, UPGRADES OR SUPPORT. PLEASE REVIEW YOUR SERVICE +OR SUBSCRIPTION AGREEMENT(S) THAT YOU MAY HAVE WITH RED HAT OR OTHER AUTHORIZED RED HAT SERVICE PROVIDERS +REGARDING SERVICES AND ASSOCIATED PAYMENTS. + +This end user license agreement (“EULA”) governs the use of Red Hat Universal Base Image and associated software supporting such container(s) +and any related updates, source code, including the appearance, structure and organization (the “Programs”), regardless of the delivery mechanism. +If a Red Hat Universal Base Image is included in another Red Hat product, the EULA terms of such other Red Hat product will apply and supersede +this EULA. If a Red Hat Universal Base Image is included in a third party work, the terms of this EULA will continue to govern the Red Hat Universal +Base Image. + +1. License Grant. Subject to the terms of this EULA, Red Hat, Inc. (“Red Hat”) grants to you a perpetual, worldwide license to the Programs (each +of which may include multiple software components). With the exception of the Red Hat trademark identified in Section 2 below, each software +component is governed by a license that permits you to run, copy, modify, and redistribute (subject to certain obligations in some cases) the +software components. This EULA pertains solely to the Programs and does not limit your rights under, or grant you rights that supersede, the +license terms applicable to any particular component. The license terms applicable to each software component are provided in the source code +of that component. + +2. Intellectual Property Rights. The Programs and each of their components are owned by Red Hat and other licensors and are protected under +copyright law and other laws as applicable. Title to the Programs and any component shall remain with Red Hat and other licensors, subject to +the applicable license, excluding any independently developed and licensed work. The “Red Hat” trademark is a registered trademark of Red +Hat and its affiliates in the U.S. and other countries. Subject to Red Hat’s trademark usage guidelines (set forth at +http://www.redhat.com/about/corporate/trademark/), this EULA permits you to distribute the Programs that include the Red Hat trademark, +provided you do not make any statements on behalf of Red Hat, including but not limited to, stating or in any way suggesting (in any public, +private and/or confidential statement (whether written or verbal)) that Red Hat supports or endorses software built and delivered with a Red Hat +Universal Base Image(s) (such derivative works referred to as a “Red Hat Based Container Images”); provided if a Red Hat Based Container +Image is Red Hat Certified and deployed on a Red Hat supported configuration as set forth at https://access.redhat.com/articles/2726611 then +you may state that the Red Hat Universal Base Image is supported by Red Hat. You agree to include this unmodified EULA in all distributions of +container images sourced, built or otherwise derived from the Programs. If you modify the Red Hat Universal Base Image(s), you must remove +any Red Hat trademark(s) prior to any subsequent distribution. Any breach of this Section 2 is a material breach of the EULA and you may no +longer use and/or distribute the Red Hat trademark(s). Modifications to the software may corrupt the Programs. + +3. Limited Warranty. Except as specifically stated in this Section 3, a separate agreement with Red Hat, or a license for a particular component, +to the maximum extent permitted under applicable law, the Programs and the components are provided and licensed “as is” without +warranty of any kind, expressed or implied, including the implied warranties of merchantability, non-infringement or fitness for a +particular purpose. Neither Red Hat nor its affiliates warrant that the functions contained in the Programs will meet your requirements or that +the operation of the Programs will be entirely error free, appear or perform precisely as described in the accompanying documentation, or comply +with regulatory requirements. Red Hat warrants that the media on which the Programs and the components are provided will be free from defects +in materials and manufacture under normal use for a period of 30 days from the date of delivery to you. This warranty extends only to the party +that purchases subscription services for the supported configurations from Red Hat and/or its affiliates or a Red Hat authorized +distributor. + +4. Limitation of Remedies and Liability. To the maximum extent permitted by applicable law, your exclusive remedy under this EULA is to return +any defective media within 30 days of delivery along with a copy of your payment receipt and Red Hat, at its option, will replace it or refund the +money you paid for the media. To the maximum extent permitted under applicable law, under no circumstances will Red Hat, its affiliates, +any Red Hat authorized distributor, or the licensor of any component provided to you under this EULA be liable to you for any incidental +or consequential damages, including lost profits or lost savings arising out of the use or inability to use the Programs or any +component, even if Red Hat, its affiliates, an authorized distributor, and/or licensor has been advised of the possibility of such +damages. In no event shall Red Hat's or its affiliates’ liability, an authorized distributor’s liability or the liability of the licensor of a +component provided to you under this EULA exceed the amount that you paid to Red Hat for the media under this EULA. + +5. Export Control. As required by the laws of the United States and other countries, you represent and warrant that you: (a) understand that the +Programs and their components may be subject to export controls under the U.S. Commerce Department’s Export Administration Regulations +(“EAR”); (b) are not located in a prohibited destination country under the EAR or U.S. sanctions regulations (currently Cuba, Iran, North Korea, +Sudan, Syria, and the Crimea Region of Ukraine, subject to change as posted by the United States government); (c) will not export, re-export, or +transfer the Programs to any prohibited destination, persons or entities on the U.S. Bureau of Industry and Security Denied Parties List or Entity +List, or the U.S. Office of Foreign Assets Control list of Specially Designated Nationals and Blocked Persons, or any similar lists maintained by +other countries, without the necessary export license(s) or authorizations(s); (d) will not use or transfer the Programs for use in connection with +any nuclear, chemical or biological weapons, missile technology, or military end-uses where prohibited by an applicable arms embargo, unless +authorized by the relevant government agency by regulation or specific license; (e) understand and agree that if you are in the United States and +export or transfer the Programs to eligible end users, you will, to the extent required by EAR Section 740.17(e), submit semi-annual reports to +the Commerce Department’s Bureau of Industry and Security, which include the name and address (including country) of each transferee; and +(f) understand that countries including the United States may restrict the import, use, or export of encryption products (which may include the +Programs and the components) and agree that you shall be solely responsible for compliance with any such import, use, or export restrictions. + +6. Third Party Software. The Program may be provided with third party software programs subject to their own license terms. The license terms +either accompany the third party software programs or, in some instances, may be viewed at www.registry.redhat.com. If you do not agree to +abide by the applicable license terms for the third party software programs, then you may not install, distribute or use them. + +7. General. If any provision of this EULA is held to be unenforceable, the enforceability of the remaining provisions shall not be affected. Any claim, +controversy or dispute arising under or relating to this EULA shall be governed by the laws of the State of New York and of the United States, +without regard to any conflict of laws provisions. The rights and obligations of the parties to this EULA shall not be governed by the United +Nations Convention on the International Sale of Goods. + +Copyright © 2019 Red Hat, Inc. All rights reserved. “Red Hat,” is a registered trademark of Red Hat, Inc. All other trademarks are the property of their respective +owners + +Accessed from https://www.redhat.com/licenses/EULA_Red_Hat_Universal_Base_Image_English_20190422.pdf \ No newline at end of file