Просмотр исходного кода

Add Podman command in justfile and document it in contributing.md (#3938)

Signed-off-by: Alan Rodrigues <alanrodrigues@Alans-MacBook-Pro.local>
Signed-off-by: Alan Rodrigues <alanr5691@yahoo.com>
Co-authored-by: Alan Rodrigues <alanrodrigues@Alans-MacBook-Pro.local>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Alan Rodrigues 2 недель назад
Родитель
Сommit
389a5bd699
2 измененных файлов с 58 добавлено и 2 удалено
  1. 27 1
      CONTRIBUTING.md
  2. 31 1
      justfile

+ 27 - 1
CONTRIBUTING.md

@@ -28,12 +28,14 @@ Follow these steps to build the OpenCost cost-model and UI from source and
 deploy. The provided build tooling is natively multi-architecture (built images
 will run on both AMD64 and ARM64 clusters).
 
+### Using Docker
+
 Dependencies:
 1. Docker (with `buildx`)
 2. [just](https://github.com/casey/just) (if you don't want to install it , Just read the `justfile` and run the commands manually)
 3. Multi-arch `buildx` builders set up via https://github.com/tonistiigi/binfmt
 4. `manifest-tool` via https://github.com/estesp/manifest-tool
-4. `npm` (if you want to build the UI)
+5. `npm` (if you want to build the UI)
 
 ### Build the backend
 
@@ -41,6 +43,30 @@ Dependencies:
 2. Edit the [pulled image](https://github.com/opencost/opencost/blob/develop/kubernetes/opencost.yaml#L145) in the `kubernetes/opencost.yaml` to `<repo>/opencost:<tag>`
 3. Set [this environment variable](https://github.com/opencost/opencost/blob/develop/kubernetes/opencost.yaml#L155) to the address of your Prometheus server
 
+### Using Podman
+
+If you prefer Podman over Docker, use the `build-podman` recipe instead. Podman's
+multi-arch manifest support is built in — no `manifest-tool` required.
+
+Dependencies:
+1. [Podman](https://podman.io/docs/installation) (v4+)
+2. [just](https://github.com/casey/just)
+
+Build and push a multi-arch image:
+
+```bash
+just build-podman "<repo>/opencost:<tag>" "<release-version>"
+# e.g.
+just build-podman myregistry.io/opencost:latest 1.0.0
+```
+
+This will:
+1. Compile `costmodel-amd64` and `costmodel-arm64` binaries with version metadata embedded
+2. Build and push `<IMAGE_TAG>-amd64` and `<IMAGE_TAG>-arm64` images using `Dockerfile.cross`
+3. Create a multi-arch manifest at `<IMAGE_TAG>` combining both and push it to the registry
+
+> **Note:** make sure you are logged in to your registry (`podman login <registry>`) before running the build.
+
 ### Build the frontend
 1. `cd ui && just build "<repo>/opencost-ui:<tag>"`
 2. Edit the [pulled image](https://github.com/opencost/opencost/blob/develop/kubernetes/opencost.yaml#L162) in the `kubernetes/opencost.yaml` to `<repo>/opencost-ui:<tag>`

+ 31 - 1
justfile

@@ -85,7 +85,7 @@ build-binary VERSION=version:
            -X github.com/opencost/opencost/core/pkg/version.GitCommit={{commit}}" \
         -o ./costmodel-arm64
 
-# Build and push a multi-arch Docker image
+# Build and push a multi-arch image using Docker
 build IMAGE_TAG RELEASE_VERSION: (build-binary RELEASE_VERSION)
     docker buildx build \
         --rm \
@@ -116,6 +116,36 @@ build IMAGE_TAG RELEASE_VERSION: (build-binary RELEASE_VERSION)
         --template {{IMAGE_TAG}}-ARCH \
         --target {{IMAGE_TAG}}
 
+# Build and push a multi-arch image using Podman
+build-podman IMAGE_TAG RELEASE_VERSION: (build-binary RELEASE_VERSION)
+    podman build \
+        --rm \
+        --platform "linux/amd64" \
+        -f 'Dockerfile.cross' \
+        --build-arg binarypath=./cmd/costmodel/costmodel-amd64 \
+        --build-arg version={{RELEASE_VERSION}} \
+        --build-arg commit={{commit}} \
+        -t {{IMAGE_TAG}}-amd64 \
+        .
+    podman push {{IMAGE_TAG}}-amd64
+
+    podman build \
+        --rm \
+        --platform "linux/arm64" \
+        -f 'Dockerfile.cross' \
+        --build-arg binarypath=./cmd/costmodel/costmodel-arm64 \
+        --build-arg version={{RELEASE_VERSION}} \
+        --build-arg commit={{commit}} \
+        -t {{IMAGE_TAG}}-arm64 \
+        .
+    podman push {{IMAGE_TAG}}-arm64
+
+    podman manifest create {{IMAGE_TAG}} \
+        {{IMAGE_TAG}}-amd64 \
+        {{IMAGE_TAG}}-arm64
+    podman manifest push --all {{IMAGE_TAG}}
+    podman manifest rm {{IMAGE_TAG}}
+
 validate-protobuf:
     ./generate.sh
     git diff --exit-code