Periodic Gateway Build #45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Periodic Gateway Build | |
| on: | |
| schedule: | |
| - cron: '0 * * * *' | |
| workflow_dispatch: | |
| jobs: | |
| hourly-build: | |
| name: Periodic Gateway Build | |
| runs-on: ubuntu-latest | |
| # BUILDX_BUILDER will be detected and exported by the initiation step | |
| steps: | |
| # ------------------------------------------------------------ | |
| # Checkout MUST be first | |
| # ------------------------------------------------------------ | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # ------------------------------------------------------------ | |
| # Initialize all log files (guarantee existence) | |
| # ------------------------------------------------------------ | |
| - name: Initialize log files | |
| run: | | |
| touch \ | |
| 1-initiate.log \ | |
| 2-gw-build.log \ | |
| 3-cli-build.log \ | |
| 4-prepare-dir.log \ | |
| 5-ap-gw-image-build.log \ | |
| docker.log | |
| # ------------------------------------------------------------ | |
| # 1. Initiation | |
| # ------------------------------------------------------------ | |
| - name: Initiate environment | |
| run: | | |
| set -o pipefail | |
| { | |
| echo "== Repository ==" | |
| git rev-parse HEAD | |
| echo "== Go version ==" | |
| go version || true | |
| echo "== Docker ==" | |
| docker version | |
| echo "== Buildx setup ==" | |
| # Prefer an active docker-backed builder. Strategy: | |
| # 1. If there's an active builder (starred), and it's docker-backed, use it. | |
| # 2. Otherwise, find any existing docker-backed builder and use it. | |
| # 3. Otherwise, attempt to create `docker-local` and use it only if creation succeeded. | |
| # 4. If none of the above work, fall back to whatever builder is active (do not attempt to `use` a non-existent name). | |
| ACTIVE_BUILDER=$(docker buildx ls 2>/dev/null | awk '/\*/{print $1}' | sed 's/\*//g' | head -n1 || true) | |
| CHOSEN_BUILDER="" | |
| if [ -n "${ACTIVE_BUILDER}" ] && docker buildx inspect "${ACTIVE_BUILDER}" >/dev/null 2>&1 && docker buildx inspect "${ACTIVE_BUILDER}" | grep -qi 'Driver: *docker'; then | |
| CHOSEN_BUILDER="${ACTIVE_BUILDER}" | |
| echo "Active docker-backed builder detected: ${CHOSEN_BUILDER}" | |
| else | |
| # find any docker-backed builder | |
| for b in $(docker buildx ls 2>/dev/null | tail -n +2 | awk '{print $1}' | sed 's/\*//g'); do | |
| if docker buildx inspect "$b" >/dev/null 2>&1 && docker buildx inspect "$b" | grep -qi 'Driver: *docker'; then | |
| CHOSEN_BUILDER="$b" | |
| echo "Found existing docker-backed builder: ${CHOSEN_BUILDER}" | |
| break | |
| fi | |
| done | |
| fi | |
| if [ -z "${CHOSEN_BUILDER}" ]; then | |
| echo "No existing docker-backed builder found; attempting to create docker-local" | |
| if docker buildx create --name docker-local --driver docker >/dev/null 2>&1; then | |
| CHOSEN_BUILDER="docker-local" | |
| echo "Created docker-local builder" | |
| else | |
| echo "Could not create docker-local builder; will not call 'docker buildx use' for a missing builder" | |
| fi | |
| fi | |
| # Only call `docker buildx use` if the chosen builder actually exists. | |
| if [ -n "${CHOSEN_BUILDER}" ] && docker buildx inspect "${CHOSEN_BUILDER}" >/dev/null 2>&1; then | |
| docker buildx use "${CHOSEN_BUILDER}" | |
| else | |
| echo "Proceeding without switching builder (using runner's default)" | |
| fi | |
| docker buildx inspect --bootstrap | |
| docker buildx ls | |
| # Determine and export the builder for later steps. | |
| CURRENT_BUILDER=$(docker buildx ls 2>/dev/null | awk '/\*/{print $1}' | sed 's/\*//g' | head -n1 || true) | |
| if [ -z "${CURRENT_BUILDER}" ]; then | |
| if [ -n "${CHOSEN_BUILDER}" ]; then | |
| CURRENT_BUILDER="${CHOSEN_BUILDER}" | |
| elif docker buildx inspect docker-local >/dev/null 2>&1; then | |
| CURRENT_BUILDER="docker-local" | |
| else | |
| for b in $(docker buildx ls 2>/dev/null | tail -n +2 | awk '{print $1}' | sed 's/\*//g'); do | |
| if docker buildx inspect "$b" >/dev/null 2>&1 && docker buildx inspect "$b" | grep -qi 'Driver: *docker'; then | |
| CURRENT_BUILDER="$b" | |
| break | |
| fi | |
| done | |
| fi | |
| fi | |
| if [ -n "${CURRENT_BUILDER}" ]; then | |
| echo "BUILDX_BUILDER=${CURRENT_BUILDER}" >> $GITHUB_ENV | |
| echo "Exported BUILDX_BUILDER=${CURRENT_BUILDER}" | |
| else | |
| echo "BUILDX_BUILDER=" >> $GITHUB_ENV | |
| echo "No docker-backed builder available; subsequent steps may use runner default" | |
| fi | |
| } 2>&1 | tee 1-initiate.log || true | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.25' | |
| # ------------------------------------------------------------ | |
| # 2. Build gateway | |
| # ------------------------------------------------------------ | |
| - name: Build gateway | |
| working-directory: ./gateway | |
| run: | | |
| set -o pipefail | |
| (make build) 2>&1 | tee "$GITHUB_WORKSPACE/2-gw-build.log" | |
| # ------------------------------------------------------------ | |
| # 3. Build CLI | |
| # ------------------------------------------------------------ | |
| - name: Build CLI | |
| working-directory: ./cli/src | |
| run: | | |
| set -o pipefail | |
| (make build-all) 2>&1 | tee "$GITHUB_WORKSPACE/3-cli-build.log" | |
| # ------------------------------------------------------------ | |
| # 4. Prepare run directory | |
| # ------------------------------------------------------------ | |
| - name: Prepare my-gw run directory | |
| run: | | |
| set -o pipefail | |
| { | |
| rm -rf my-gw | |
| mkdir my-gw | |
| if [ -f cli/src/build/ap-linux-amd64 ]; then | |
| cp cli/src/build/ap-linux-amd64 my-gw/ap | |
| else | |
| cp cli/src/build/ap-linux-amd64-v* my-gw/ap | |
| fi | |
| chmod +x my-gw/ap | |
| if [ -f cli/src/tests/resources/simple-policy-manifest.yaml ]; then | |
| cp cli/src/tests/resources/simple-policy-manifest.yaml my-gw/policy-manifest.yaml | |
| fi | |
| } 2>&1 | tee 4-prepare-dir.log | |
| # ------------------------------------------------------------ | |
| # 5. Gateway image build + docker.log extraction | |
| # ------------------------------------------------------------ | |
| - name: Build gateway image | |
| working-directory: ./my-gw | |
| env: | |
| CI: "" | |
| WSO2AP_GW_USERNAME: ${{ secrets.WSO2AP_GW_USERNAME || '' }} | |
| WSO2AP_GW_PASSWORD: ${{ secrets.WSO2AP_GW_PASSWORD || '' }} | |
| run: | | |
| set -o pipefail | |
| REAL_DOCKER_LOG="$HOME/.wso2ap/.tmp/gateway-image-build/logs/docker.log" | |
| mkdir -p "$(dirname "$REAL_DOCKER_LOG")" | |
| set -o pipefail | |
| # (removed background tailing - will copy logs after build instead) | |
| # Run the build and capture stdout/stderr into the workspace build log. | |
| (./ap gateway image build) 2>&1 | tee "$GITHUB_WORKSPACE/5-ap-gw-image-build.log" | |
| BUILD_RC=${PIPESTATUS[0]} | |
| # Post-build diagnostics: list/log sizes/stat to help debug missing files | |
| LOG_DIR="$(dirname "$REAL_DOCKER_LOG")" | |
| echo "=== DIAGNOSTICS: list $LOG_DIR ===" >> "$GITHUB_WORKSPACE/5-ap-gw-image-build.log" 2>&1 | |
| ls -la "$LOG_DIR" >> "$GITHUB_WORKSPACE/5-ap-gw-image-build.log" 2>&1 || true | |
| echo "=== DIAGNOSTICS: stat $REAL_DOCKER_LOG ===" >> "$GITHUB_WORKSPACE/5-ap-gw-image-build.log" 2>&1 | |
| stat "$REAL_DOCKER_LOG" >> "$GITHUB_WORKSPACE/5-ap-gw-image-build.log" 2>&1 || true | |
| echo "=== DIAGNOSTICS: du -h $LOG_DIR ===" >> "$GITHUB_WORKSPACE/5-ap-gw-image-build.log" 2>&1 | |
| du -h "$LOG_DIR" >> "$GITHUB_WORKSPACE/5-ap-gw-image-build.log" 2>&1 || true | |
| # Copy any .log files from the real log dir into the workspace (try normal copy, then sudo if necessary) | |
| if [ -d "$LOG_DIR" ]; then | |
| mkdir -p "$GITHUB_WORKSPACE/.wso2ap/.tmp/gateway-image-build/logs" | |
| for f in "$LOG_DIR"/*.log; do | |
| [ -e "$f" ] || continue | |
| cp "$f" "$GITHUB_WORKSPACE/.wso2ap/.tmp/gateway-image-build/logs/" 2>>"$GITHUB_WORKSPACE/5-ap-gw-image-build.log" || ( | |
| sudo cp "$f" "$GITHUB_WORKSPACE/.wso2ap/.tmp/gateway-image-build/logs/" 2>>"$GITHUB_WORKSPACE/5-ap-gw-image-build.log" || echo "copy failed for $f" >>"$GITHUB_WORKSPACE/5-ap-gw-image-build.log" | |
| ) | |
| done | |
| # Also copy the primary docker.log into workspace root for convenience | |
| if [ -f "$REAL_DOCKER_LOG" ]; then | |
| cp "$REAL_DOCKER_LOG" "$GITHUB_WORKSPACE/docker.log" 2>>"$GITHUB_WORKSPACE/5-ap-gw-image-build.log" || sudo cp "$REAL_DOCKER_LOG" "$GITHUB_WORKSPACE/docker.log" 2>>"$GITHUB_WORKSPACE/5-ap-gw-image-build.log" || true | |
| fi | |
| fi | |
| # (no background tail to kill) | |
| # Exit with the build return code so failures are visible | |
| if [ "${BUILD_RC}" -ne 0 ]; then | |
| echo "ap gateway image build failed (rc=${BUILD_RC})" >&2 | |
| exit ${BUILD_RC} | |
| fi | |
| # ------------------------------------------------------------ | |
| # Upload logs ALWAYS | |
| # ------------------------------------------------------------ | |
| - name: Upload logs | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: gateway-build-logs | |
| path: | | |
| 1-initiate.log | |
| 2-gw-build.log | |
| 3-cli-build.log | |
| 4-prepare-dir.log | |
| 5-ap-gw-image-build.log | |
| docker.log |