diff --git a/docs/04a-consumer-setup-source.md b/docs/04a-consumer-setup-source.md index 1dae7c1a..24fc8f1f 100644 --- a/docs/04a-consumer-setup-source.md +++ b/docs/04a-consumer-setup-source.md @@ -36,9 +36,9 @@ Save the .env file and exit the editor #### 4. Build and start the proxy-router ```bash ./build.sh -go run cmd/main.go +./bin/proxy-router ``` -After the iniial setup, you can execute `git pull` to get the latest updates and re-run the `./build.sh` and `go run cmd/main.go` to update the proxy-router with the latest changes. +After the iniial setup, you can execute `git pull` to get the latest updates and re-run the `./build.sh` and `./bin/proxy-router` to update the proxy-router with the latest changes. #### 5. Confirm that the build is successful and console should show similar to below after started (and listening on specified ports 8082 for Swagger API and 3333 for the proxy-router): diff --git a/proxy-router/Dockerfile b/proxy-router/Dockerfile index 6a25774a..f3581e27 100644 --- a/proxy-router/Dockerfile +++ b/proxy-router/Dockerfile @@ -1,23 +1,38 @@ +# Stage 1: Build FROM golang:1.22.3-alpine as builder +# Capture the Git tag and commit hash during build +ARG TAG_NAME ARG COMMIT +ENV TAG_NAME=$TAG_NAME ENV COMMIT=$COMMIT -WORKDIR /app +WORKDIR /app COPY . . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./build.sh&& \ -cp /bin/sh /app/sh && chmod +x /app/sh +# Build the Go binary (recommended for linux/amd64...for MacARM use buildx) +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ + TAG_NAME=$TAG_NAME COMMIT=$COMMIT ./build.sh && \ + cp /bin/sh /app/sh && chmod +x /app/sh + + # Multiplatform Build Notes: +# to support both amd64 and arm64, use Docker’s Buildx to create a multi-architecture image +# docker buildx create --use +# docker buildx build --platform linux/amd64,linux/arm64 -t proxy-router:latest . +# Stage 2: Final Image FROM scratch WORKDIR /app + +# Copy required files and binary COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /app/bin/proxy-router /usr/bin/ -# COPY --from=builder /usr/bin/dbus-launch /usr/bin/ -# COPY --from=builder /app/.env /app/.env + +# Optional Copy utilities from busybox image # COPY --from=busybox /bin /bin # COPY --from=busybox /lib /lib SHELL ["/bin/sh", "-c"] EXPOSE 3333 8082 + ENTRYPOINT ["proxy-router"] \ No newline at end of file diff --git a/proxy-router/build.sh b/proxy-router/build.sh index 6ac085b0..9067df06 100755 --- a/proxy-router/build.sh +++ b/proxy-router/build.sh @@ -1,8 +1,17 @@ #!/bin/sh -VERSION=${TAG_NAME:-0.1.0} -echo VERSION=$VERSION +# Check if TAG_NAME is set; if not, use the latest Git tag or fallback to 0.1.0 +if [ -z "$TAG_NAME" ]; then + TAG_NAME=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.1.0") + if [ "$TAG_NAME" = "0.1.0" ]; then + echo "Warning: No Git tags found. Defaulting to TAG_NAME=$TAG_NAME" + else + echo "Using latest Git tag: $TAG_NAME" + fi +fi +VERSION=$TAG_NAME +echo VERSION=$VERSION # if commit is not set, use the latest commit if [ -z "$COMMIT" ]; then COMMIT=$(git rev-parse HEAD)