Jaypore CI

> Jaypore CI: Minimal, Offline, Local CI system.
Log | Files | Refs | README

build_binary.sh (1488B)


      1 #!/bin/bash
      2 set -euo pipefail
      3 
      4 # ---------------------------------------------------------------------------
      5 # Build a static git-jci binary for the requested platform.
      6 #
      7 # Required environment variables (set by the calling docker run command):
      8 #   GOOS                - Target OS  (linux | windows | darwin)
      9 #   GOARCH              - Target arch (amd64 | arm64 | arm)
     10 #   OUTPUT_BINARY_NAME  - Final filename placed in ${OUTPUT_DIR}
     11 #                         e.g. git-jci-linux-amd64  /  git-jci-windows-amd64.exe
     12 #
     13 # Optional:
     14 #   GOARM               - ARM version for GOARCH=arm  (default: 7)
     15 # ---------------------------------------------------------------------------
     16 
     17 REPO_DIR="/tmp/repo"
     18 OUTPUT_DIR="${REPO_DIR}/bin"
     19 ENTRY_POINT="./cmd/git-jci"
     20 
     21 # Ensure required vars are present
     22 : "${GOOS:?GOOS must be set}"
     23 : "${GOARCH:?GOARCH must be set}"
     24 : "${OUTPUT_BINARY_NAME:?OUTPUT_BINARY_NAME must be set}"
     25 
     26 GOARM="${GOARM:-7}"
     27 
     28 cd "${REPO_DIR}"
     29 
     30 echo "[${OUTPUT_BINARY_NAME}] Downloading dependencies..."
     31 go mod download
     32 
     33 echo "[${OUTPUT_BINARY_NAME}] Building for GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM}..."
     34 mkdir -p "${OUTPUT_DIR}"
     35 
     36 CGO_ENABLED=0 \
     37 GOOS="${GOOS}" \
     38 GOARCH="${GOARCH}" \
     39 GOARM="${GOARM}" \
     40 go build \
     41     -buildvcs=false \
     42     -tags "netgo osusergo" \
     43     -ldflags "-s -w -extldflags '-static'" \
     44     -o "${OUTPUT_DIR}/${OUTPUT_BINARY_NAME}" \
     45     "${ENTRY_POINT}"
     46 
     47 echo "[${OUTPUT_BINARY_NAME}] Binary built successfully: ${OUTPUT_DIR}/${OUTPUT_BINARY_NAME}"