Explorar o código

test out container building (#3081)

Signed-off-by: Alex Meijer <alexander.meijer@ibm.com>
Alex Meijer hai 1 ano
pai
achega
66879963f3

+ 56 - 0
.github/actions/build-container/action.yaml

@@ -0,0 +1,56 @@
+name: 'Build and Publish Container'
+description: 'Build and publish container'
+
+inputs:
+    actor:
+        required: true
+        type: string
+    image_tag:
+        required: true
+        type: string
+    release_version:
+        required: true
+        type: string
+    GITHUB_TOKEN:
+        required: true
+        type: string
+
+runs:
+    using: "composite"
+    steps:
+      - name: Log into registry ghcr.io
+        uses: docker/login-action@v3
+        with:
+          registry: ghcr.io
+          username: ${{ inputs.actor }}
+          password: ${{ inputs.GITHUB_TOKEN }}
+
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v3
+        with:
+          buildkitd-flags: --debug
+
+      - name: Install Go
+        uses: actions/setup-go@v5
+        with:
+          go-version: 'stable'
+
+      - name: Set up just
+        uses: extractions/setup-just@v2
+
+      ## Install manifest-tool, which is required to combine multi-arch images
+      ## https://github.com/estesp/manifest-tool
+      - name: Install manifest-tool
+        shell: bash
+        run: |
+          mkdir -p manifest-tool
+          pushd manifest-tool
+          wget -q https://github.com/estesp/manifest-tool/releases/download/v2.0.8/binaries-manifest-tool-2.0.8.tar.gz
+          tar -xzf binaries-manifest-tool-2.0.8.tar.gz
+          cp manifest-tool-linux-amd64 manifest-tool
+          echo "$(pwd)" >> $GITHUB_PATH
+
+      - name: Build and push (multiarch) OpenCost
+        shell: bash
+        run: |
+          just build '${{ inputs.image_tag }}' '${{ inputs.release_version }}'

+ 43 - 0
.github/workflows/build-and-publish-develop.yml

@@ -0,0 +1,43 @@
+name: Build and Publish Develop
+
+on:
+  push:
+    branches:
+      - develop
+
+concurrency:
+  group: build-opencost-develop
+  cancel-in-progress: false
+
+env:
+  # Use docker.io for Docker Hub if empty
+  REGISTRY: ghcr.io
+
+jobs:
+  build-and-publish-opencost:
+    runs-on: ubuntu-latest
+    permissions:
+      contents: read
+      packages: write
+    steps:
+      - name: Checkout Repo
+        uses: actions/checkout@v4
+      - name: Set SHA
+        id: sha
+        run: |
+          echo "OC_SHORTHASH=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
+
+      - name: Set OpenCost Image Tags
+        id: tags
+        run: |
+          echo "IMAGE_TAG=ghcr.io/${{ github.repository_owner }}/opencost:develop-${{ steps.sha.outputs.OC_SHORTHASH }}" >> $GITHUB_OUTPUT
+
+      - name: Build and publish container
+        uses: ./.github/actions/build-container 
+        with:
+          actor: ${{ github.actor }}
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          image_tag: ${{ steps.tags.outputs.IMAGE_TAG }}
+          release_version: develop-${{ steps.sha.outputs.OC_SHORTHASH }}
+
+

+ 12 - 37
.github/workflows/build-and-publish-release.yml

@@ -17,8 +17,6 @@ concurrency:
 env:
   # Use docker.io for Docker Hub if empty
   REGISTRY: ghcr.io
-  # github.repository as <account>/<repo>
-  IMAGE_NAME: ${{ github.repository }}
 
 jobs:
   build-and-publish-opencost:
@@ -63,23 +61,11 @@ jobs:
         uses: actions/checkout@v4
         with:
           ref: '${{ steps.branch.outputs.BRANCH_NAME }}'
-          path: ./opencost
 
       - name: Set SHA
         id: sha
         run: |
-          pushd ./opencost
           echo "OC_SHORTHASH=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
-          popd
-
-      # Login against a Docker registry except on PR
-      # https://github.com/docker/login-action
-      - name: Log into registry ${{ env.REGISTRY }}
-        uses: docker/login-action@v3
-        with:
-          registry: ${{ env.REGISTRY }}
-          username: ${{ github.actor }}
-          password: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Set OpenCost Image Tags
         id: tags
@@ -88,37 +74,26 @@ jobs:
           echo "IMAGE_TAG_LATEST=ghcr.io/${{ github.repository_owner }}/opencost:latest" >> $GITHUB_OUTPUT
           echo "IMAGE_TAG_VERSION=ghcr.io/${{ github.repository_owner }}/opencost:${{ steps.version_number.outputs.RELEASE_VERSION }}" >> $GITHUB_OUTPUT
 
-      - name: Set up Docker Buildx
-        uses: docker/setup-buildx-action@v3
+      - name: Build and publish container
+        uses: ./.github/actions/build-container 
         with:
-          buildkitd-flags: --debug
+          actor: ${{ github.actor }}
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          image_tag: ${{ steps.tags.outputs.IMAGE_TAG }}
+          release_version: ${{ steps.version_number.outputs.RELEASE_VERSION }}
 
-      - name: Install Go
-        uses: actions/setup-go@v5
+      - name: Log into registry ${{ env.REGISTRY }}
+        uses: docker/login-action@v3
         with:
-          go-version: 'stable'
-
-      - name: Set up just
-        uses: extractions/setup-just@v2
+            registry: ${{ env.REGISTRY }}
+            username: ${{ github.actor }}
+            password: ${{ secrets.GITHUB_TOKEN }}
 
       - name: Install crane
         uses: imjasonh/setup-crane@v0.4
 
-      ## Install manifest-tool, which is required to combine multi-arch images
-      ## https://github.com/estesp/manifest-tool
-      - name: Install manifest-tool
-        run: |
-          mkdir -p manifest-tool
-          pushd manifest-tool
-          wget -q https://github.com/estesp/manifest-tool/releases/download/v2.0.8/binaries-manifest-tool-2.0.8.tar.gz
-          tar -xzf binaries-manifest-tool-2.0.8.tar.gz
-          cp manifest-tool-linux-amd64 manifest-tool
-          echo "$(pwd)" >> $GITHUB_PATH
-
-      - name: Build and push (multiarch) OpenCost
-        working-directory: ./opencost
+      - name: Copy tags
         run: |
-          just build '${{ steps.tags.outputs.IMAGE_TAG }}' '${{ steps.version_number.outputs.RELEASE_VERSION }}'
           crane copy '${{ steps.tags.outputs.IMAGE_TAG }}' '${{ steps.tags.outputs.IMAGE_TAG_LATEST }}'
           crane copy '${{ steps.tags.outputs.IMAGE_TAG }}' '${{ steps.tags.outputs.IMAGE_TAG_VERSION }}'