merged: go-runtime.Dockerfile & go-builder.Dockerfile -> go-base.Dockerfile
This commit is contained in:
parent
692a990098
commit
a0c9e328ef
3
.github/workflows/build-base-images.yml
vendored
3
.github/workflows/build-base-images.yml
vendored
@ -51,8 +51,7 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
image:
|
||||
- { name: go-builder, file: deploy/base-images/go-builder.Dockerfile }
|
||||
- { name: go-runtime, file: deploy/base-images/go-runtime.Dockerfile }
|
||||
- { name: go-base, file: deploy/base-images/go-base.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 }
|
||||
|
||||
10
.github/workflows/build-service-images.yml
vendored
10
.github/workflows/build-service-images.yml
vendored
@ -104,10 +104,12 @@ jobs:
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
build-args: |
|
||||
NODE_BUILDER_IMAGE=${{ env.REGISTRY }}/${{ env.BASE_ORG }}/node-builder@${{ inputs.node_builder_digest }}
|
||||
NODE_RUNTIME_IMAGE=${{ env.REGISTRY }}/${{ env.BASE_ORG }}/node-runtime@${{ inputs.node_runtime_digest }}
|
||||
POSTGRES_RUNTIME_IMAGE=${{ env.REGISTRY }}/${{ env.BASE_ORG }}/postgres-runtime@${{ inputs.postgres_runtime_digest }}
|
||||
OPENRESTY_GEOIP_IMAGE=${{ env.REGISTRY }}/${{ env.BASE_ORG }}/openresty-geoip@${{ inputs.openresty_geoip_digest }}
|
||||
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 }}
|
||||
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 }}
|
||||
POSTGRES_RUNTIME_IMAGE=${{ env.REGISTRY }}/${{ env.ORG }}/postgres-runtime@${{ inputs.postgres_runtime_digest }}
|
||||
|
||||
# -----------------------------
|
||||
# SBOM
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
# Multi-stage production build for the account service
|
||||
FROM golang:1.23 AS builder
|
||||
|
||||
ARG GO_BASE_IMAGE
|
||||
|
||||
FROM ${GO_BUILDER_IMAGE} AS builder
|
||||
WORKDIR /src
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
@ -8,7 +11,9 @@ COPY . .
|
||||
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/accountsvc ./account/cmd/accountsvc
|
||||
|
||||
FROM debian:12-slim AS runtime
|
||||
# PROD Image
|
||||
|
||||
FROM ${GO_RUNTIME_IMAGE} AS runtime
|
||||
ENV CONFIG_PATH=/etc/xcontrol/account/account.yaml \
|
||||
PORT=8080
|
||||
|
||||
@ -19,39 +24,7 @@ RUN apt-get update \
|
||||
WORKDIR /app
|
||||
COPY --from=builder /out/accountsvc /usr/local/bin/accountsvc
|
||||
COPY account/config/account.yaml /etc/xcontrol/account/account.yaml
|
||||
|
||||
RUN <<'SCRIPT' > /usr/local/bin/account-entrypoint.sh
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
CONFIG_FILE="${CONFIG_PATH:-/etc/xcontrol/account/account.yaml}"
|
||||
DEFAULT_CONFIG="/etc/xcontrol/account/account.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/accountsvc --config "${CONFIG_FILE}" "$@"
|
||||
SCRIPT
|
||||
|
||||
COPY account-entrypoint.sh /usr/local/bin/account-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/account-entrypoint.sh
|
||||
|
||||
VOLUME ["/etc/xcontrol/account"]
|
||||
|
||||
30
account/entrypoint.sh
Normal file
30
account/entrypoint.sh
Normal file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
CONFIG_FILE="${CONFIG_PATH:-/etc/xcontrol/account/account.yaml}"
|
||||
DEFAULT_CONFIG="/etc/xcontrol/account/account.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/accountsvc --config "${CONFIG_FILE}" "$@"
|
||||
SCRIPT
|
||||
@ -1,26 +0,0 @@
|
||||
FROM ubuntu:24.04
|
||||
|
||||
LABEL maintainer="XControl" \
|
||||
description="Go 1.23 builder image with common dependencies for XControl services"
|
||||
|
||||
ENV GO_VERSION=1.23.8 \
|
||||
CGO_ENABLED=0 \
|
||||
GOOS=linux \
|
||||
GOARCH=amd64 \
|
||||
PATH=/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
RUN set -eux; \
|
||||
apt-get update; \
|
||||
apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
curl \
|
||||
git \
|
||||
build-essential; \
|
||||
rm -rf /var/lib/apt/lists/*; \
|
||||
curl -fsSL "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" -o /tmp/go.tgz; \
|
||||
tar -C /usr/local -xzf /tmp/go.tgz; \
|
||||
rm /tmp/go.tgz
|
||||
|
||||
WORKDIR /workspace
|
||||
|
||||
CMD ["bash"]
|
||||
Loading…
Reference in New Issue
Block a user