diff --git a/.github/workflows/upstream-docker-release.yml b/.github/workflows/upstream-docker-release.yml index cc798ce..73f0186 100644 --- a/.github/workflows/upstream-docker-release.yml +++ b/.github/workflows/upstream-docker-release.yml @@ -22,22 +22,12 @@ permissions: write-all # Necessary for the generate-build-provenance action with jobs: image: - name: Build Image - uses: OpenCHAMI/github-actions/.github/workflows/docker-build-release.yml@v3.3 + name: Build & Push Multi-arch Image + uses: OpenCHAMI/github-actions/.github/workflows/docker-build-release.yml@v3.4 with: fetch-depth: 1 registry-name: ghcr.io/openchami/pcs cgo-enabled: 1 - platforms: "linux/amd64" - docker-file: "Dockerfile.build" - image_arm: - name: Build ARM Image - uses: OpenCHAMI/github-actions/.github/workflows/docker-build-release.yml@v3.3 - with: - fetch-depth: 1 - registry-name: ghcr.io/openchami/pcs - cgo-enabled: 1 - additional-env-vars: | - CC=aarch64-linux-gnu-gcc - platforms: "linux/arm64" + platforms: "linux/amd64,linux/arm64" docker-file: "Dockerfile.build" + image-description: "OpenCHAMI Power Control Service" diff --git a/Dockerfile.build b/Dockerfile.build index b067aba..5f5a9ab 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -20,8 +20,9 @@ RUN printf "Building for TARGETPLATFORM=${TARGETPLATFORM}" \ && printf "With 'uname -s': $(uname -s) and 'uname -m': $(uname -m)" # Install cross-compilation dependencies +# Install build-essential for native compilation and aarch64 cross-compiler for ARM builds RUN apt-get update && \ - apt-get install -y g++-aarch64-linux-gnu && \ + apt-get install -y build-essential g++-aarch64-linux-gnu && \ rm -rf /var/lib/apt/lists/* WORKDIR /workspace @@ -52,18 +53,37 @@ ARG CGO_ENABLED RUN mkdir bin -# Use shell parameter expansion to add -ldflags if CC is set to specify the external linker -RUN CGO_ENABLED="${CGO_ENABLED}" \ - GOOS=linux \ - GOARCH="${TARGETARCH}" \ - CC="${CC}" \ - GO111MODULE=on \ - go build ${CC:+-ldflags="-extld=$CC"} -v -o bin/power-control ./cmd/power-control +# Build the binary with appropriate cross-compilation settings +# Set CC based on target architecture (don't rely on build args for multi-arch builds) +RUN set -ex && \ + echo "Building for TARGETARCH=${TARGETARCH}" && \ + export CGO_ENABLED="${CGO_ENABLED}" && \ + export GOOS=linux && \ + export GOARCH="${TARGETARCH}" && \ + export GO111MODULE=on && \ + if [ "${TARGETARCH}" = "arm64" ]; then \ + echo "Using ARM64 cross-compiler" && \ + export CC="aarch64-linux-gnu-gcc" && \ + echo "CC is now: ${CC}" && \ + go build -ldflags="-extld=${CC}" -v -o bin/power-control ./cmd/power-control; \ + else \ + echo "Using native amd64 compiler" && \ + echo "Building without external CC" && \ + go build -v -o bin/power-control ./cmd/power-control; \ + fi ### release image # TODO seems kinda off that we don't pin wolfi or tini, but whatever FROM chainguard/wolfi-base:latest AS main +# OCI labels for better container metadata +LABEL org.opencontainers.image.title="OpenCHAMI Power Control Service" \ + org.opencontainers.image.description="OpenCHAMI Power Control Service" \ + org.opencontainers.image.vendor="OpenCHAMI" \ + org.opencontainers.image.source="https://github.com/OpenCHAMI/power-control" \ + org.opencontainers.image.documentation="https://github.com/OpenCHAMI/power-control/blob/main/README.md" \ + org.opencontainers.image.licenses="MIT" + RUN set -ex \ && apk update \ && apk add --no-cache tini \ diff --git a/README.md b/README.md index 8dbbbbd..79410c2 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,3 @@ -# Power Control Service(pcs) +# Power Control Service (pcs) -This is a fork of the original PCS code from [Cray-HPE/hms-power-control](https://github.com/Cray-HPE/hms-power-control), suitable only for experimentation and demo purposes at this point. - -## Build/Install with goreleaser - -This project uses [GoReleaser](https://goreleaser.com/) to automate releases and include additional build metadata such as commit info, build time, and versioning. Below is a guide on how to set up and build the project locally using GoReleaser. - -### Environment Variables - -To include detailed build metadata, ensure the following environment variables are set: - -* __GIT_STATE__: Indicates whether there are uncommitted changes in the working directory. Set to clean if the repository is clean, or dirty if there are uncommitted changes. -* __BUILD_HOST__: The hostname of the machine where the build is being performed. -* __GO_VERSION__: The version of Go used for the build. GoReleaser uses this to ensure consistent Go versioning information. -* __BUILD_USER__: The username of the person or system performing the build. - -Set all the environment variables with: -```bash -export GIT_STATE=$(if git diff-index --quiet HEAD --; then echo 'clean'; else echo 'dirty'; fi) -export BUILD_HOST=$(hostname) -export GO_VERSION=$(go version | awk '{print $3}') -export BUILD_USER=$(whoami) -``` - -### Building Locally with GoReleaser - -Once the environment variables are set, you can build the project locally using GoReleaser in snapshot mode (to avoid publishing). - - -Follow the installation instructions from [GoReleaser’s documentation](https://goreleaser.com/install/). - -1. Run GoReleaser in snapshot mode with the --snapshot flag to create a local build without attempting to release it: - ```bash - goreleaser release --snapshot --clean - ``` -2. Check the dist/ directory for the built binaries, which will include the metadata from the environment variables. You can inspect the binary output to confirm that the metadata was correctly embedded. - -__NOTE__ If you see errors, ensure that you are using the same version of goreleaser that is being used in the [Release Action](.github/workflows/Release.yml) \ No newline at end of file +This is a fork of the original PCS code from [Cray-HPE/hms-power-control](https://github.com/Cray-HPE/hms-power-control). It adds support for Postgres operation. \ No newline at end of file