diff --git a/.github/workflows/build-base-images.yml b/.github/workflows/build-base-images.yml index 1856d43..c2cf1d5 100644 --- a/.github/workflows/build-base-images.yml +++ b/.github/workflows/build-base-images.yml @@ -51,7 +51,7 @@ jobs: strategy: matrix: image: - - { name: go-base, file: deploy/base-images/go-base.Dockerfile } + - { name: go-runtime, file: deploy/base-images/go-runtime.Dockerfile } - { name: node-builder, file: deploy/base-images/node-builder.Dockerfile } - { name: node-runtime, file: deploy/base-images/node-runtime.Dockerfile } - { name: openresty-geoip, file: deploy/base-images/openresty-geoip.Dockerfile } diff --git a/.github/workflows/build-service-images.yml b/.github/workflows/build-service-images.yml index a2705ed..33ed07e 100644 --- a/.github/workflows/build-service-images.yml +++ b/.github/workflows/build-service-images.yml @@ -7,6 +7,9 @@ on: description: "Push service images instead of local builds" type: boolean default: true + go_runtime_digest: + type: string + default: "" postgres_runtime_digest: type: string default: "" @@ -35,8 +38,7 @@ permissions: env: REGISTRY: ghcr.io - ORG: cloudneutral-lab - BASE_ORG: cloud-neutral-toolkit + ORG: cloud-neutral-toolkit jobs: build-service: @@ -52,20 +54,6 @@ jobs: steps: - uses: actions/checkout@v4 - # ----------------------------- - # Lint per-language - # ----------------------------- - - name: Lint - working-directory: ${{ matrix.service.context }} - run: | - if [ -f package.json ]; then - corepack enable - pnpm install --frozen-lockfile - pnpm lint || exit 1 - elif [ -f go.mod ]; then - go vet ./... - fi - # ----------------------------- # Login # ----------------------------- @@ -78,15 +66,11 @@ jobs: # ----------------------------- # Metadata # ----------------------------- - - uses: docker/metadata-action@v5 + - name: Generate Auto Tags id: meta + uses: ./.github/actions/auto-tag with: - images: ${{ env.REGISTRY }}/${{ env.ORG }}/${{ matrix.service.name }} - tags: | - type=sha - type=ref,event=branch - type=ref,event=tag - type=raw,value=latest + image: ${{ env.REGISTRY }}/${{ env.ORG }}/${{ matrix.image.name }} - uses: docker/setup-qemu-action@v3 - uses: docker/setup-buildx-action@v3 @@ -104,8 +88,7 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | - GO_BUILDER_IMAGE=${{ env.REGISTRY }}/${{ env.ORG }}/go-builder@${{ inputs.node_builder_digest }} - GO_RUNTIME_IMAGE=${{ env.REGISTRY }}/${{ env.ORG }}/go-runtime@${{ inputs.node_runtime_digest }} + GO_BASE_IMAGE=${{ env.REGISTRY }}/${{ env.ORG }}/go-runtime@${{ inputs.go_runtime_digest }} NODE_BUILDER_IMAGE=${{ env.REGISTRY }}/${{ env.ORG }}/node-builder@${{ inputs.node_builder_digest }} NODE_RUNTIME_IMAGE=${{ env.REGISTRY }}/${{ env.ORG }}/node-runtime@${{ inputs.node_runtime_digest }} OPENRESTY_GEOIP_IMAGE=${{ env.REGISTRY }}/${{ env.ORG }}/openresty-geoip@${{ inputs.openresty_geoip_digest }} diff --git a/account/Dockerfile b/account/Dockerfile index cf0e672..ece307e 100644 --- a/account/Dockerfile +++ b/account/Dockerfile @@ -2,18 +2,22 @@ ARG GO_BASE_IMAGE -FROM ${GO_BUILDER_IMAGE} AS builder +FROM ${GO_BASE_IMAGE} AS builder WORKDIR /src +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates make \ + && rm -rf /var/lib/apt/lists/* COPY go.mod go.sum ./ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/accountsvc ./account/cmd/accountsvc +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/account ./account/cmd/account # PROD Image -FROM ${GO_RUNTIME_IMAGE} AS runtime +FROM ${GO_BASE_IMAGE} AS runtime + ENV CONFIG_PATH=/etc/xcontrol/account/account.yaml \ PORT=8080 @@ -22,7 +26,7 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* WORKDIR /app -COPY --from=builder /out/accountsvc /usr/local/bin/accountsvc +COPY --from=builder /out/account /usr/local/bin/account COPY account/config/account.yaml /etc/xcontrol/account/account.yaml COPY account-entrypoint.sh /usr/local/bin/account-entrypoint.sh RUN chmod +x /usr/local/bin/account-entrypoint.sh diff --git a/deploy/base-images/go-base.Dockerfile b/deploy/base-images/go-runtime.Dockerfile similarity index 100% rename from deploy/base-images/go-base.Dockerfile rename to deploy/base-images/go-runtime.Dockerfile diff --git a/rag-server/Dockerfile b/rag-server/Dockerfile index 800f2a0..44fa591 100644 --- a/rag-server/Dockerfile +++ b/rag-server/Dockerfile @@ -1,5 +1,7 @@ # Multi-stage production build for the RAG server -FROM golang:1.23 AS builder +ARG GO_BASE_IMAGE +FROM ${GO_BASE_IMAGE} AS builder + WORKDIR /src COPY go.mod go.sum ./ @@ -8,53 +10,20 @@ COPY . . RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/xcontrol-rag ./rag-server/cmd/xcontrol-server -FROM debian:12-slim AS runtime -ENV CONFIG_PATH=/etc/xcontrol/rag-server/server.yaml \ - PORT=8090 +FROM ${GO_BASE_IMAGE} AS runtime + +ENV CONFIG_PATH=/etc/xcontrol/rag-server.yaml PORT=8090 RUN apt-get update \ && apt-get install -y --no-install-recommends ca-certificates \ && rm -rf /var/lib/apt/lists/* WORKDIR /app -COPY --from=builder /out/xcontrol-rag /usr/local/bin/xcontrol-server -COPY rag-server/config/server.yaml /etc/xcontrol/rag-server/server.yaml +COPY --from=builder /out/xcontrol-rag /usr/local/bin/rag-server +COPY rag-server/config/server.yaml /etc/xcontrol/rag-server.yaml +RUN chmod +x /usr/local/bin/entrypoint.sh -RUN <<'SCRIPT' > /usr/local/bin/rag-server-entrypoint.sh -#!/usr/bin/env bash -set -euo pipefail - -CONFIG_FILE="${CONFIG_PATH:-/etc/xcontrol/rag-server/server.yaml}" -DEFAULT_CONFIG="/etc/xcontrol/rag-server/server.yaml" -mkdir -p "$(dirname "${CONFIG_FILE}")" - -if [ ! -f "${CONFIG_FILE}" ]; then - cp "${DEFAULT_CONFIG}" "${CONFIG_FILE}" -fi - -if [ -n "${PORT:-}" ]; then - tmp_cfg=$(mktemp) - awk -v port="$PORT" ' - /^server:/ {print; in_server=1; addr_written=0; next} - in_server && /^ addr:/ {print " addr: \":" port "\""; addr_written=1; next} - in_server && /^ [^ ]/ {in_server=0} - {print} - END { - if (port != "" && in_server == 0 && addr_written == 0) { - print "server:"; - print " addr: \":" port "\""; - } - } - ' "${CONFIG_FILE}" > "${tmp_cfg}" - CONFIG_FILE="${tmp_cfg}" -fi - -exec /usr/local/bin/xcontrol-server --config "${CONFIG_FILE}" "$@" -SCRIPT - -RUN chmod +x /usr/local/bin/rag-server-entrypoint.sh - -VOLUME ["/etc/xcontrol/rag-server"] +VOLUME ["/etc/xcontrol/"] EXPOSE 8090 -ENTRYPOINT ["/usr/local/bin/rag-server-entrypoint.sh"] +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] CMD [] diff --git a/rag-server/entrypoint.sh b/rag-server/entrypoint.sh new file mode 100644 index 0000000..6ba4689 --- /dev/null +++ b/rag-server/entrypoint.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -euo pipefail + +CONFIG_FILE="${CONFIG_PATH:-/etc/xcontrol/rag-server/server.yaml}" +DEFAULT_CONFIG="/etc/xcontrol/rag-server/server.yaml" +mkdir -p "$(dirname "${CONFIG_FILE}")" + +if [ ! -f "${CONFIG_FILE}" ]; then + cp "${DEFAULT_CONFIG}" "${CONFIG_FILE}" +fi + +if [ -n "${PORT:-}" ]; then + tmp_cfg=$(mktemp) + awk -v port="$PORT" ' + /^server:/ {print; in_server=1; addr_written=0; next} + in_server && /^ addr:/ {print " addr: \":" port "\""; addr_written=1; next} + in_server && /^ [^ ]/ {in_server=0} + {print} + END { + if (port != "" && in_server == 0 && addr_written == 0) { + print "server:"; + print " addr: \":" port "\""; + } + } + ' "${CONFIG_FILE}" > "${tmp_cfg}" + CONFIG_FILE="${tmp_cfg}" +fi + +exec /usr/local/bin/xcontrol-server --config "${CONFIG_FILE}" "$@"